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