mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-02-01 16:08:17 +00:00
场景反序列化。
This commit is contained in:
parent
d91d8cc898
commit
261bdbf6ef
@ -13,10 +13,7 @@ NewSceneEvent.prototype = Object.create(MenuEvent.prototype);
|
||||
NewSceneEvent.prototype.constructor = NewSceneEvent;
|
||||
|
||||
NewSceneEvent.prototype.start = function () {
|
||||
var _this = this;
|
||||
this.app.on('mNewScene.' + this.id, function () {
|
||||
_this.onNewScene();
|
||||
});
|
||||
this.app.on('mNewScene.' + this.id, this.onNewScene.bind(this));
|
||||
};
|
||||
|
||||
NewSceneEvent.prototype.stop = function () {
|
||||
@ -26,11 +23,12 @@ NewSceneEvent.prototype.stop = function () {
|
||||
NewSceneEvent.prototype.onNewScene = function () {
|
||||
var editor = this.app.editor;
|
||||
|
||||
UI.confirm('询问', '所有未保存数据将丢失,确定吗?', function (event, btn) {
|
||||
if (btn === 'ok') {
|
||||
editor.clear();
|
||||
}
|
||||
});
|
||||
// UI.confirm('询问', '所有未保存数据将丢失,确定吗?', function (event, btn) {
|
||||
// if (btn === 'ok') {
|
||||
editor.clear();
|
||||
// }
|
||||
// });
|
||||
document.title = '未命名';
|
||||
};
|
||||
|
||||
export default NewSceneEvent;
|
||||
@ -132,9 +132,9 @@ Converter.prototype.fromJson = function (app, json) {
|
||||
|
||||
var camera = null;
|
||||
|
||||
if (camera.metadata.generator === 'OrthographicCameraSerializer') {
|
||||
if (cameraJson.metadata.generator === 'OrthographicCameraSerializer') {
|
||||
camera = (new OrthographicCameraSerializer()).fromJSON(cameraJson);
|
||||
} else if (camera.metadata.generator === 'PerspectiveCameraSerializer') {
|
||||
} else if (cameraJson.metadata.generator === 'PerspectiveCameraSerializer') {
|
||||
camera = (new PerspectiveCameraSerializer()).fromJSON(cameraJson);
|
||||
} else {
|
||||
console.warn(`Converter: 场景中不存在相机信息。`);
|
||||
|
||||
@ -22,7 +22,28 @@ SceneSerializer.prototype.toJSON = function (obj) {
|
||||
};
|
||||
|
||||
SceneSerializer.prototype.fromJSON = function (json) {
|
||||
var obj = new THREE.Scene();
|
||||
|
||||
Object3DSerializer.prototype.fromJSON(json, obj);
|
||||
|
||||
if (json.background) {
|
||||
obj.background = new THREE.Color(json.background);
|
||||
}
|
||||
|
||||
if (json.fog && json.fog.type === 'Fog') {
|
||||
obj.fog = new THREE.Fog(json.fog.color, json.fog.near, json.fog.far);
|
||||
} else if (json.fog && json.fog.type === 'FogExp2') {
|
||||
obj.fog = new THREE.FogExp2(json.fog.color, json.fog.density);
|
||||
} else if (json.fog) {
|
||||
console.warn(`SceneSerializer: unknown fog type ${json.fog.type}.`);
|
||||
}
|
||||
|
||||
if (json.overrideMaterial) {
|
||||
obj.overrideMaterial = json.overrideMaterial;
|
||||
console.warn('TODO: //');
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
export default SceneSerializer;
|
||||
Loading…
x
Reference in New Issue
Block a user