Line data Source code
1 : import { toRaw } from 'vue'
2 :
3 : import type Load3d from '@comfyorg/viewport3d/load3d/Load3d'
4 : import type {
5 : CameraConfig,
6 : CameraState,
7 : Model3DInfo
8 : } from '@comfyorg/viewport3d/load3d/interfaces'
9 : import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
10 :
11 : type Load3dSerializedBase = {
12 : camera_info: CameraState | null
13 : model_3d_info: Model3DInfo
14 : }
15 :
16 3 : export function snapshotLoad3dState(
17 : node: LGraphNode,
18 : load3d: Load3d
19 : ): Load3dSerializedBase {
20 : // `node.properties` is the node data store's reactive proxy, and useLoad3d
21 : // deep-watches `Camera Config` to mark the scene dirty. Recording the live
22 : // camera into the snapshot is a read of the scene, not a change to it, so
23 : // write through the raw object; otherwise every capture re-dirties the
24 : // scene and the capture-until-stable loop in load3d.ts never settles.
25 3 : const properties = toRaw(node.properties)
26 3 : const cameraConfig: CameraConfig = (properties['Camera Config'] as
27 : | CameraConfig
28 : | undefined) || {
29 : cameraType: load3d.getCurrentCameraType(),
30 : fov: load3d.cameraManager.perspectiveCamera.fov
31 : }
32 3 : cameraConfig.state = load3d.getCameraState()
33 3 : properties['Camera Config'] = cameraConfig
34 :
35 3 : load3d.stopRecording()
36 :
37 3 : const modelInfo = load3d.getModelInfo()
38 3 : const model_3d_info: Model3DInfo = modelInfo ? [modelInfo] : []
39 :
40 3 : return {
41 : camera_info: cameraConfig.state ?? null,
42 : model_3d_info
43 : }
44 : }
|