From 108a5607fa476d96a67ce417a8d03988e5d213ef Mon Sep 17 00:00:00 2001 From: liteng <930372551@qq.com> Date: Mon, 31 Dec 2018 20:39:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=9D=90=E8=B4=A8=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/component/MaterialComponent.js | 5 ++++ .../src/serialization/core/ServerObject.js | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/ShadowEditor.Web/src/component/MaterialComponent.js b/ShadowEditor.Web/src/component/MaterialComponent.js index d53c16c2..684e4719 100644 --- a/ShadowEditor.Web/src/component/MaterialComponent.js +++ b/ShadowEditor.Web/src/component/MaterialComponent.js @@ -1393,6 +1393,11 @@ MaterialComponent.prototype.updateMaterial = function () { editor.execute(new SetMaterialValueCommand(object, 'wireframeLinewidth', wireframeLinewidth.getValue())); } + if (this.selected.userData.Server === true) { // 服务端模型 + this.selected.userData.materials = this.selected.userData.materials || {}; + this.selected.userData.materials[material.uuid] = (new MaterialsSerializer()).toJSON(material); + } + this.updateUI(); if (textureWarning) { diff --git a/ShadowEditor.Web/src/serialization/core/ServerObject.js b/ShadowEditor.Web/src/serialization/core/ServerObject.js index ee322ceb..052b794d 100644 --- a/ShadowEditor.Web/src/serialization/core/ServerObject.js +++ b/ShadowEditor.Web/src/serialization/core/ServerObject.js @@ -1,6 +1,7 @@ import BaseSerializer from '../BaseSerializer'; import Object3DSerializer from './Object3DSerializer'; import ModelLoader from '../../loader/ModelLoader'; +import MaterialsSerializer from '../material/MaterialsSerializer'; /** * ServerObject @@ -20,6 +21,16 @@ ServerObject.prototype.toJSON = function (obj) { delete json.userData.obj; // 以后下载对象缓存统一改为obj delete json.userData.root; // 模型根节点 delete json.userData.helper; + + // 清理无用材质 + if (obj.userData.materials) { + Object.keys(obj.userData.materials).forEach(n => { + if (n !== obj.material.uuid) { + delete obj.userData.materials[n]; + } + }); + } + return json; }; @@ -37,6 +48,7 @@ ServerObject.prototype.fromJSON = function (json, options, environment) { loader.load(url, json.userData, environment).then(obj => { if (obj) { Object3DSerializer.prototype.fromJSON.call(this, json, obj); + this.parseMaterials(json, obj); resolve(obj); } else { resolve(null); @@ -45,4 +57,21 @@ ServerObject.prototype.fromJSON = function (json, options, environment) { }); }; +ServerObject.prototype.parseMaterials = function (json, obj) { + if (json.userData.materials) { + Object.values(json.userData.materials).forEach(n => { + this.parseMaterial(n, obj); + }); + } +}; + +ServerObject.prototype.parseMaterial = function (json, obj) { + if (obj.material.uuid === json.uuid) { + var material = obj.material; + obj.material = (new MaterialsSerializer()).fromJSON(json); + obj.material.needsUpdate = true; + material.dispose(); + } +}; + export default ServerObject; \ No newline at end of file