From 323e8ce3867df9842e586b7ef794db735e22ad43 Mon Sep 17 00:00:00 2001 From: Miles Ryan <75916236+Quicksticks-oss@users.noreply.github.com> Date: Thu, 30 May 2024 19:25:44 -0400 Subject: [PATCH] Feature/bugfix saving (#447) Fixes saving and loading for new scenes. --- app/pages/PageEnigma/Editor/scene.ts | 14 ++--- .../proxy/storyteller_proxy_scene.ts | 57 ++++++++++++------- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/app/pages/PageEnigma/Editor/scene.ts b/app/pages/PageEnigma/Editor/scene.ts index ff9a24783b..3639a516ee 100644 --- a/app/pages/PageEnigma/Editor/scene.ts +++ b/app/pages/PageEnigma/Editor/scene.ts @@ -415,13 +415,13 @@ class Scene { 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; + glb.scene.userData["name"] = "Scene"; + glb.scene.userData["media_id"] = media_id; + glb.scene.userData["color"] = "#FFFFFF"; + glb.scene.userData["metalness"] = 0.0; + glb.scene.userData["shininess"] = 0.5; + glb.scene.userData["specular"] = 0.5; + glb.scene.userData["locked"] = false; this.scene.add(glb.scene); } diff --git a/app/pages/PageEnigma/proxy/storyteller_proxy_scene.ts b/app/pages/PageEnigma/proxy/storyteller_proxy_scene.ts index 7a378975e5..fad5e16ae8 100644 --- a/app/pages/PageEnigma/proxy/storyteller_proxy_scene.ts +++ b/app/pages/PageEnigma/proxy/storyteller_proxy_scene.ts @@ -26,32 +26,45 @@ export class StoryTellerProxyScene { this.sceneItemProxy = []; } + async getChildren(child: THREE.Object3D) { + if (this.lookUpDictionary[child.uuid] == null) { + this.lookUpDictionary[child.uuid] = new StoryTellerProxy3DObject( + this.version, + child.userData["media_id"], + ); + } + const proxyObject3D: StoryTellerProxy3DObject = + this.lookUpDictionary[child.uuid]; + proxyObject3D.position.copy(child.position); + proxyObject3D.rotation.copy(child.rotation); + proxyObject3D.scale.copy(child.scale); + proxyObject3D.object_user_data_name = child.userData.name; + proxyObject3D.object_name = child.name; + proxyObject3D.object_uuid = child.uuid; + proxyObject3D.color = child.userData["color"]; + proxyObject3D.metalness = child.userData["metalness"]; + proxyObject3D.shininess = child.userData["shininess"]; + proxyObject3D.specular = child.userData["specular"]; + proxyObject3D.locked = child.userData["locked"]; + const json_data = await proxyObject3D.toJSON(); + return json_data + } + public async saveToScene(): Promise { const results: ObjectJSON[] = []; if (this.scene.scene != null) { - for (const child of this.scene.scene.children) { - if (child.userData["media_id"] != undefined) { - if (this.lookUpDictionary[child.uuid] == null) { - this.lookUpDictionary[child.uuid] = new StoryTellerProxy3DObject( - this.version, - child.userData["media_id"], - ); + for (let pchild of this.scene.scene.children) { + if (pchild.type == "Group") { + for (let child of pchild.children) { + if (child.userData["media_id"] != undefined) { + results.push(await this.getChildren(child)); + } + } + } + else { + if (pchild.userData["media_id"] != undefined) { + results.push(await this.getChildren(pchild)); } - const proxyObject3D: StoryTellerProxy3DObject = - this.lookUpDictionary[child.uuid]; - proxyObject3D.position.copy(child.position); - proxyObject3D.rotation.copy(child.rotation); - proxyObject3D.scale.copy(child.scale); - proxyObject3D.object_user_data_name = child.userData.name; - proxyObject3D.object_name = child.name; - proxyObject3D.object_uuid = child.uuid; - proxyObject3D.color = child.userData["color"]; - proxyObject3D.metalness = child.userData["metalness"]; - proxyObject3D.shininess = child.userData["shininess"]; - proxyObject3D.specular = child.userData["specular"]; - proxyObject3D.locked = child.userData["locked"]; - const json_data = await proxyObject3D.toJSON(); - results.push(json_data); } } } else {