Line data Source code
1 13 : <template>
2 : <template v-if="!sceneHasImage || hdriPath">
3 : <Button
4 : variant="textonly"
5 : size="unset"
6 : :tooltip="fileActionLabel"
7 : tooltip-side="bottom"
8 : :class="actionClass(false)"
9 : type="button"
10 : :aria-label="compact ? fileActionLabel : undefined"
11 : @click="hdriFileRef?.click()"
12 : >
13 : <i class="icon-[lucide--upload]" />
14 : <span v-if="!compact">{{ fileActionLabel }}</span>
15 : </Button>
16 : <input
17 : ref="hdriFileRef"
18 : type="file"
19 : :accept="SUPPORTED_HDRI_EXTENSIONS_ACCEPT"
20 : class="pointer-events-none absolute size-0 opacity-0"
21 : @change="onHdriFilePicked"
22 : />
23 : </template>
24 :
25 : <template v-if="hdriPath">
26 : <Button
27 : variant="textonly"
28 : size="unset"
29 : :tooltip="t('load3d.hdri.label')"
30 : tooltip-side="bottom"
31 : :class="actionClass(hdriEnabled)"
32 : :aria-pressed="hdriEnabled"
33 : type="button"
34 : :aria-label="compact ? t('load3d.hdri.label') : undefined"
35 : @click="toggleHdriEnabled"
36 : >
37 : <i class="icon-[lucide--globe]" />
38 : <span v-if="!compact">{{ t('load3d.hdri.label') }}</span>
39 : </Button>
40 : <Button
41 : variant="textonly"
42 : size="unset"
43 : :tooltip="t('load3d.hdri.showAsBackground')"
44 : tooltip-side="bottom"
45 : :class="actionClass(hdriShowAsBackground)"
46 : :aria-pressed="hdriShowAsBackground"
47 : type="button"
48 : :aria-label="compact ? t('load3d.hdri.showAsBackground') : undefined"
49 : @click="toggleHdriShowAsBackground"
50 : >
51 : <i class="icon-[lucide--image]" />
52 : <span v-if="!compact">{{ t('load3d.hdri.showAsBackground') }}</span>
53 : </Button>
54 : <Button
55 : variant="textonly"
56 : size="unset"
57 : :tooltip="t('load3d.hdri.removeFile')"
58 : tooltip-side="bottom"
59 : :class="actionClass(false)"
60 : type="button"
61 : :aria-label="compact ? t('load3d.hdri.removeFile') : undefined"
62 : @click="removeHdri"
63 : >
64 : <i class="icon-[lucide--x]" />
65 : <span v-if="!compact">{{ t('load3d.hdri.removeFile') }}</span>
66 : </Button>
67 : </template>
68 : </template>
69 :
70 : <script setup lang="ts">
71 : import { computed, ref } from 'vue'
72 : import { useI18n } from 'vue-i18n'
73 :
74 : import { actionClass } from '@/extensions/core/load3d/components/menubar/menuBarStyles'
75 : import Button from '@comfyorg/design-system/button/Button'
76 : import { useToast } from '@/components/ui/toast/toastStore'
77 : import {
78 : SUPPORTED_HDRI_EXTENSIONS,
79 : SUPPORTED_HDRI_EXTENSIONS_ACCEPT
80 : } from '@comfyorg/viewport3d/load3d/constants'
81 : import type { LightConfig } from '@comfyorg/viewport3d/load3d/interfaces'
82 :
83 : const { compact = false, sceneHasImage = false } = defineProps<{
84 : compact?: boolean
85 : sceneHasImage?: boolean
86 : }>()
87 :
88 0 : const config = defineModel<LightConfig>('config')
89 :
90 0 : const emit = defineEmits<{
91 : (e: 'updateHdriFile', file: File | null): void
92 : }>()
93 :
94 0 : const { t } = useI18n()
95 :
96 0 : const hdriPath = computed(() => config.value?.hdri?.hdriPath ?? '')
97 0 : const fileActionLabel = computed(() =>
98 : hdriPath.value ? t('load3d.hdri.changeFile') : t('load3d.hdri.uploadFile')
99 : )
100 0 : const hdriEnabled = computed(() => config.value?.hdri?.enabled ?? false)
101 0 : const hdriShowAsBackground = computed(
102 : () => config.value?.hdri?.showAsBackground ?? false
103 : )
104 :
105 0 : const hdriFileRef = ref<HTMLInputElement | null>(null)
106 :
107 0 : function onHdriFilePicked(event: Event) {
108 0 : const input = event.target as HTMLInputElement
109 0 : const file = input.files?.[0] ?? null
110 0 : input.value = ''
111 0 : if (file) {
112 0 : const ext = `.${file.name.split('.').pop()?.toLowerCase() ?? ''}`
113 0 : if (!SUPPORTED_HDRI_EXTENSIONS.has(ext)) {
114 0 : useToast().warning(t('toastMessages.unsupportedHDRIFormat'))
115 0 : return
116 : }
117 : }
118 0 : emit('updateHdriFile', file)
119 : }
120 :
121 0 : function toggleHdriEnabled() {
122 0 : const hdri = config.value?.hdri
123 0 : if (hdri) hdri.enabled = !hdri.enabled
124 : }
125 :
126 0 : function toggleHdriShowAsBackground() {
127 0 : const hdri = config.value?.hdri
128 0 : if (hdri) hdri.showAsBackground = !hdri.showAsBackground
129 : }
130 :
131 0 : function removeHdri() {
132 0 : emit('updateHdriFile', null)
133 : }
134 : </script>
|