Skip to content

Commit

Permalink
[3d] improve storing Camera State logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jtydhr88 committed Jan 23, 2025
1 parent b54e270 commit b45b317
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
34 changes: 4 additions & 30 deletions src/extensions/core/load3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,20 +354,7 @@ app.registerExtension({

const fov = node.widgets.find((w: IWidget) => w.name === 'fov')

let cameraState
try {
const cameraInfo = node.properties['Camera Info']
if (
cameraInfo &&
typeof cameraInfo === 'string' &&
cameraInfo.trim() !== ''
) {
cameraState = JSON.parse(cameraInfo)
}
} catch (error) {
console.warn('Failed to parse camera state:', error)
cameraState = undefined
}
let cameraState = node.properties['Camera Info']

configureLoad3D(
load3d,
Expand All @@ -386,7 +373,7 @@ app.registerExtension({

// @ts-expect-error hacky override
sceneWidget.serializeValue = async () => {
node.properties['Camera Info'] = JSON.stringify(load3d.getCameraState())
node.properties['Camera Info'] = load3d.getCameraState()

const { scene: imageData, mask: maskData } = await load3d.captureScene(
w.value,
Expand Down Expand Up @@ -598,20 +585,7 @@ app.registerExtension({

const fov = node.widgets.find((w: IWidget) => w.name === 'fov')

let cameraState
try {
const cameraInfo = node.properties['Camera Info']
if (
cameraInfo &&
typeof cameraInfo === 'string' &&
cameraInfo.trim() !== ''
) {
cameraState = JSON.parse(cameraInfo)
}
} catch (error) {
console.warn('Failed to parse camera state:', error)
cameraState = undefined
}
let cameraState = node.properties['Camera Info']

configureLoad3D(
load3d,
Expand Down Expand Up @@ -643,7 +617,7 @@ app.registerExtension({

// @ts-expect-error hacky override
sceneWidget.serializeValue = async () => {
node.properties['Camera Info'] = JSON.stringify(load3d.getCameraState())
node.properties['Camera Info'] = load3d.getCameraState()

load3d.toggleAnimation(false)

Expand Down
4 changes: 4 additions & 0 deletions src/extensions/core/load3d/Load3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class Load3d {
)
this.controls.enableDamping = true

this.controls.addEventListener('end', () => {
this.storeNodeProperty('Camera Info', this.getCameraState())
})

this.gltfLoader = new GLTFLoader()
this.objLoader = new OBJLoader()
this.mtlLoader = new MTLLoader()
Expand Down

0 comments on commit b45b317

Please sign in to comment.