Line data Source code
1 13 : <template>
2 0 : <PopoverRoot v-if="isOriginalMaterial" v-model:open="intensityOpen">
3 : <PopoverTrigger as-child>
4 : <Button
5 : variant="textonly"
6 : size="unset"
7 : :tooltip="t('load3d.menuBar.intensity')"
8 : tooltip-side="bottom"
9 : :class="actionClass(false)"
10 : type="button"
11 : :aria-label="compact ? t('load3d.menuBar.intensity') : undefined"
12 : >
13 : <i class="icon-[lucide--sun]" />
14 : <span v-if="!compact">{{ t('load3d.menuBar.intensity') }}</span>
15 : </Button>
16 : </PopoverTrigger>
17 : <PopoverContent
18 : align="start"
19 : :side-offset="8"
20 : :class="cn(formPanelClass, 'w-56')"
21 : >
22 : <div class="flex flex-col gap-2 p-1">
23 : <span class="text-sm text-foreground">{{
24 : t('load3d.lightIntensity')
25 : }}</span>
26 : <Slider
27 : :model-value="[sliderValue]"
28 : :min="sliderMin"
29 : :max="sliderMax"
30 : :step="sliderStep"
31 : @update:model-value="onIntensityUpdate"
32 : />
33 : </div>
34 : </PopoverContent>
35 : </PopoverRoot>
36 : <span v-else class="px-2 text-sm text-muted-foreground">{{
37 : t('load3d.menuBar.originalMaterialOnly')
38 : }}</span>
39 : </template>
40 :
41 : <script setup lang="ts">
42 : import { computed } from 'vue'
43 : import { useI18n } from 'vue-i18n'
44 :
45 : import {
46 : actionClass,
47 : formPanelClass
48 : } from '@/extensions/core/load3d/components/menubar/menuBarStyles'
49 : import { usePopoverExclusivity } from '@/extensions/core/load3d/components/menubar/usePopoverExclusivity'
50 : import PopoverContent from '@comfyorg/design-system/popover/PopoverContent'
51 : import Slider from '@comfyorg/design-system/slider/Slider'
52 : import Button from '@comfyorg/design-system/button/Button'
53 : import type { LightConfig } from '@comfyorg/viewport3d/load3d/interfaces'
54 : import { useSettingStore } from '@/platform/settings/settingStore'
55 : import { cn } from '@comfyorg/tailwind-utils'
56 : import { PopoverRoot, PopoverTrigger } from 'reka-ui'
57 :
58 : const { compact = false, isOriginalMaterial = false } = defineProps<{
59 : compact?: boolean
60 : isOriginalMaterial?: boolean
61 : }>()
62 :
63 0 : const config = defineModel<LightConfig>('config')
64 :
65 0 : const { t } = useI18n()
66 :
67 0 : const intensityOpen = usePopoverExclusivity()('light-intensity')
68 :
69 0 : const settingStore = useSettingStore()
70 0 : const lightIntensityMinimum = settingStore.get(
71 : 'Comfy.Load3D.LightIntensityMinimum'
72 : )
73 0 : const lightIntensityMaximum = settingStore.get(
74 : 'Comfy.Load3D.LightIntensityMaximum'
75 : )
76 0 : const lightAdjustmentIncrement = settingStore.get(
77 : 'Comfy.Load3D.LightAdjustmentIncrement'
78 : )
79 :
80 0 : const usesHdriIntensity = computed(
81 : () => !!config.value?.hdri?.hdriPath?.length && !!config.value?.hdri?.enabled
82 : )
83 :
84 0 : const sliderMin = computed(() =>
85 : usesHdriIntensity.value ? 0 : lightIntensityMinimum
86 : )
87 0 : const sliderMax = computed(() =>
88 : usesHdriIntensity.value ? 5 : lightIntensityMaximum
89 : )
90 0 : const sliderStep = computed(() =>
91 : usesHdriIntensity.value ? 0.1 : lightAdjustmentIncrement
92 : )
93 0 : const sliderValue = computed(() =>
94 : usesHdriIntensity.value
95 : ? (config.value?.hdri?.intensity ?? 1)
96 : : (config.value?.intensity ?? lightIntensityMinimum)
97 : )
98 :
99 0 : function onIntensityUpdate(value?: number[]) {
100 0 : if (!value?.length || !config.value) return
101 0 : const next = value[0]
102 0 : if (usesHdriIntensity.value) {
103 0 : if (config.value.hdri) config.value.hdri.intensity = next
104 : } else {
105 0 : config.value.intensity = next
106 : }
107 : }
108 : </script>
|