Line data Source code
1 13 : <template>
2 175 : <div class="flex size-full flex-col">
3 : <div
4 : ref="topBarRef"
5 : class="flex h-10 shrink-0 items-center gap-1 bg-popover px-2"
6 : @wheel.stop
7 : >
8 : <PopoverRoot v-model:open="categoryMenuOpen">
9 : <PopoverTrigger as-child>
10 : <Button
11 : variant="textonly"
12 : size="unset"
13 : :tooltip="compact ? activeLabel : ''"
14 : tooltip-side="bottom"
15 : :class="chipClass"
16 : type="button"
17 : :aria-label="compact ? activeLabel : undefined"
18 : data-testid="load3d-category-menu"
19 : >
20 : <i v-if="compact" :class="activeIcon" />
21 : <template v-else>{{ activeLabel }}</template>
22 : <i class="icon-[lucide--chevron-down] opacity-70" />
23 : </Button>
24 : </PopoverTrigger>
25 : <PopoverContent align="start" :side-offset="8" :class="menuPanelClass">
26 180 : <button
27 : v-for="c in categoryDefs"
28 : :key="c.key"
29 : type="button"
30 : :class="
31 : cn(
32 : menuButtonClass,
33 : activeCategory === c.key && selectedMenuButtonClass
34 : )
35 : "
36 : :aria-pressed="activeCategory === c.key"
37 : @click="selectCategory(c.key)"
38 : >
39 : <i :class="c.icon" />
40 : {{ c.label }}
41 : </button>
42 : </PopoverContent>
43 : </PopoverRoot>
44 :
45 : <div class="mx-1 h-5 w-px shrink-0 bg-border" />
46 :
47 : <SceneMenuGroup
48 : v-if="activeCategory === 'scene' && sceneConfig"
49 : v-model:config="sceneConfig"
50 : v-model:fov="cameraFov"
51 : :compact
52 : :can-use-background-image="canUseBackgroundImage"
53 : :hdri-active="hdriActive"
54 : @update-background-image="emit('updateBackgroundImage', $event)"
55 : />
56 : <ModelMenuGroup
57 : v-else-if="activeCategory === 'model' && modelConfig"
58 : v-model:config="modelConfig"
59 : :compact
60 : :material-modes="materialModes"
61 : :has-skeleton="hasSkeleton"
62 : />
63 : <CameraMenuGroup
64 : v-else-if="activeCategory === 'camera' && cameraConfig"
65 : v-model:config="cameraConfig"
66 : :compact
67 : />
68 : <LightMenuGroup
69 : v-else-if="activeCategory === 'light' && lightConfig && modelConfig"
70 : v-model:config="lightConfig"
71 : :compact
72 : :is-original-material="isOriginalMaterial"
73 : />
74 : <HdriMenuGroup
75 : v-else-if="activeCategory === 'hdri' && lightConfig"
76 : v-model:config="lightConfig"
77 : :compact
78 : :scene-has-image="sceneHasImage"
79 : @update-hdri-file="emit('updateHdriFile', $event)"
80 : />
81 : <GizmoMenuGroup
82 : v-else-if="activeCategory === 'gizmo' && modelConfig"
83 : v-model:config="modelConfig"
84 : :compact
85 : @toggle-gizmo="emit('toggleGizmo', $event)"
86 : @set-gizmo-mode="emit('setGizmoMode', $event)"
87 : @reset-gizmo-transform="emit('resetGizmoTransform')"
88 : />
89 : </div>
90 :
91 : <div class="relative min-h-0 flex-1 overflow-hidden">
92 : <slot />
93 : <ModelStatsOverlay
94 : v-if="modelStats && hasGeometry(modelStats)"
95 : :stats="modelStats"
96 : />
97 : <div
98 : v-if="isRecording"
99 : class="pointer-events-none absolute inset-0 border-2 border-primary"
100 : />
101 : </div>
102 :
103 : <AnimationMenuStrip
104 : v-if="animations.length > 0"
105 : v-model:playing="playing"
106 : v-model:selected-speed="selectedSpeed"
107 : v-model:selected-animation="selectedAnimation"
108 : v-model:animation-progress="animationProgress"
109 : :animations="animations"
110 : :animation-duration="animationDuration"
111 : :compact
112 : @seek="emit('seek', $event)"
113 : />
114 :
115 : <div
116 : class="flex h-10 shrink-0 items-center justify-between gap-1 bg-popover px-2"
117 : @wheel.stop
118 : >
119 : <div class="flex items-center gap-1">
120 : <RecordMenuControl
121 : v-if="canUseRecording"
122 : v-model:is-recording="isRecording"
123 : v-model:has-recording="hasRecording"
124 : v-model:recording-duration="recordingDuration"
125 : :compact
126 : @start-recording="emit('startRecording')"
127 : @stop-recording="emit('stopRecording')"
128 : @export-recording="emit('exportRecording')"
129 : @clear-recording="emit('clearRecording')"
130 : />
131 : </div>
132 : <div class="flex items-center gap-1">
133 : <ViewerControls
134 : v-if="enableViewer && node"
135 : :node="node as LGraphNode"
136 : />
137 : <Button
138 : v-if="canFitToViewer"
139 : variant="textonly"
140 : size="icon"
141 : :tooltip="t('load3d.fitToViewer')"
142 : type="button"
143 : :aria-label="t('load3d.fitToViewer')"
144 : @click="emit('fitToViewer')"
145 : >
146 : <i class="icon-[lucide--scan]" />
147 : </Button>
148 : <Button
149 : v-if="canCenterCameraOnModel"
150 : variant="textonly"
151 : size="icon"
152 : :tooltip="t('load3d.centerCameraOnModel')"
153 : type="button"
154 : :aria-label="t('load3d.centerCameraOnModel')"
155 : @click="emit('centerCamera')"
156 : >
157 : <i class="icon-[lucide--crosshair]" />
158 : </Button>
159 : <PopoverRoot v-if="canExport" v-model:open="exportOpen">
160 : <PopoverTrigger as-child>
161 : <Button
162 : variant="textonly"
163 : size="icon"
164 : :tooltip="t('load3d.export')"
165 : type="button"
166 : :aria-label="t('load3d.export')"
167 : >
168 : <i class="icon-[lucide--download]" />
169 : </Button>
170 : </PopoverTrigger>
171 : <PopoverContent
172 : side="top"
173 : align="end"
174 : :side-offset="8"
175 : :class="menuPanelClass"
176 : >
177 0 : <button
178 : v-for="format in exportFormats"
179 : :key="format.value"
180 : type="button"
181 : :class="menuButtonClass"
182 : @click="onExport(format.value)"
183 : >
184 : {{ format.label }}
185 : </button>
186 : </PopoverContent>
187 : </PopoverRoot>
188 : </div>
189 : </div>
190 : </div>
191 : </template>
192 :
193 : <script setup lang="ts">
194 : import { useElementSize } from '@vueuse/core'
195 : import { PopoverRoot, PopoverTrigger } from 'reka-ui'
196 : import { computed, ref, watch } from 'vue'
197 : import { useI18n } from 'vue-i18n'
198 :
199 : import { cn } from '@comfyorg/tailwind-utils'
200 :
201 : import AnimationMenuStrip from '@/extensions/core/load3d/components/menubar/AnimationMenuStrip.vue'
202 : import CameraMenuGroup from '@/extensions/core/load3d/components/menubar/CameraMenuGroup.vue'
203 : import GizmoMenuGroup from '@/extensions/core/load3d/components/menubar/GizmoMenuGroup.vue'
204 : import HdriMenuGroup from '@/extensions/core/load3d/components/menubar/HdriMenuGroup.vue'
205 : import LightMenuGroup from '@/extensions/core/load3d/components/menubar/LightMenuGroup.vue'
206 : import {
207 : chipClass,
208 : menuPanelClass
209 : } from '@/extensions/core/load3d/components/menubar/menuBarStyles'
210 : import ModelMenuGroup from '@/extensions/core/load3d/components/menubar/ModelMenuGroup.vue'
211 : import ModelStatsOverlay from '@/extensions/core/load3d/components/menubar/ModelStatsOverlay.vue'
212 : import RecordMenuControl from '@/extensions/core/load3d/components/menubar/RecordMenuControl.vue'
213 : import SceneMenuGroup from '@/extensions/core/load3d/components/menubar/SceneMenuGroup.vue'
214 : import { usePopoverExclusivity } from '@/extensions/core/load3d/components/menubar/usePopoverExclusivity'
215 : import ViewerControls from '@/extensions/core/load3d/components/controls/ViewerControls.vue'
216 : import Button from '@comfyorg/design-system/button/Button'
217 : import PopoverContent from '@comfyorg/design-system/popover/PopoverContent'
218 : import {
219 : menuButtonClass,
220 : selectedMenuButtonClass
221 : } from '@comfyorg/design-system/lib/menu/menuStyles'
222 : import { getExportFormatOptions } from '@comfyorg/viewport3d/load3d/constants'
223 : import { hasGeometry } from '@comfyorg/viewport3d/load3d/modelStats'
224 : import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
225 : import type { ModelStats } from '@comfyorg/viewport3d/load3d/modelStats'
226 : import type {
227 : AnimationItem,
228 : CameraConfig,
229 : GizmoMode,
230 : LightConfig,
231 : MaterialMode,
232 : ModelConfig,
233 : SceneConfig
234 : } from '@comfyorg/viewport3d/load3d/interfaces'
235 :
236 : const {
237 : animations = [],
238 : animationDuration = 0,
239 : canUseLighting = true,
240 : canUseHdri = true,
241 : canUseGizmo = true,
242 : canExport = true,
243 : canUseBackgroundImage = true,
244 : canFitToViewer = true,
245 : canCenterCameraOnModel = true,
246 : canUseRecording = true,
247 : enableViewer = false,
248 : node = null,
249 : materialModes = ['original', 'clay', 'normal', 'wireframe'],
250 : hasSkeleton = false,
251 : modelStats = null,
252 : sourceFormat = null
253 : } = defineProps<{
254 : animations?: AnimationItem[]
255 : animationDuration?: number
256 : canUseLighting?: boolean
257 : canUseHdri?: boolean
258 : canUseGizmo?: boolean
259 : canExport?: boolean
260 : canUseBackgroundImage?: boolean
261 : canFitToViewer?: boolean
262 : canCenterCameraOnModel?: boolean
263 : canUseRecording?: boolean
264 : enableViewer?: boolean
265 : node?: LGraphNode | null
266 : materialModes?: readonly MaterialMode[]
267 : hasSkeleton?: boolean
268 : modelStats?: ModelStats | null
269 : sourceFormat?: string | null
270 : }>()
271 :
272 26 : const sceneConfig = defineModel<SceneConfig>('sceneConfig')
273 26 : const modelConfig = defineModel<ModelConfig>('modelConfig')
274 26 : const cameraConfig = defineModel<CameraConfig>('cameraConfig')
275 26 : const lightConfig = defineModel<LightConfig>('lightConfig')
276 26 : const isRecording = defineModel<boolean>('isRecording')
277 26 : const hasRecording = defineModel<boolean>('hasRecording')
278 26 : const recordingDuration = defineModel<number>('recordingDuration')
279 26 : const playing = defineModel<boolean>('playing')
280 26 : const selectedSpeed = defineModel<number>('selectedSpeed')
281 26 : const selectedAnimation = defineModel<number>('selectedAnimation')
282 26 : const animationProgress = defineModel<number>('animationProgress')
283 :
284 26 : const emit = defineEmits<{
285 : (e: 'seek', progress: number): void
286 : (e: 'updateBackgroundImage', file: File | null): void
287 : (e: 'updateHdriFile', file: File | null): void
288 : (e: 'exportModel', format: string): void
289 : (e: 'fitToViewer'): void
290 : (e: 'centerCamera'): void
291 : (e: 'toggleGizmo', enabled: boolean): void
292 : (e: 'setGizmoMode', mode: GizmoMode): void
293 : (e: 'resetGizmoTransform'): void
294 : (e: 'startRecording'): void
295 : (e: 'stopRecording'): void
296 : (e: 'exportRecording'): void
297 : (e: 'clearRecording'): void
298 : }>()
299 :
300 26 : const { t } = useI18n()
301 :
302 26 : const categoryDefs = computed(() =>
303 : [
304 : {
305 : key: 'scene',
306 : label: t('load3d.scene'),
307 : icon: 'icon-[lucide--layers]',
308 : show: !!sceneConfig.value
309 : },
310 : {
311 : key: 'model',
312 : label: t('load3d.model3d'),
313 : icon: 'icon-[lucide--box]',
314 : show: !!modelConfig.value
315 : },
316 : {
317 : key: 'camera',
318 : label: t('load3d.camera'),
319 : icon: 'icon-[lucide--camera]',
320 : show: !!cameraConfig.value
321 : },
322 : {
323 : key: 'light',
324 : label: t('load3d.light'),
325 : icon: 'icon-[lucide--sun]',
326 : show: canUseLighting && !!lightConfig.value && !!modelConfig.value
327 : },
328 : {
329 : key: 'hdri',
330 : label: t('load3d.hdri.label'),
331 : icon: 'icon-[lucide--globe]',
332 : show: canUseHdri && !!lightConfig.value
333 : },
334 : {
335 : key: 'gizmo',
336 : label: t('load3d.gizmo.label'),
337 : icon: 'icon-[lucide--axis-3d]',
338 : show: canUseGizmo && !!modelConfig.value
339 : }
340 : ].filter((c) => c.show)
341 : )
342 :
343 26 : const activeCategory = ref('scene')
344 26 : const activeDef = computed(() =>
345 : categoryDefs.value.find((c) => c.key === activeCategory.value)
346 : )
347 26 : const activeLabel = computed(() => activeDef.value?.label ?? '')
348 26 : const activeIcon = computed(() => activeDef.value?.icon ?? '')
349 26 : watch(categoryDefs, (defs) => {
350 9 : if (!defs.some((c) => c.key === activeCategory.value)) {
351 0 : activeCategory.value = defs[0]?.key ?? 'scene'
352 : }
353 : })
354 :
355 26 : const exclusivePopover = usePopoverExclusivity()
356 26 : const categoryMenuOpen = exclusivePopover('category-menu')
357 26 : const exportOpen = exclusivePopover('export')
358 :
359 26 : const sceneHasImage = computed(
360 : () =>
361 : !!sceneConfig.value?.backgroundImage &&
362 : sceneConfig.value.backgroundImage !== ''
363 : )
364 26 : const hdriActive = computed(
365 : () =>
366 : !!lightConfig.value?.hdri?.hdriPath && !!lightConfig.value?.hdri?.enabled
367 : )
368 26 : const isOriginalMaterial = computed(
369 : () => modelConfig.value?.materialMode === 'original'
370 : )
371 26 : const cameraFov = computed({
372 : get: () => cameraConfig.value?.fov ?? 0,
373 : set: (value) => {
374 0 : if (cameraConfig.value) cameraConfig.value.fov = value
375 : }
376 : })
377 :
378 26 : const exportFormats = computed(() => getExportFormatOptions(sourceFormat))
379 :
380 26 : const topBarRef = ref<HTMLElement | null>(null)
381 26 : const { width: topW } = useElementSize(topBarRef)
382 24 : const compactWidthThreshold = 480
383 26 : const compact = computed(
384 : () => topW.value > 0 && topW.value < compactWidthThreshold
385 : )
386 :
387 3 : function selectCategory(key: string) {
388 3 : activeCategory.value = key
389 3 : categoryMenuOpen.value = false
390 : }
391 :
392 0 : function onExport(format: string) {
393 0 : emit('exportModel', format)
394 0 : exportOpen.value = false
395 : }
396 : </script>
|