|
| 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 | + <div class="p-2 space-y-4"> |
| 21 | + <SceneControls |
| 22 | + v-model:background-color="viewer.backgroundColor.value" |
| 23 | + v-model:show-grid="viewer.showGrid.value" |
| 24 | + :has-background-image="viewer.hasBackgroundImage.value" |
| 25 | + @update-background-image="viewer.handleBackgroundImageUpdate" |
| 26 | + /> |
| 27 | + </div> |
| 28 | + |
| 29 | + <div class="p-2 space-y-4"> |
| 30 | + <ModelControls |
| 31 | + v-model:up-direction="viewer.upDirection.value" |
| 32 | + v-model:material-mode="viewer.materialMode.value" |
| 33 | + /> |
| 34 | + </div> |
| 35 | + |
| 36 | + <div class="p-2 space-y-4"> |
| 37 | + <CameraControls |
| 38 | + v-model:camera-type="viewer.cameraType.value" |
| 39 | + v-model:fov="viewer.fov.value" |
| 40 | + /> |
| 41 | + </div> |
| 42 | + |
| 43 | + <div class="p-2 space-y-4"> |
| 44 | + <LightControls |
| 45 | + v-model:light-intensity="viewer.lightIntensity.value" |
| 46 | + /> |
| 47 | + </div> |
| 48 | + |
| 49 | + <div class="p-2 space-y-4"> |
| 50 | + <ExportControls @export-model="viewer.exportModel" /> |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + |
| 55 | + <div class="p-4"> |
| 56 | + <div class="flex gap-2"> |
| 57 | + <Button |
| 58 | + icon="pi pi-times" |
| 59 | + severity="secondary" |
| 60 | + :label="t('g.cancel')" |
| 61 | + @click="handleCancel" |
| 62 | + /> |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | +</template> |
| 68 | + |
| 69 | +<script setup lang="ts"> |
| 70 | +import Button from 'primevue/button' |
| 71 | +import { onBeforeUnmount, onMounted, ref, toRaw } from 'vue' |
| 72 | +
|
| 73 | +import CameraControls from '@/components/load3d/controls/viewer/CameraControls.vue' |
| 74 | +import ExportControls from '@/components/load3d/controls/viewer/ExportControls.vue' |
| 75 | +import LightControls from '@/components/load3d/controls/viewer/LightControls.vue' |
| 76 | +import ModelControls from '@/components/load3d/controls/viewer/ModelControls.vue' |
| 77 | +import SceneControls from '@/components/load3d/controls/viewer/SceneControls.vue' |
| 78 | +import { t } from '@/i18n' |
| 79 | +import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' |
| 80 | +import { useLoad3dService } from '@/services/load3dService' |
| 81 | +import { useDialogStore } from '@/stores/dialogStore' |
| 82 | +
|
| 83 | +const props = defineProps<{ |
| 84 | + node: LGraphNode |
| 85 | +}>() |
| 86 | +
|
| 87 | +const viewerContentRef = ref<HTMLDivElement>() |
| 88 | +const containerRef = ref<HTMLDivElement>() |
| 89 | +const mainContentRef = ref<HTMLDivElement>() |
| 90 | +const maximized = ref(false) |
| 91 | +const mutationObserver = ref<MutationObserver | null>(null) |
| 92 | +
|
| 93 | +const viewer = useLoad3dService().getOrCreateViewer(toRaw(props.node)) |
| 94 | +
|
| 95 | +onMounted(async () => { |
| 96 | + const source = useLoad3dService().getLoad3d(props.node) |
| 97 | + if (source && containerRef.value) { |
| 98 | + await viewer.initializeViewer(containerRef.value, source) |
| 99 | + } |
| 100 | +
|
| 101 | + if (viewerContentRef.value) { |
| 102 | + mutationObserver.value = new MutationObserver((mutations) => { |
| 103 | + mutations.forEach((mutation) => { |
| 104 | + if ( |
| 105 | + mutation.type === 'attributes' && |
| 106 | + mutation.attributeName === 'maximized' |
| 107 | + ) { |
| 108 | + maximized.value = |
| 109 | + (mutation.target as HTMLElement).getAttribute('maximized') === |
| 110 | + 'true' |
| 111 | +
|
| 112 | + setTimeout(() => { |
| 113 | + viewer.refreshViewport() |
| 114 | + }, 0) |
| 115 | + } |
| 116 | + }) |
| 117 | + }) |
| 118 | +
|
| 119 | + mutationObserver.value.observe(viewerContentRef.value, { |
| 120 | + attributes: true, |
| 121 | + attributeFilter: ['maximized'] |
| 122 | + }) |
| 123 | + } |
| 124 | +
|
| 125 | + window.addEventListener('resize', viewer.handleResize) |
| 126 | +}) |
| 127 | +
|
| 128 | +const handleCancel = () => { |
| 129 | + viewer.restoreInitialState() |
| 130 | + useDialogStore().closeDialog() |
| 131 | +} |
| 132 | +
|
| 133 | +onBeforeUnmount(() => { |
| 134 | + window.removeEventListener('resize', viewer.handleResize) |
| 135 | +
|
| 136 | + if (mutationObserver.value) { |
| 137 | + mutationObserver.value.disconnect() |
| 138 | + mutationObserver.value = null |
| 139 | + } |
| 140 | +
|
| 141 | + // we will manually cleanup the viewer in dialog close handler |
| 142 | +}) |
| 143 | +</script> |
| 144 | + |
| 145 | +<style scoped> |
| 146 | +:deep(.p-panel-content) { |
| 147 | + padding: 0; |
| 148 | +} |
| 149 | +</style> |
0 commit comments