From 970b2094865db0f89fb120aeaed03d08c2fd925a Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Mon, 9 Sep 2019 21:39:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=86=8D=E4=BE=9D=E8=B5=96=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=AB=AF=E6=A8=A1=E5=9E=8B`userData.changed`=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=BF=98=E5=8E=9F=E4=BF=AE=E6=94=B9=E8=BF=87=E7=9A=84?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=90=8D=E7=A7=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../src/serialization/Converter.js | 12 ++++- .../src/serialization/core/ServerObject.js | 49 ------------------- 3 files changed, 11 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 5262b61a..f2c21111 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Supported Languages: 中文 / [繁體中文](README-tw.md) / [English](README-en ## v0.3.3即将更新 1. 一键清理没用的场景和场景历史记录工具。 +2. 不再依赖服务端模型`userData.changed`属性还原修改过的组件名称。 ## v0.3.2更新 diff --git a/ShadowEditor.Web/src/serialization/Converter.js b/ShadowEditor.Web/src/serialization/Converter.js index aa2c69d4..47f224b3 100644 --- a/ShadowEditor.Web/src/serialization/Converter.js +++ b/ShadowEditor.Web/src/serialization/Converter.js @@ -125,8 +125,16 @@ Converter.prototype.toJSON = function (obj) { } // 将场景转为json - scene.userData.children = []; // 将层级结构保存在场景中,以供场景加载时还原。 - this.traverse(scene, scene.userData.children, list); + let children = []; // 将层级结构保存在场景中,以供场景加载时还原。 + this.traverse(scene, children, list); + + let sceneJson = list.filter(n => n.uuid === scene.uuid)[0]; + + if (sceneJson) { + sceneJson.userData.children = children; + } else { + console.warn(`Converter: no scene json with id ${scene.uuid}`); + } return list; }; diff --git a/ShadowEditor.Web/src/serialization/core/ServerObject.js b/ShadowEditor.Web/src/serialization/core/ServerObject.js index 4dde6843..c2707564 100644 --- a/ShadowEditor.Web/src/serialization/core/ServerObject.js +++ b/ShadowEditor.Web/src/serialization/core/ServerObject.js @@ -26,10 +26,6 @@ ServerObject.prototype.toJSON = function (obj) { json.userData.children = []; this.serializeChildren(obj.children, json.userData.children); - // 记录修改过的名称 - json.userData.changed = []; // 对应模型的children - this.serializeChanged(obj, 0, json.userData.changed); - return json; }; @@ -55,26 +51,6 @@ ServerObject.prototype.serializeChildren = function (children, list) { } }; -/** - * 序列化模型修改过的属性 - * @param {THREE.Object3D} obj 模型或部件 - * @param {Integer} index 索引 - * @param {Object} changed 修改过的属性 - */ -ServerObject.prototype.serializeChanged = function (obj, index, changed) { - changed[index] = { - name: obj.name, - }; - - if (obj.children) { - changed[index].children = []; - - obj.children.forEach((n, i) => { - this.serializeChanged(n, i, changed[index].children); - }); - } -}; - ServerObject.prototype.fromJSON = function (json, options, environment) { let url = json.userData.Url; @@ -102,11 +78,6 @@ ServerObject.prototype.fromJSON = function (json, options, environment) { // 还原原来修改过的模型 this.revertObject(obj, environment.parts); - // 还原原来修改过的名称 - if (json.userData.changed) { - this.parseChanged(obj, 0, json.userData.changed); - } - resolve(obj); } else { resolve(null); @@ -134,26 +105,6 @@ ServerObject.prototype.parseChildren = function (children, list) { } }; -/** - * 还原修改过的属性 - * @param {THREE.Object3D} obj 模型或部件 - * @param {Integer} index 索引 - * @param {Array} changed 修改过的属性 - */ -ServerObject.prototype.parseChanged = function (obj, index, changed) { - if (obj && changed[index]) { - obj.name = changed[index].name; - } - - if (obj.children && changed[index]) { - var changed1 = changed[index].children; - - obj.children.forEach((n, i) => { - this.parseChanged(n, i, changed1); - }); - } -}; - /** * 还原调整过顺序的原始模型。 * @param {THREE.Object3D} obj 服务端模型