From ee9cc9f78f2cd89e2ab94f5801088743744c4666 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Thu, 2 Jan 2025 16:17:05 -0800 Subject: [PATCH] Helper.ts: Clean up object deletion and pass object reference instead of UUID Because the object is already removed from scene, passing the UUID to timeline deletion never worked because it couldn't fetch the object from the UUID from the scene. By passing the object directly, we can still access the UUID and update the engines as necessary. --- app/pages/PageEnigma/Editor/helper.ts | 71 ++++++++++++++------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/app/pages/PageEnigma/Editor/helper.ts b/app/pages/PageEnigma/Editor/helper.ts index d2b07c0fdc..efcfa22fb4 100644 --- a/app/pages/PageEnigma/Editor/helper.ts +++ b/app/pages/PageEnigma/Editor/helper.ts @@ -105,7 +105,7 @@ export class SceneUtils { // TO UPDATE selected objects in the scene might want to add to the scene ... async setSelectedObject(position: XYZ, rotation: XYZ, scale: XYZ) { if (this.editor.sceneManager?.selected_objects) { - let object = this.editor.sceneManager?.selected_objects[0]; + const object = this.editor.sceneManager?.selected_objects[0]; if (object != undefined || object != null) { object.position.x = position.x; object.position.y = position.y; @@ -157,7 +157,7 @@ export class SceneUtils { () => document .getElementById("letterbox") - ?.addEventListener("contextmenu", function(event) { + ?.addEventListener("contextmenu", function (event) { event.preventDefault(); }), 250, @@ -232,46 +232,51 @@ function removeObject3D(object3D) { deleteObject(uuid: string) { const obj = this.scene.get_object_by_uuid(uuid); + + if (!obj) { + return + } + this.removeTransformControls(); - if (obj?.name === this.editor.camera_name) { + if (obj.name === this.editor.camera_name) { return; } - if (obj) { - // Finally remove the object from the scene - this.scene.scene.remove(obj); - obj.traverse(child => { - (child as THREE.Mesh)?.geometry?.dispose() - if (Array.isArray((child as THREE.Mesh).texture)) { - (child as THREE.Mesh).texture.forEach(mat => mat.dispose()); - } else if ((child as THREE.Mesh).texture) { - (child as THREE.Mesh).texture.dispose(); - } + // Finally remove the object from the scene + this.scene.scene.remove(obj); - if (Array.isArray((child as THREE.Mesh).material)) { - (child as THREE.Mesh).material.forEach(mat => mat.dispose()); - } else if ((child as THREE.Mesh).material) { - (child as THREE.Mesh).material.dispose(); - } - }) - - if (Array.isArray((obj as THREE.Mesh).texture)) { - (obj as THREE.Mesh).texture.forEach(mat => mat.dispose()); - } else if ((obj as THREE.Mesh).texture) { - (obj as THREE.Mesh).texture.dispose(); + obj.traverse(child => { + (child as THREE.Mesh)?.geometry?.dispose() + if (Array.isArray((child as THREE.Mesh).texture)) { + (child as THREE.Mesh).texture.forEach(mat => mat.dispose()); + } else if ((child as THREE.Mesh).texture) { + (child as THREE.Mesh).texture.dispose(); } - if (Array.isArray((obj as THREE.Mesh).material)) { - (obj as THREE.Mesh).material.forEach(mat => mat.dispose()); - } else if ((obj as THREE.Mesh).material) { - (obj as THREE.Mesh).material.dispose(); + if (Array.isArray((child as THREE.Mesh).material)) { + (child as THREE.Mesh).material.forEach(mat => mat.dispose()); + } else if ((child as THREE.Mesh).material) { + (child as THREE.Mesh).material.dispose(); } + }) - if ((obj as THREE.Mesh).geometry) { - (obj as THREE.Mesh).geometry.dispose() - } + if (Array.isArray((obj as THREE.Mesh).texture)) { + (obj as THREE.Mesh).texture.forEach(mat => mat.dispose()); + } else if ((obj as THREE.Mesh).texture) { + (obj as THREE.Mesh).texture.dispose(); } - this.editor.timeline.deleteObject(uuid); + + if (Array.isArray((obj as THREE.Mesh).material)) { + (obj as THREE.Mesh).material.forEach(mat => mat.dispose()); + } else if ((obj as THREE.Mesh).material) { + (obj as THREE.Mesh).material.dispose(); + } + + if ((obj as THREE.Mesh).geometry) { + (obj as THREE.Mesh).geometry.dispose() + } + + this.editor.timeline.deleteObject(obj); Queue.publish({ queueName: QueueNames.FROM_ENGINE, action: fromEngineActions.DELETE_OBJECT, @@ -286,6 +291,6 @@ function removeObject3D(object3D) { this.editor.selected = undefined; this.editor.publishSelect(); hideObjectPanel(); - this.editor.timeline.deleteObject(uuid); + this.editor.timeline.deleteObject(obj); } }