|
| 1 | +<template> |
| 2 | + <div |
| 3 | + ref="viewerContentRef" |
| 4 | + class="flex w-full" |
| 5 | + :class="[maximized ? 'h-full' : 'h-[70vh]']" |
| 6 | + @mouseenter="viewer.handleMouseEnter" |
| 7 | + @mouseleave="viewer.handleMouseLeave" |
| 8 | + > |
| 9 | + <div ref="mainContentRef" class="flex-1 relative"> |
| 10 | + <div |
| 11 | + ref="containerRef" |
| 12 | + class="absolute w-full h-full comfy-load-3d-viewer" |
| 13 | + @resize="viewer.handleResize" |
| 14 | + /> |
| 15 | + </div> |
| 16 | + |
| 17 | + <div class="w-72 flex flex-col"> |
| 18 | + <div class="flex-1 overflow-y-auto p-4"> |
| 19 | + <div class="space-y-2"> |
| 20 | + <Panel v-model:collapsed="panelStates.scene" toggleable> |
| 21 | + <template #header> |
| 22 | + <div class="flex items-center gap-2"> |
| 23 | + <i class="pi pi-image" /> |
| 24 | + <span>{{ t('load3d.viewer.sceneSettings') }}</span> |
| 25 | + </div> |
| 26 | + </template> |
| 27 | + <div class="p-4 space-y-4"> |
| 28 | + <SceneControls |
| 29 | + v-model:background-color="viewer.backgroundColor.value" |
| 30 | + v-model:show-grid="viewer.showGrid.value" |
| 31 | + :has-background-image="viewer.hasBackgroundImage.value" |
| 32 | + @update-background-image="viewer.handleBackgroundImageUpdate" |
| 33 | + /> |
| 34 | + </div> |
| 35 | + </Panel> |
| 36 | + |
| 37 | + <Panel v-model:collapsed="panelStates.model" toggleable> |
| 38 | + <template #header> |
| 39 | + <div class="flex items-center gap-2"> |
| 40 | + <i class="pi pi-box" /> |
| 41 | + <span>{{ t('load3d.viewer.modelSettings') }}</span> |
| 42 | + </div> |
| 43 | + </template> |
| 44 | + <div class="p-4 space-y-4"> |
| 45 | + <ModelControls |
| 46 | + v-model:up-direction="viewer.upDirection.value" |
| 47 | + v-model:material-mode="viewer.materialMode.value" |
| 48 | + /> |
| 49 | + </div> |
| 50 | + </Panel> |
| 51 | + |
| 52 | + <Panel v-model:collapsed="panelStates.camera" toggleable> |
| 53 | + <template #header> |
| 54 | + <div class="flex items-center gap-2"> |
| 55 | + <i class="pi pi-camera" /> |
| 56 | + <span>{{ t('load3d.viewer.cameraSettings') }}</span> |
| 57 | + </div> |
| 58 | + </template> |
| 59 | + <div class="p-4 space-y-4"> |
| 60 | + <CameraControls |
| 61 | + v-model:camera-type="viewer.cameraType.value" |
| 62 | + v-model:fov="viewer.fov.value" |
| 63 | + /> |
| 64 | + </div> |
| 65 | + </Panel> |
| 66 | + |
| 67 | + <Panel v-model:collapsed="panelStates.light" toggleable> |
| 68 | + <template #header> |
| 69 | + <div class="flex items-center gap-2"> |
| 70 | + <i class="pi pi-sun" /> |
| 71 | + <span>{{ t('load3d.viewer.lightSettings') }}</span> |
| 72 | + </div> |
| 73 | + </template> |
| 74 | + <div class="p-4 space-y-4"> |
| 75 | + <LightControls |
| 76 | + v-model:light-intensity="viewer.lightIntensity.value" |
| 77 | + /> |
| 78 | + </div> |
| 79 | + </Panel> |
| 80 | + |
| 81 | + <Panel v-model:collapsed="panelStates.export" toggleable> |
| 82 | + <template #header> |
| 83 | + <div class="flex items-center gap-2"> |
| 84 | + <i class="pi pi-download" /> |
| 85 | + <span>{{ t('load3d.viewer.exportSettings') }}</span> |
| 86 | + </div> |
| 87 | + </template> |
| 88 | + <div class="p-4 space-y-4"> |
| 89 | + <ExportControls @export-model="viewer.exportModel" /> |
| 90 | + </div> |
| 91 | + </Panel> |
| 92 | + </div> |
| 93 | + </div> |
| 94 | + |
| 95 | + <div class="p-4"> |
| 96 | + <div class="flex gap-2"> |
| 97 | + <Button |
| 98 | + icon="pi pi-times" |
| 99 | + severity="secondary" |
| 100 | + :label="t('g.cancel')" |
| 101 | + @click="handleCancel" |
| 102 | + /> |
| 103 | + <Button |
| 104 | + icon="pi pi-check" |
| 105 | + severity="secondary" |
| 106 | + :label="t('g.apply')" |
| 107 | + @click="handleConfirm" |
| 108 | + /> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + </div> |
| 113 | +</template> |
| 114 | + |
| 115 | +<script setup lang="ts"> |
| 116 | +import { LGraphNode } from '@comfyorg/litegraph' |
| 117 | +import Button from 'primevue/button' |
| 118 | +import Panel from 'primevue/panel' |
| 119 | +import { onBeforeUnmount, onMounted, ref, toRef } from 'vue' |
| 120 | +
|
| 121 | +import CameraControls from '@/components/load3d/controls/viewer/CameraControls.vue' |
| 122 | +import ExportControls from '@/components/load3d/controls/viewer/ExportControls.vue' |
| 123 | +import LightControls from '@/components/load3d/controls/viewer/LightControls.vue' |
| 124 | +import ModelControls from '@/components/load3d/controls/viewer/ModelControls.vue' |
| 125 | +import SceneControls from '@/components/load3d/controls/viewer/SceneControls.vue' |
| 126 | +import { useLoad3dViewer } from '@/composables/useLoad3dViewer' |
| 127 | +import { t } from '@/i18n' |
| 128 | +import { useLoad3dService } from '@/services/load3dService' |
| 129 | +import { useDialogStore } from '@/stores/dialogStore' |
| 130 | +
|
| 131 | +const props = defineProps<{ |
| 132 | + node: LGraphNode |
| 133 | +}>() |
| 134 | +
|
| 135 | +const viewerContentRef = ref<HTMLDivElement>() |
| 136 | +const containerRef = ref<HTMLDivElement>() |
| 137 | +const mainContentRef = ref<HTMLDivElement>() |
| 138 | +const maximized = ref(false) |
| 139 | +const mutationObserver = ref<MutationObserver | null>(null) |
| 140 | +
|
| 141 | +const panelStates = ref({ |
| 142 | + scene: false, |
| 143 | + model: true, |
| 144 | + camera: true, |
| 145 | + light: true, |
| 146 | + export: true |
| 147 | +}) |
| 148 | +
|
| 149 | +const viewer = useLoad3dViewer(toRef(props, 'node')) |
| 150 | +
|
| 151 | +onMounted(async () => { |
| 152 | + const source = useLoad3dService().getLoad3d(props.node) |
| 153 | + if (source && containerRef.value) { |
| 154 | + await viewer.initializeViewer(containerRef.value, source) |
| 155 | + } |
| 156 | +
|
| 157 | + if (viewerContentRef.value) { |
| 158 | + mutationObserver.value = new MutationObserver((mutations) => { |
| 159 | + mutations.forEach((mutation) => { |
| 160 | + if ( |
| 161 | + mutation.type === 'attributes' && |
| 162 | + mutation.attributeName === 'maximized' |
| 163 | + ) { |
| 164 | + maximized.value = |
| 165 | + (mutation.target as HTMLElement).getAttribute('maximized') === |
| 166 | + 'true' |
| 167 | +
|
| 168 | + setTimeout(() => { |
| 169 | + viewer.refreshViewport() |
| 170 | + }, 0) |
| 171 | + } |
| 172 | + }) |
| 173 | + }) |
| 174 | +
|
| 175 | + mutationObserver.value.observe(viewerContentRef.value, { |
| 176 | + attributes: true, |
| 177 | + attributeFilter: ['maximized'] |
| 178 | + }) |
| 179 | + } |
| 180 | +
|
| 181 | + window.addEventListener('resize', viewer.handleResize) |
| 182 | +}) |
| 183 | +
|
| 184 | +const handleCancel = () => { |
| 185 | + viewer.restoreInitialState() |
| 186 | + useDialogStore().closeDialog() |
| 187 | +} |
| 188 | +
|
| 189 | +const handleConfirm = async () => { |
| 190 | + const success = await viewer.applyChanges() |
| 191 | + if (!success) { |
| 192 | + viewer.restoreInitialState() |
| 193 | + } |
| 194 | +
|
| 195 | + useDialogStore().closeDialog() |
| 196 | +} |
| 197 | +
|
| 198 | +onBeforeUnmount(() => { |
| 199 | + window.removeEventListener('resize', viewer.handleResize) |
| 200 | +
|
| 201 | + if (mutationObserver.value) { |
| 202 | + mutationObserver.value.disconnect() |
| 203 | + mutationObserver.value = null |
| 204 | + } |
| 205 | +
|
| 206 | + viewer.cleanup() |
| 207 | +}) |
| 208 | +</script> |
| 209 | + |
| 210 | +<style scoped> |
| 211 | +:deep(.p-panel-content) { |
| 212 | + padding: 0; |
| 213 | +} |
| 214 | +</style> |
0 commit comments