mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 02:32:18 +00:00
[3d] improve storing Camera State logic (#2328)
This commit is contained in:
@@ -354,20 +354,7 @@ app.registerExtension({
|
|||||||
|
|
||||||
const fov = node.widgets.find((w: IWidget) => w.name === 'fov')
|
const fov = node.widgets.find((w: IWidget) => w.name === 'fov')
|
||||||
|
|
||||||
let cameraState
|
let cameraState = node.properties['Camera Info']
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
configureLoad3D(
|
configureLoad3D(
|
||||||
load3d,
|
load3d,
|
||||||
@@ -386,7 +373,7 @@ app.registerExtension({
|
|||||||
|
|
||||||
// @ts-expect-error hacky override
|
// @ts-expect-error hacky override
|
||||||
sceneWidget.serializeValue = async () => {
|
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(
|
const { scene: imageData, mask: maskData } = await load3d.captureScene(
|
||||||
w.value,
|
w.value,
|
||||||
@@ -598,20 +585,7 @@ app.registerExtension({
|
|||||||
|
|
||||||
const fov = node.widgets.find((w: IWidget) => w.name === 'fov')
|
const fov = node.widgets.find((w: IWidget) => w.name === 'fov')
|
||||||
|
|
||||||
let cameraState
|
let cameraState = node.properties['Camera Info']
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
configureLoad3D(
|
configureLoad3D(
|
||||||
load3d,
|
load3d,
|
||||||
@@ -643,7 +617,7 @@ app.registerExtension({
|
|||||||
|
|
||||||
// @ts-expect-error hacky override
|
// @ts-expect-error hacky override
|
||||||
sceneWidget.serializeValue = async () => {
|
sceneWidget.serializeValue = async () => {
|
||||||
node.properties['Camera Info'] = JSON.stringify(load3d.getCameraState())
|
node.properties['Camera Info'] = load3d.getCameraState()
|
||||||
|
|
||||||
load3d.toggleAnimation(false)
|
load3d.toggleAnimation(false)
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ class Load3d {
|
|||||||
)
|
)
|
||||||
this.controls.enableDamping = true
|
this.controls.enableDamping = true
|
||||||
|
|
||||||
|
this.controls.addEventListener('end', () => {
|
||||||
|
this.storeNodeProperty('Camera Info', this.getCameraState())
|
||||||
|
})
|
||||||
|
|
||||||
this.gltfLoader = new GLTFLoader()
|
this.gltfLoader = new GLTFLoader()
|
||||||
this.objLoader = new OBJLoader()
|
this.objLoader = new OBJLoader()
|
||||||
this.mtlLoader = new MTLLoader()
|
this.mtlLoader = new MTLLoader()
|
||||||
@@ -576,6 +580,10 @@ class Load3d {
|
|||||||
|
|
||||||
if (this.viewHelper.animating) {
|
if (this.viewHelper.animating) {
|
||||||
this.viewHelper.update(delta)
|
this.viewHelper.update(delta)
|
||||||
|
|
||||||
|
if (!this.viewHelper.animating) {
|
||||||
|
this.storeNodeProperty('Camera Info', this.getCameraState())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderer.clear()
|
this.renderer.clear()
|
||||||
|
|||||||
@@ -149,6 +149,10 @@ class Load3dAnimation extends Load3d {
|
|||||||
|
|
||||||
if (this.viewHelper.animating) {
|
if (this.viewHelper.animating) {
|
||||||
this.viewHelper.update(delta)
|
this.viewHelper.update(delta)
|
||||||
|
|
||||||
|
if (!this.viewHelper.animating) {
|
||||||
|
this.storeNodeProperty('Camera Info', this.getCameraState())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.viewHelper.render(this.renderer)
|
this.viewHelper.render(this.renderer)
|
||||||
|
|||||||
Reference in New Issue
Block a user