Files
ComfyUI_frontend/src/composables/useLoad3dDrag.ts
Terry Jia afa10f7a1e [refactor] refactor load3d (#5765)
Summary

Fully Refactored the Load3D module to improve architecture and
maintainability by consolidating functionality into a
centralized composable pattern and simplifying component structure. and
support VueNodes system

  Changes

- Architecture: Introduced new useLoad3d composable to centralize 3D
loading logic and state
  management
- Component Simplification: Removed redundant components
(Load3DAnimation.vue, Load3DAnimationScene.vue,
  PreviewManager.ts) 
- Support VueNodes
- improve config store
- remove lineart output due Animation doesnot support it, may add it
back later
- remove Preview screen and keep scene in fixed ratio in load3d (not
affect preview3d)
- improve record video feature which will already record video by same
ratio as scene
Need BE change https://github.com/comfyanonymous/ComfyUI/pull/10025


https://github.com/user-attachments/assets/9e038729-84a0-45ad-b0f2-11c57d7e0c9a



┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-5765-refactor-refactor-load3d-2796d73d365081728297cc486e2e9052)
by [Unito](https://www.unito.io)
2025-10-31 16:19:35 -04:00

71 lines
1.7 KiB
TypeScript

import { computed, ref, toValue } from 'vue'
import type { MaybeRefOrGetter } from 'vue'
import { SUPPORTED_EXTENSIONS } from '@/extensions/core/load3d/interfaces'
import { t } from '@/i18n'
import { useToastStore } from '@/platform/updates/common/toastStore'
interface UseLoad3dDragOptions {
onModelDrop: (file: File) => void | Promise<void>
disabled?: MaybeRefOrGetter<boolean>
}
export function useLoad3dDrag(options: UseLoad3dDragOptions) {
const isDragging = ref(false)
const dragMessage = ref('')
const isDisabled = computed(() => toValue(options.disabled) ?? false)
function isValidModelFile(file: File): boolean {
const fileName = file.name.toLowerCase()
const extension = fileName.substring(fileName.lastIndexOf('.'))
return SUPPORTED_EXTENSIONS.has(extension)
}
function handleDragOver(event: DragEvent) {
if (isDisabled.value) return
if (!event.dataTransfer) return
const hasFiles = event.dataTransfer.types.includes('Files')
if (!hasFiles) return
isDragging.value = true
event.dataTransfer.dropEffect = 'copy'
dragMessage.value = t('load3d.dropToLoad')
}
function handleDragLeave() {
isDragging.value = false
}
async function handleDrop(event: DragEvent) {
isDragging.value = false
if (isDisabled.value) return
if (!event.dataTransfer) return
const files = Array.from(event.dataTransfer.files)
if (files.length === 0) return
const modelFile = files.find(isValidModelFile)
if (modelFile) {
await options.onModelDrop(modelFile)
} else {
useToastStore().addAlert(t('load3d.unsupportedFileType'))
}
}
return {
isDragging,
dragMessage,
handleDragOver,
handleDragLeave,
handleDrop
}
}