Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/composables/useLoad3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
CameraConfig,
CameraState,
CameraType,
EventCallback,
LightConfig,
MaterialMode,
ModelConfig,
Expand Down Expand Up @@ -564,7 +565,7 @@ export const useLoad3d = (nodeOrRef: MaybeRef<LGraphNode | null>) => {
const handleEvents = (action: 'add' | 'remove') => {
Object.entries(eventConfig).forEach(([event, handler]) => {
const method = `${action}EventListener` as const
load3d?.[method](event, handler)
load3d?.[method](event, handler as EventCallback)
})
}
Comment thread
Myestery marked this conversation as resolved.

Expand Down
44 changes: 28 additions & 16 deletions src/extensions/core/load3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
import Load3DViewerContent from '@/components/load3d/Load3dViewerContent.vue'
import { nodeToLoad3dMap, useLoad3d } from '@/composables/useLoad3d'
import { createExportMenuItems } from '@/extensions/core/load3d/exportMenuHelper'
import type {
CameraConfig,
CameraState
} from '@/extensions/core/load3d/interfaces'
import Load3DConfiguration from '@/extensions/core/load3d/Load3DConfiguration'
import Load3dUtils from '@/extensions/core/load3d/Load3dUtils'
import { t } from '@/i18n'
import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
import type { IContextMenuValue } from '@/lib/litegraph/src/interfaces'
import type { IStringWidget } from '@/lib/litegraph/src/types/widgets'
import { useToastStore } from '@/platform/updates/common/toastStore'
import { type CustomInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { NodeExecutionOutput } from '@/schemas/apiSchema'
import type { CustomInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { api } from '@/scripts/api'
import { ComfyApp, app } from '@/scripts/app'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
Expand All @@ -32,12 +37,12 @@
isPreview: true
}

async function handleModelUpload(files: FileList, node: any) {
async function handleModelUpload(files: FileList, node: LGraphNode) {
if (!files?.length) return

const modelWidget = node.widgets?.find(
(w: any) => w.name === 'model_file'
) as IStringWidget
const modelWidget = node.widgets?.find((w) => w.name === 'model_file') as
| IStringWidget
| undefined

try {
const resourceFolder = (node.properties['Resource Folder'] as string) || ''
Expand Down Expand Up @@ -81,7 +86,7 @@
}
}

async function handleResourcesUpload(files: FileList, node: any) {
async function handleResourcesUpload(files: FileList, node: LGraphNode) {
if (!files?.length) return

try {
Expand Down Expand Up @@ -330,7 +335,9 @@
await nextTick()

useLoad3d(node).waitForLoad3d((load3d) => {
const cameraConfig = node.properties['Camera Config'] as any
const cameraConfig = node.properties['Camera Config'] as
| CameraConfig
| undefined
const cameraState = cameraConfig?.state

const config = new Load3DConfiguration(load3d, node.properties)
Expand All @@ -357,7 +364,9 @@
return null
}

const cameraConfig = (node.properties['Camera Config'] as any) || {
const cameraConfig: CameraConfig = (node.properties[
'Camera Config'
] as CameraConfig | undefined) || {
cameraType: currentLoad3d.getCurrentCameraType(),
fov: currentLoad3d.cameraManager.perspectiveCamera.fov
}
Expand Down Expand Up @@ -388,7 +397,8 @@
mask: `threed/${dataMask.name} [temp]`,
normal: `threed/${dataNormal.name} [temp]`,
camera_info:
(node.properties['Camera Config'] as any)?.state || null,
(node.properties['Camera Config'] as CameraConfig | undefined)
?.state || null,
recording: ''
}

Expand Down Expand Up @@ -472,7 +482,9 @@
if (lastTimeModelFile) {
modelWidget.value = lastTimeModelFile

const cameraConfig = node.properties['Camera Config'] as any
const cameraConfig = node.properties['Camera Config'] as
| CameraConfig
| undefined
const cameraState = cameraConfig?.state

const settings = {
Expand All @@ -484,21 +496,21 @@
config.configure(settings)
}

node.onExecuted = function (message: any) {
onExecuted?.apply(this, arguments as any)
node.onExecuted = function (output: NodeExecutionOutput) {
onExecuted?.call(this, output)

let filePath = message.result[0]
let filePath = output.result?.[0] as string | undefined

Check failure on line 502 in src/extensions/core/load3d.ts

View workflow job for this annotation

GitHub Actions / collect

Element implicitly has an 'any' type because expression of type '0' can't be used to index type '{}'.

Check failure on line 502 in src/extensions/core/load3d.ts

View workflow job for this annotation

GitHub Actions / setup

Element implicitly has an 'any' type because expression of type '0' can't be used to index type '{}'.

if (!filePath) {
const msg = t('toastMessages.unableToGetModelFilePath')
console.error(msg)
useToastStore().addAlert(msg)
}

let cameraState = message.result[1]
let bgImagePath = message.result[2]
const cameraState = output.result?.[1] as CameraState | undefined

Check failure on line 510 in src/extensions/core/load3d.ts

View workflow job for this annotation

GitHub Actions / collect

Element implicitly has an 'any' type because expression of type '1' can't be used to index type '{}'.

Check failure on line 510 in src/extensions/core/load3d.ts

View workflow job for this annotation

GitHub Actions / setup

Element implicitly has an 'any' type because expression of type '1' can't be used to index type '{}'.
const bgImagePath = output.result?.[2] as string | undefined

Check failure on line 511 in src/extensions/core/load3d.ts

View workflow job for this annotation

GitHub Actions / collect

Element implicitly has an 'any' type because expression of type '2' can't be used to index type '{}'.

Check failure on line 511 in src/extensions/core/load3d.ts

View workflow job for this annotation

GitHub Actions / setup

Element implicitly has an 'any' type because expression of type '2' can't be used to index type '{}'.

modelWidget.value = filePath.replaceAll('\\', '/')
modelWidget.value = filePath?.replaceAll('\\', '/')
Comment thread
coderabbitai[bot] marked this conversation as resolved.

node.properties['Last Time Model File'] = modelWidget.value

Expand Down
14 changes: 9 additions & 5 deletions src/extensions/core/load3d/AnimationManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as THREE from 'three'
import type { GLTF } from 'three/examples/jsm/loaders/GLTFLoader'

import {
type AnimationItem,
type AnimationManagerInterface,
type EventManagerInterface
import type {
AnimationItem,
AnimationManagerInterface,
EventManagerInterface
} from '@/extensions/core/load3d/interfaces'

export class AnimationManager implements AnimationManagerInterface {
Expand Down Expand Up @@ -38,7 +39,10 @@ export class AnimationManager implements AnimationManagerInterface {
this.eventManager.emitEvent('animationListChange', [])
}

setupModelAnimations(model: THREE.Object3D, originalModel: any): void {
setupModelAnimations(
model: THREE.Object3D,
originalModel: THREE.Object3D | THREE.BufferGeometry | GLTF | null
): void {
if (this.currentAnimation) {
this.currentAnimation.stopAllAction()
this.animationActions = []
Expand Down
10 changes: 5 additions & 5 deletions src/extensions/core/load3d/EventManager.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { type EventCallback, type EventManagerInterface } from './interfaces'

export class EventManager implements EventManagerInterface {
private listeners: { [key: string]: EventCallback[] } = {}
private listeners: Record<string, EventCallback[]> = {}

addEventListener(event: string, callback: EventCallback): void {
addEventListener<T>(event: string, callback: EventCallback<T>): void {
if (!this.listeners[event]) {
this.listeners[event] = []
}
this.listeners[event].push(callback)
this.listeners[event].push(callback as EventCallback)
}

removeEventListener(event: string, callback: EventCallback): void {
removeEventListener<T>(event: string, callback: EventCallback<T>): void {
if (this.listeners[event]) {
this.listeners[event] = this.listeners[event].filter(
(cb) => cb !== callback
)
}
}

emitEvent(event: string, data?: any): void {
emitEvent<T>(event: string, data: T): void {
if (this.listeners[event]) {
this.listeners[event].forEach((callback) => callback(data))
}
Expand Down
5 changes: 3 additions & 2 deletions src/extensions/core/load3d/Load3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ViewHelperManager } from './ViewHelperManager'
import {
type CameraState,
type CaptureResult,
type EventCallback,
type Load3DOptions,
type MaterialMode,
type UpDirection
Expand Down Expand Up @@ -610,11 +611,11 @@ class Load3d {
this.forceRender()
}

addEventListener(event: string, callback: (data?: any) => void): void {
addEventListener<T>(event: string, callback: EventCallback<T>): void {
this.eventManager.addEventListener(event, callback)
}

removeEventListener(event: string, callback: (data?: any) => void): void {
removeEventListener<T>(event: string, callback: EventCallback<T>): void {
this.eventManager.removeEventListener(event, callback)
}

Expand Down
15 changes: 9 additions & 6 deletions src/extensions/core/load3d/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export interface LightConfig {
intensity: number
}

export interface EventCallback {
(data?: any): void
export interface EventCallback<T = unknown> {
(data: T): void
}

export interface Load3DOptions {
Expand Down Expand Up @@ -128,9 +128,9 @@ export interface ViewHelperManagerInterface extends BaseManager {
}

export interface EventManagerInterface {
addEventListener(event: string, callback: EventCallback): void
removeEventListener(event: string, callback: EventCallback): void
emitEvent(event: string, data?: any): void
addEventListener<T>(event: string, callback: EventCallback<T>): void
removeEventListener<T>(event: string, callback: EventCallback<T>): void
emitEvent<T>(event: string, data: T): void
}

export interface AnimationManagerInterface extends BaseManager {
Expand All @@ -141,7 +141,10 @@ export interface AnimationManagerInterface extends BaseManager {
isAnimationPlaying: boolean
animationSpeed: number

setupModelAnimations(model: THREE.Object3D, originalModel: any): void
setupModelAnimations(
model: THREE.Object3D,
originalModel: THREE.Object3D | THREE.BufferGeometry | GLTF | null
): void
updateAnimationList(): void
setAnimationSpeed(speed: number): void
updateSelectedAnimation(index: number): void
Expand Down
Loading