diff --git a/ShadowEditor.Server/Controllers/Export/ExportSceneController.cs b/ShadowEditor.Server/Controllers/Export/ExportSceneController.cs index 78c69e52..7da5f7e7 100644 --- a/ShadowEditor.Server/Controllers/Export/ExportSceneController.cs +++ b/ShadowEditor.Server/Controllers/Export/ExportSceneController.cs @@ -12,6 +12,7 @@ using MongoDB.Driver; using Newtonsoft.Json.Linq; using ShadowEditor.Server.Base; using ShadowEditor.Server.Helpers; +using System.Text; namespace ShadowEditor.Server.Controllers.Export { @@ -70,7 +71,10 @@ namespace ShadowEditor.Server.Controllers.Export // 拷贝静态资源 var viewPath = HttpContext.Current.Server.MapPath("~/view.html"); - File.Copy(viewPath, $"{path}/view.html", true); + + var viewFileData = File.ReadAllText(viewPath, Encoding.UTF8); + viewFileData = viewFileData.Replace("location.origin", "'.'"); // 替换server地址,以便部署到Git Pages上 + File.WriteAllText($"{path}/view.html", viewFileData, Encoding.UTF8); var faviconPath = HttpContext.Current.Server.MapPath("~/favicon.ico"); File.Copy(faviconPath, $"{path}/favicon.ico", true); @@ -81,31 +85,15 @@ namespace ShadowEditor.Server.Controllers.Export var buildPath = HttpContext.Current.Server.MapPath($"~/build"); DirectoryHelper.Copy(buildPath, $"{path}/build"); - // 拷贝场景数据 + // 分析场景,拷贝使用的资源 var data = new JArray(); - foreach (var i in docs) - { - i["_id"] = i["_id"].ToString(); // ObjectId - data.Add(JsonHelper.ToObject(i.ToJson())); - } - - if (!Directory.Exists($"{path}/Scene")) - { - Directory.CreateDirectory($"{path}/Scene"); - } - - var file = new FileStream($"{path}/Scene/{ID}.txt", FileMode.Create, FileAccess.Write); - var writer = new StreamWriter(file); - writer.Write(JsonHelper.ToJson(data)); - writer.Close(); - file.Close(); - - // 分析场景,拷贝使用的资源 var urls = new List(); foreach (var i in docs) { + i["_id"] = i["_id"].ToString(); // ObjectId + var generator = i["metadata"]["generator"].ToString(); if (generator == "ServerObject") // 服务端模型 @@ -190,8 +178,23 @@ namespace ShadowEditor.Server.Controllers.Export urls.Add(i["material"]["roughnessMap"]["image"]["src"].ToString()); } } + + data.Add(JsonHelper.ToObject(i.ToJson())); } + // 将场景写入文件 + if (!Directory.Exists($"{path}/Scene")) + { + Directory.CreateDirectory($"{path}/Scene"); + } + + // 复制资源 + var file = new FileStream($"{path}/Scene/{ID}.txt", FileMode.Create, FileAccess.Write); + var writer = new StreamWriter(file); + writer.Write(JsonHelper.ToJson(data)); + writer.Close(); + file.Close(); + foreach (var url in urls) { if (!url.StartsWith("/")) // 可能是base64地址 diff --git a/ShadowEditor.Web/src/loader/MMDLoader.js b/ShadowEditor.Web/src/loader/MMDLoader.js index ac858d5e..431f3207 100644 --- a/ShadowEditor.Web/src/loader/MMDLoader.js +++ b/ShadowEditor.Web/src/loader/MMDLoader.js @@ -64,7 +64,7 @@ MMDLoader.prototype.loadWithAnimation = function (url, options, environment, loa } return new Promise(resolve => { - loader.loadWithAnimation(url, [options.Animation.Url], mmd => { + loader.loadWithAnimation(url, [environment.server + options.Animation.Url], mmd => { resolve(mmd); }, undefined, () => { resolve(null); @@ -80,7 +80,7 @@ MMDLoader.prototype.loadCameraAnimation = function (url, options, environment, l } return new Promise(resolve => { - loader.loadAnimation([options.CameraAnimation.Url], environment.camera, vmd => { + loader.loadAnimation([environment.server + options.CameraAnimation.Url], environment.camera, vmd => { resolve(vmd); }, undefined, () => { resolve(null); @@ -97,7 +97,7 @@ MMDLoader.prototype.loadAudio = function (url, options, environment, loader) { return new Promise(resolve => { var loader = new THREE.AudioLoader(); - loader.load(options.Audio.Url, buffer => { + loader.load(environment.server + options.Audio.Url, buffer => { var audio = new THREE.Audio(environment.audioListener).setBuffer(buffer); Object.assign(audio.userData, options.Audio); resolve(audio); diff --git a/ShadowEditor.Web/src/serialization/Converter.js b/ShadowEditor.Web/src/serialization/Converter.js index bdd0beb5..b80cf19e 100644 --- a/ShadowEditor.Web/src/serialization/Converter.js +++ b/ShadowEditor.Web/src/serialization/Converter.js @@ -61,6 +61,7 @@ Converter.prototype.constructor = Converter; /** * 将应用转为json * @param {*} obj 格式:{ options: options, camera: camera, renderer: renderer, scripts: scripts, scene: scene } + * @param {*} obj.server 服务端地址 */ Converter.prototype.toJSON = function (obj) { var options = obj.options; @@ -191,6 +192,7 @@ Converter.prototype.sceneToJson = function (scene, list) { * 场景反序列化 * @param {*} jsons json对象(列表) * @param {*} options 配置选项 格式:{ server: serverUrl } 其中,serverUrl为服务端地址,用于下载模型、纹理等资源 + * @param {*} options.server 服务端地址 */ Converter.prototype.fromJson = function (jsons, options) { var obj = { @@ -306,7 +308,7 @@ Converter.prototype.sceneFromJson = function (jsons, options) { switch (objJson.metadata.generator) { case 'SceneSerializer': - obj = (new SceneSerializer()).fromJSON(objJson); + obj = (new SceneSerializer()).fromJSON(objJson, undefined, options.server); break; case 'GroupSerializer': obj = (new GroupSerializer()).fromJSON(objJson); diff --git a/ShadowEditor.Web/src/serialization/core/SceneSerializer.js b/ShadowEditor.Web/src/serialization/core/SceneSerializer.js index feb8423e..872d60aa 100644 --- a/ShadowEditor.Web/src/serialization/core/SceneSerializer.js +++ b/ShadowEditor.Web/src/serialization/core/SceneSerializer.js @@ -29,7 +29,7 @@ SceneSerializer.prototype.toJSON = function (obj) { return json; }; -SceneSerializer.prototype.fromJSON = function (json, parent) { +SceneSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.Scene() : parent; Object3DSerializer.prototype.fromJSON(json, obj); @@ -38,7 +38,7 @@ SceneSerializer.prototype.fromJSON = function (json, parent) { (json.background.metadata.generator === 'CubeTextureSerializer' || json.background.metadata.generator === 'TextureSerializer') ) { // 天空盒和背景图片 - obj.background = new TexturesSerializer().fromJSON(json.background); + obj.background = new TexturesSerializer().fromJSON(json.background, undefined, server); } else { // 纯色 obj.background = new THREE.Color(json.background); } @@ -51,7 +51,7 @@ SceneSerializer.prototype.fromJSON = function (json, parent) { console.warn(`SceneSerializer: unknown fog type ${json.fog.type}.`); } - obj.overrideMaterial = json.overrideMaterial == null ? null : (new MaterialsSerializer()).fromJSON(json.overrideMaterial); + obj.overrideMaterial = json.overrideMaterial == null ? null : (new MaterialsSerializer()).fromJSON(json.overrideMaterial, undefined, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/core/ServerObject.js b/ShadowEditor.Web/src/serialization/core/ServerObject.js index 296e49bc..e656966a 100644 --- a/ShadowEditor.Web/src/serialization/core/ServerObject.js +++ b/ShadowEditor.Web/src/serialization/core/ServerObject.js @@ -66,6 +66,9 @@ ServerObject.prototype.fromJSON = function (json, options, environment) { url = options.server + url; } + // 将server传递给MMDLoader,以便下载资源 + environment.server = options.server; + return new Promise(resolve => { var loader = new ModelLoader(); loader.load(url, json.userData, environment).then(obj => { diff --git a/ShadowEditor.Web/src/serialization/material/LineBasicMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/LineBasicMaterialSerializer.js index 83a7bd43..7406ed38 100644 --- a/ShadowEditor.Web/src/serialization/material/LineBasicMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/LineBasicMaterialSerializer.js @@ -16,10 +16,10 @@ LineBasicMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -LineBasicMaterialSerializer.prototype.fromJSON = function (json, parent) { +LineBasicMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.LineBasicMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/LineDashedMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/LineDashedMaterialSerializer.js index 1133c73d..86122ed0 100644 --- a/ShadowEditor.Web/src/serialization/material/LineDashedMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/LineDashedMaterialSerializer.js @@ -16,10 +16,10 @@ LineDashedMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -LineDashedMaterialSerializer.prototype.fromJSON = function (json, parent) { +LineDashedMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.LineDashedMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MaterialSerializer.js index 28e966ba..c1161b25 100644 --- a/ShadowEditor.Web/src/serialization/material/MaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MaterialSerializer.js @@ -86,12 +86,12 @@ MaterialSerializer.prototype.toJSON = function (obj) { return json; }; -MaterialSerializer.prototype.fromJSON = function (json, parent) { +MaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.Material() : parent; - obj.alphaMap = json.alphaMap == null ? null : (new TexturesSerializer()).fromJSON(json.alphaMap); + obj.alphaMap = json.alphaMap == null ? null : (new TexturesSerializer()).fromJSON(json.alphaMap, undefined, server); obj.alphaTest = json.alphaTest; - obj.aoMap = json.aoMap == null ? null : (new TexturesSerializer()).fromJSON(json.aoMap); + obj.aoMap = json.aoMap == null ? null : (new TexturesSerializer()).fromJSON(json.aoMap, undefined, server); obj.aoMapIntensity = json.aoMapIntensity; obj.blendDst = json.blendDst; obj.blendDstAlpha = json.blendDstAlpha; @@ -100,7 +100,7 @@ MaterialSerializer.prototype.fromJSON = function (json, parent) { obj.blendSrc = json.blendSrc; obj.blendSrcAlpha = json.blendSrcAlpha; obj.blending = json.blending; - obj.bumpMap = json.bumpMap == null ? null : (new TexturesSerializer()).fromJSON(json.bumpMap); + obj.bumpMap = json.bumpMap == null ? null : (new TexturesSerializer()).fromJSON(json.bumpMap, undefined, server); obj.bumpScale = json.bumpScale; obj.clipIntersection = json.clipIntersection; obj.clipShadow = json.clipShadow; @@ -111,27 +111,27 @@ MaterialSerializer.prototype.fromJSON = function (json, parent) { obj.depthTest = json.depthTest; obj.depthWrite = json.depthWrite; obj.displacementBias = json.displacementBias; - obj.displacementMap = json.displacementMap == null ? null : (new TexturesSerializer()).fromJSON(json.displacementMap); + obj.displacementMap = json.displacementMap == null ? null : (new TexturesSerializer()).fromJSON(json.displacementMap, undefined, server); obj.displacementScale = json.displacementScale; obj.dithering = json.dithering; obj.emissive = json.emissive == null ? undefined : new THREE.Color(json.emissive); obj.emissiveIntensity = json.emissiveIntensity; - obj.emissiveMap = json.emissiveMap == null ? null : (new TexturesSerializer()).fromJSON(json.emissiveMap); - obj.envMap = json.envMap == null ? null : (new TexturesSerializer()).fromJSON(json.envMap); + obj.emissiveMap = json.emissiveMap == null ? null : (new TexturesSerializer()).fromJSON(json.emissiveMap, undefined, server); + obj.envMap = json.envMap == null ? null : (new TexturesSerializer()).fromJSON(json.envMap, undefined, server); obj.envMapIntensity = json.envMapIntensity; obj.flatShading = json.flatShading; obj.fog = json.fog; - obj.lightMap = json.lightMap == null ? null : (new TexturesSerializer()).fromJSON(json.lightMap); + obj.lightMap = json.lightMap == null ? null : (new TexturesSerializer()).fromJSON(json.lightMap, undefined, server); obj.lightMapIntensity = json.lightMapIntensity; obj.lights = json.lights; obj.linewidth = json.linewidth; obj.map = json.map == null ? null : (new TexturesSerializer()).fromJSON(json.map); obj.metalness = json.metalness; - obj.metalnessMap = json.metalnessMap == null ? null : (new TexturesSerializer()).fromJSON(json.metalnessMap); + obj.metalnessMap = json.metalnessMap == null ? null : (new TexturesSerializer()).fromJSON(json.metalnessMap, undefined, server); obj.morphNormals = json.morphNormals; obj.morphTargets = json.morphTargets; obj.name = json.name; - obj.normalMap = json.normalMap == null ? null : (new TexturesSerializer()).fromJSON(json.normalMap); + obj.normalMap = json.normalMap == null ? null : (new TexturesSerializer()).fromJSON(json.normalMap, undefined, server); obj.normalScale = json.normalScale == null ? null : new THREE.Vector2().copy(json.normalScale); obj.opacity = json.opacity; obj.polygonOffset = json.polygonOffset; @@ -141,7 +141,7 @@ MaterialSerializer.prototype.fromJSON = function (json, parent) { obj.premultipliedAlpha = json.premultipliedAlpha; obj.refractionRatio = json.refractionRatio; obj.roughness = json.roughness; - obj.roughnessMap = json.roughnessMap == null ? null : (new TexturesSerializer()).fromJSON(json.roughnessMap); + obj.roughnessMap = json.roughnessMap == null ? null : (new TexturesSerializer()).fromJSON(json.roughnessMap, undefined, server); obj.shadowSide = json.shadowSide; obj.side = json.side; obj.skinning = json.skinning; diff --git a/ShadowEditor.Web/src/serialization/material/MaterialsSerializer.js b/ShadowEditor.Web/src/serialization/material/MaterialsSerializer.js index 722aff0f..ce3479c3 100644 --- a/ShadowEditor.Web/src/serialization/material/MaterialsSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MaterialsSerializer.js @@ -70,7 +70,7 @@ MaterialsSerializer.prototype.toJSON = function (obj) { return (new serializer()).toJSON(obj); }; -MaterialsSerializer.prototype.fromJSON = function (json, parent) { +MaterialsSerializer.prototype.fromJSON = function (json, parent, server) { var generator = json.metadata.generator; var serializer = Serializers[generator.replace('Serializer', '')]; @@ -80,7 +80,7 @@ MaterialsSerializer.prototype.fromJSON = function (json, parent) { return null; } - return (new serializer()).fromJSON(json, parent); + return (new serializer()).fromJSON(json, parent, server); }; export default MaterialsSerializer; \ No newline at end of file diff --git a/ShadowEditor.Web/src/serialization/material/MeshBasicMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MeshBasicMaterialSerializer.js index 6465f984..2621b16a 100644 --- a/ShadowEditor.Web/src/serialization/material/MeshBasicMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MeshBasicMaterialSerializer.js @@ -16,10 +16,10 @@ MeshBasicMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MeshBasicMaterialSerializer.prototype.fromJSON = function (json, parent) { +MeshBasicMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MeshBasicMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MeshDepthMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MeshDepthMaterialSerializer.js index a6adacb2..4cf6e30b 100644 --- a/ShadowEditor.Web/src/serialization/material/MeshDepthMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MeshDepthMaterialSerializer.js @@ -16,10 +16,10 @@ MeshDepthMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MeshDepthMaterialSerializer.prototype.fromJSON = function (json, parent) { +MeshDepthMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MeshDepthMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MeshDistanceMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MeshDistanceMaterialSerializer.js index b4b31211..a0cd9800 100644 --- a/ShadowEditor.Web/src/serialization/material/MeshDistanceMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MeshDistanceMaterialSerializer.js @@ -16,10 +16,10 @@ MeshDistanceMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MeshDistanceMaterialSerializer.prototype.fromJSON = function (json, parent) { +MeshDistanceMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MeshDistanceMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MeshFaceMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MeshFaceMaterialSerializer.js index 6eac5f9b..26e3c223 100644 --- a/ShadowEditor.Web/src/serialization/material/MeshFaceMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MeshFaceMaterialSerializer.js @@ -16,10 +16,10 @@ MeshFaceMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MeshFaceMaterialSerializer.prototype.fromJSON = function (json, parent) { +MeshFaceMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MeshFaceMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MeshLambertMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MeshLambertMaterialSerializer.js index 7f542b9e..383e769a 100644 --- a/ShadowEditor.Web/src/serialization/material/MeshLambertMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MeshLambertMaterialSerializer.js @@ -16,10 +16,10 @@ MeshLambertMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MeshLambertMaterialSerializer.prototype.fromJSON = function (json, parent) { +MeshLambertMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MeshLambertMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MeshNormalMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MeshNormalMaterialSerializer.js index 9f08a10b..5498d799 100644 --- a/ShadowEditor.Web/src/serialization/material/MeshNormalMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MeshNormalMaterialSerializer.js @@ -16,10 +16,10 @@ MeshNormalMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MeshNormalMaterialSerializer.prototype.fromJSON = function (json, parent) { +MeshNormalMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MeshNormalMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MeshPhongMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MeshPhongMaterialSerializer.js index 6788f51c..a308d193 100644 --- a/ShadowEditor.Web/src/serialization/material/MeshPhongMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MeshPhongMaterialSerializer.js @@ -16,10 +16,10 @@ MeshPhongMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MeshPhongMaterialSerializer.prototype.fromJSON = function (json, parent) { +MeshPhongMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MeshPhongMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MeshPhysicalMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MeshPhysicalMaterialSerializer.js index e627f6b2..21505f3d 100644 --- a/ShadowEditor.Web/src/serialization/material/MeshPhysicalMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MeshPhysicalMaterialSerializer.js @@ -16,10 +16,10 @@ MeshPhysicalMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MeshPhysicalMaterialSerializer.prototype.fromJSON = function (json, parent) { +MeshPhysicalMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MeshPhysicalMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MeshStandardMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MeshStandardMaterialSerializer.js index e989c4c7..6e2facbe 100644 --- a/ShadowEditor.Web/src/serialization/material/MeshStandardMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MeshStandardMaterialSerializer.js @@ -16,10 +16,10 @@ MeshStandardMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MeshStandardMaterialSerializer.prototype.fromJSON = function (json, parent) { +MeshStandardMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MeshStandardMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MeshToonMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MeshToonMaterialSerializer.js index 57dd9c45..caec4711 100644 --- a/ShadowEditor.Web/src/serialization/material/MeshToonMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MeshToonMaterialSerializer.js @@ -16,10 +16,10 @@ MeshToonMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MeshToonMaterialSerializer.prototype.fromJSON = function (json, parent) { +MeshToonMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MeshToonMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/MultiMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/MultiMaterialSerializer.js index c39fb855..c9925c82 100644 --- a/ShadowEditor.Web/src/serialization/material/MultiMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/MultiMaterialSerializer.js @@ -16,10 +16,10 @@ MultiMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -MultiMaterialSerializer.prototype.fromJSON = function (json, parent) { +MultiMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.MultiMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/ParticleBasicMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/ParticleBasicMaterialSerializer.js index 3ab47f85..e82a5932 100644 --- a/ShadowEditor.Web/src/serialization/material/ParticleBasicMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/ParticleBasicMaterialSerializer.js @@ -16,10 +16,10 @@ ParticleBasicMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -ParticleBasicMaterialSerializer.prototype.fromJSON = function (json, parent) { +ParticleBasicMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.ParticleBasicMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/ParticleSystemMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/ParticleSystemMaterialSerializer.js index 499540ed..992f532c 100644 --- a/ShadowEditor.Web/src/serialization/material/ParticleSystemMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/ParticleSystemMaterialSerializer.js @@ -16,10 +16,10 @@ ParticleSystemMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -ParticleSystemMaterialSerializer.prototype.fromJSON = function (json, parent) { +ParticleSystemMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.ParticleSystemMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/PointCloudMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/PointCloudMaterialSerializer.js index ddf4f133..f6a7af2a 100644 --- a/ShadowEditor.Web/src/serialization/material/PointCloudMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/PointCloudMaterialSerializer.js @@ -16,10 +16,10 @@ PointCloudMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -PointCloudMaterialSerializer.prototype.fromJSON = function (json, parent) { +PointCloudMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.PointCloudMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/PointsMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/PointsMaterialSerializer.js index 1ceb8536..859d7af5 100644 --- a/ShadowEditor.Web/src/serialization/material/PointsMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/PointsMaterialSerializer.js @@ -16,10 +16,10 @@ PointsMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -PointsMaterialSerializer.prototype.fromJSON = function (json, parent) { +PointsMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.PointsMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/RawShaderMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/RawShaderMaterialSerializer.js index 23c92c97..67f531d3 100644 --- a/ShadowEditor.Web/src/serialization/material/RawShaderMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/RawShaderMaterialSerializer.js @@ -39,10 +39,10 @@ RawShaderMaterialSerializer.prototype.toJSON = function (obj) { return json; }; -RawShaderMaterialSerializer.prototype.fromJSON = function (json, parent) { +RawShaderMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.RawShaderMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); obj.defines = json.defines; diff --git a/ShadowEditor.Web/src/serialization/material/ShaderMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/ShaderMaterialSerializer.js index e14754ae..283a5471 100644 --- a/ShadowEditor.Web/src/serialization/material/ShaderMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/ShaderMaterialSerializer.js @@ -39,10 +39,10 @@ ShaderMaterialSerializer.prototype.toJSON = function (obj) { return json; }; -ShaderMaterialSerializer.prototype.fromJSON = function (json, parent) { +ShaderMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.ShaderMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); obj.defines = json.defines; diff --git a/ShadowEditor.Web/src/serialization/material/ShadowMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/ShadowMaterialSerializer.js index d6f44549..301705e8 100644 --- a/ShadowEditor.Web/src/serialization/material/ShadowMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/ShadowMaterialSerializer.js @@ -16,10 +16,10 @@ ShadowMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -ShadowMaterialSerializer.prototype.fromJSON = function (json, parent) { +ShadowMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.ShadowMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/SpriteCanvasMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/SpriteCanvasMaterialSerializer.js index b617665d..48ee3d00 100644 --- a/ShadowEditor.Web/src/serialization/material/SpriteCanvasMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/SpriteCanvasMaterialSerializer.js @@ -16,10 +16,10 @@ SpriteCanvasMaterialSerializer.prototype.toJSON = function (obj) { return MaterialSerializer.prototype.toJSON.call(this, obj); }; -SpriteCanvasMaterialSerializer.prototype.fromJSON = function (json, parent) { +SpriteCanvasMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.SpriteCanvasMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/material/SpriteMaterialSerializer.js b/ShadowEditor.Web/src/serialization/material/SpriteMaterialSerializer.js index fdcd8a49..a3ecc9b8 100644 --- a/ShadowEditor.Web/src/serialization/material/SpriteMaterialSerializer.js +++ b/ShadowEditor.Web/src/serialization/material/SpriteMaterialSerializer.js @@ -18,10 +18,10 @@ SpriteMaterialSerializer.prototype.toJSON = function (obj) { return json; }; -SpriteMaterialSerializer.prototype.fromJSON = function (json, parent) { +SpriteMaterialSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.SpriteMaterial() : parent; - MaterialSerializer.prototype.fromJSON.call(this, json, obj); + MaterialSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/texture/CanvasTextureSerializer.js b/ShadowEditor.Web/src/serialization/texture/CanvasTextureSerializer.js index 13512086..0c9150fd 100644 --- a/ShadowEditor.Web/src/serialization/texture/CanvasTextureSerializer.js +++ b/ShadowEditor.Web/src/serialization/texture/CanvasTextureSerializer.js @@ -16,10 +16,10 @@ CanvasTextureSerializer.prototype.toJSON = function (obj) { return TextureSerializer.prototype.toJSON.call(this, obj); }; -CanvasTextureSerializer.prototype.fromJSON = function (json, parent) { +CanvasTextureSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.CanvasTexture() : parent; - TextureSerializer.prototype.fromJSON.call(this, json, obj); + TextureSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/texture/CompressedTextureSerializer.js b/ShadowEditor.Web/src/serialization/texture/CompressedTextureSerializer.js index 262b1528..ec7f237a 100644 --- a/ShadowEditor.Web/src/serialization/texture/CompressedTextureSerializer.js +++ b/ShadowEditor.Web/src/serialization/texture/CompressedTextureSerializer.js @@ -16,10 +16,10 @@ CompressedTextureSerializer.prototype.toJSON = function (obj) { return TextureSerializer.prototype.toJSON.call(this, obj); }; -CompressedTextureSerializer.prototype.fromJSON = function (json, parent) { +CompressedTextureSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.CompressedTexture() : parent; - TextureSerializer.prototype.fromJSON.call(this, json, obj); + TextureSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/texture/CubeTextureSerializer.js b/ShadowEditor.Web/src/serialization/texture/CubeTextureSerializer.js index 2852d1a5..28631923 100644 --- a/ShadowEditor.Web/src/serialization/texture/CubeTextureSerializer.js +++ b/ShadowEditor.Web/src/serialization/texture/CubeTextureSerializer.js @@ -31,12 +31,12 @@ CubeTextureSerializer.prototype.toJSON = function (obj) { return json; }; -CubeTextureSerializer.prototype.fromJSON = function (json, parent) { +CubeTextureSerializer.prototype.fromJSON = function (json, parent, server) { // 用一个像素的图片初始化CubeTexture,避免图片载入前的警告信息。 var img = ImageUtils.onePixelCanvas(); var obj = parent === undefined ? new THREE.CubeTexture([img, img, img, img, img, img]) : parent; - TextureSerializer.prototype.fromJSON.call(this, json, obj); + TextureSerializer.prototype.fromJSON.call(this, json, obj, server); if (Array.isArray(json.image)) { var promises = json.image.map(n => { diff --git a/ShadowEditor.Web/src/serialization/texture/DataTextureSerializer.js b/ShadowEditor.Web/src/serialization/texture/DataTextureSerializer.js index 5da79780..b05ce9f9 100644 --- a/ShadowEditor.Web/src/serialization/texture/DataTextureSerializer.js +++ b/ShadowEditor.Web/src/serialization/texture/DataTextureSerializer.js @@ -16,10 +16,10 @@ DataTextureSerializer.prototype.toJSON = function (obj) { return TextureSerializer.prototype.toJSON.call(this, obj); }; -DataTextureSerializer.prototype.fromJSON = function (json, parent) { +DataTextureSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.DataTexture() : parent; - TextureSerializer.prototype.fromJSON.call(this, json, obj); + TextureSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/texture/DepthTextureSerializer.js b/ShadowEditor.Web/src/serialization/texture/DepthTextureSerializer.js index 95cab0bd..90ff6fcb 100644 --- a/ShadowEditor.Web/src/serialization/texture/DepthTextureSerializer.js +++ b/ShadowEditor.Web/src/serialization/texture/DepthTextureSerializer.js @@ -16,10 +16,10 @@ DepthTextureSerializer.prototype.toJSON = function (obj) { return TextureSerializer.prototype.toJSON.call(this, obj); }; -DepthTextureSerializer.prototype.fromJSON = function (json, parent) { +DepthTextureSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.DataTexture() : parent; - TextureSerializer.prototype.fromJSON.call(this, json, obj); + TextureSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/src/serialization/texture/TextureSerializer.js b/ShadowEditor.Web/src/serialization/texture/TextureSerializer.js index a0c64c03..166be443 100644 --- a/ShadowEditor.Web/src/serialization/texture/TextureSerializer.js +++ b/ShadowEditor.Web/src/serialization/texture/TextureSerializer.js @@ -70,7 +70,7 @@ TextureSerializer.prototype.toJSON = function (obj) { return json; }; -TextureSerializer.prototype.fromJSON = function (json, parent) { +TextureSerializer.prototype.fromJSON = function (json, parent, server) { // 用一个像素的图片初始化Texture,避免图片载入前的警告信息。 var img = ImageUtils.onePixelCanvas(); var obj = parent === undefined ? new THREE.Texture(img) : parent; @@ -84,7 +84,13 @@ TextureSerializer.prototype.fromJSON = function (json, parent) { if (json.image && !Array.isArray(json.image) && json.image.tagName === 'img') { // 图片 var img = document.createElement('img'); - img.src = json.image.src; + + if(json.image.src && json.image.src.startsWith('/')) { + img.src = server + json.image.src; + } else { + img.src = json.image.src; + } + img.width = json.image.width; img.height = json.image.height; img.onload = function () { @@ -98,7 +104,13 @@ TextureSerializer.prototype.fromJSON = function (json, parent) { var ctx = canvas.getContext('2d'); var img = document.createElement('img'); - img.src = json.image.src; + + if(json.image.src && json.image.src.startsWith('/')) { + img.src = server + json.image.src; + } else { + img.src = json.image.src; + } + img.onload = function () { canvas.width = img.width; canvas.height = img.height; diff --git a/ShadowEditor.Web/src/serialization/texture/TexturesSerializer.js b/ShadowEditor.Web/src/serialization/texture/TexturesSerializer.js index e09d36a1..9e55dd03 100644 --- a/ShadowEditor.Web/src/serialization/texture/TexturesSerializer.js +++ b/ShadowEditor.Web/src/serialization/texture/TexturesSerializer.js @@ -40,7 +40,7 @@ TexturesSerializer.prototype.toJSON = function (obj) { return (new serializer()).toJSON(obj); }; -TexturesSerializer.prototype.fromJSON = function (json, parent) { +TexturesSerializer.prototype.fromJSON = function (json, parent, server) { var generator = json.metadata.generator; var serializer = Serializers[generator.replace('Serializer', '')]; @@ -50,7 +50,7 @@ TexturesSerializer.prototype.fromJSON = function (json, parent) { return null; } - return (new serializer()).fromJSON(json, parent); + return (new serializer()).fromJSON(json, parent, server); }; export default TexturesSerializer; \ No newline at end of file diff --git a/ShadowEditor.Web/src/serialization/texture/VideoTextureSerializer.js b/ShadowEditor.Web/src/serialization/texture/VideoTextureSerializer.js index c300dc1c..e386bfe4 100644 --- a/ShadowEditor.Web/src/serialization/texture/VideoTextureSerializer.js +++ b/ShadowEditor.Web/src/serialization/texture/VideoTextureSerializer.js @@ -16,10 +16,10 @@ VideoTextureSerializer.prototype.toJSON = function (obj) { return TextureSerializer.prototype.toJSON.call(this, obj); }; -VideoTextureSerializer.prototype.fromJSON = function (json, parent) { +VideoTextureSerializer.prototype.fromJSON = function (json, parent, server) { var obj = parent === undefined ? new THREE.VideoTexture() : parent; - TextureSerializer.prototype.fromJSON.call(this, json, obj); + TextureSerializer.prototype.fromJSON.call(this, json, obj, server); return obj; }; diff --git a/ShadowEditor.Web/view.html b/ShadowEditor.Web/view.html index 37e198be..eb119e01 100644 --- a/ShadowEditor.Web/view.html +++ b/ShadowEditor.Web/view.html @@ -89,7 +89,7 @@ var sceneFile = getQueryString('sceneFile'); if (sceneID) { // 通过/api/Scene/Load?ID=sceneID获取场景数据 - fetch(`/api/Scene/Load?ID=${sceneID}`).then(response => { + fetch(`${app.options.server}/api/Scene/Load?ID=${sceneID}`).then(response => { if (response.ok) { response.json().then(json => { if (json.Code === 200) { @@ -99,7 +99,7 @@ } }); } else if (sceneFile) { // 通过/Scene/sceneID.txt获取场景数据(导出用) - fetch(`Scene/${sceneFile}.txt`).then(response => { + fetch(`${app.options.server}/Scene/${sceneFile}.txt`).then(response => { if (response.ok) { response.json().then(json => { app.start(JSON.stringify(json));