diff --git a/app/pages/PageEnigma/Editor/keybinds_controls.ts b/app/pages/PageEnigma/Editor/keybinds_controls.ts index 2d57871bb2..a0ad30b4ed 100644 --- a/app/pages/PageEnigma/Editor/keybinds_controls.ts +++ b/app/pages/PageEnigma/Editor/keybinds_controls.ts @@ -111,7 +111,7 @@ export class MouseControls { if (intersects.length > 0) { if (intersects[0].object.type != "GridHelper") { let currentObject = intersects[0].object; - while (currentObject.parent && currentObject.parent.type !== "Scene") { + while (currentObject.parent?.parent && currentObject.parent?.parent.type !== "Scene") { currentObject = currentObject.parent; } this.editor.selected = currentObject; diff --git a/app/pages/PageEnigma/Editor/scene.ts b/app/pages/PageEnigma/Editor/scene.ts index 2f152625c3..ff9a24783b 100644 --- a/app/pages/PageEnigma/Editor/scene.ts +++ b/app/pages/PageEnigma/Editor/scene.ts @@ -331,6 +331,28 @@ class Scene { return await this.loadGlbWithPlaceholder(media_id, name, auto_add, position); } + addChildrenToScene(parent: THREE.Object3D, scene: THREE.Scene): void { + parent.children.forEach((child: THREE.Object3D) => { + scene.add(child); + // If the child has its own children, recursively add them + if (child.children && child.children.length > 0) { + this.addChildrenToScene(child, scene); + } + }); + } + + containsGroup(object: THREE.Object3D): boolean { + if (object instanceof THREE.Group) { + return true; + } + for (const child of object.children) { + if (this.containsGroup(child)) { + return true; + } + } + return false; + } + async loadGlbWithPlaceholder( media_id: string, name: string, @@ -388,12 +410,21 @@ class Scene { child.userData["locked"] = false; child.layers.enable(0); child.layers.enable(1); - if (auto_add) { - this.scene.add(child); - } child_result = child; }); + if (auto_add) { + glb.scene.name = "Scene"; + glb.userData["name"] = "Scene"; + glb.userData["media_id"] = media_id; + glb.userData["color"] = "#FFFFFF"; + glb.userData["metalness"] = 0.0; + glb.userData["shininess"] = 0.5; + glb.userData["specular"] = 0.5; + glb.userData["locked"] = false; + this.scene.add(glb.scene); + } + if (child_result == undefined) { throw Error("GLB Did not contain an object or children."); }