mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-02-01 16:08:17 +00:00
场景菜单。
This commit is contained in:
parent
33003929e2
commit
eea835700f
@ -33,6 +33,11 @@ import ClearEvent from './editor/ClearEvent';
|
||||
import LoadEvent from './editor/LoadEvent';
|
||||
import SaveEvent from './editor/SaveEvent';
|
||||
|
||||
import NewSceneEvent from './menu/scene/NewSceneEvent';
|
||||
import LoadSceneEvent from './menu/scene/LoadSceneEvent';
|
||||
import SaveSceneEvent from './menu/scene/SaveSceneEvent';
|
||||
import PublishSceneEvent from './menu/scene/PublishSceneEvent';
|
||||
|
||||
/**
|
||||
* 事件执行器
|
||||
*/
|
||||
@ -73,6 +78,12 @@ function EventDispatcher(app) {
|
||||
new ClearEvent(this.app),
|
||||
new LoadEvent(this.app),
|
||||
new SaveEvent(this.app),
|
||||
|
||||
// menubar中的事件
|
||||
new NewSceneEvent(this.app),
|
||||
new LoadSceneEvent(this.app),
|
||||
new SaveSceneEvent(this.app),
|
||||
new PublishSceneEvent(this.app),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
22
src/event/menu/MenuEvent.js
Normal file
22
src/event/menu/MenuEvent.js
Normal file
@ -0,0 +1,22 @@
|
||||
import BaseEvent from '../BaseEvent';
|
||||
|
||||
/**
|
||||
* 菜单事件
|
||||
* @param {*} app
|
||||
*/
|
||||
function MenuEvent(app) {
|
||||
BaseEvent.call(this, app);
|
||||
}
|
||||
|
||||
MenuEvent.prototype = Object.create(BaseEvent.prototype);
|
||||
MenuEvent.prototype.constructor = MenuEvent;
|
||||
|
||||
MenuEvent.prototype.start = function () {
|
||||
|
||||
};
|
||||
|
||||
MenuEvent.prototype.stop = function () {
|
||||
|
||||
};
|
||||
|
||||
export default MenuEvent;
|
||||
33
src/event/menu/scene/LoadSceneEvent.js
Normal file
33
src/event/menu/scene/LoadSceneEvent.js
Normal file
@ -0,0 +1,33 @@
|
||||
import MenuEvent from '../MenuEvent';
|
||||
|
||||
/**
|
||||
* 载入场景
|
||||
* @param {*} app
|
||||
*/
|
||||
function LoadSceneEvent(app) {
|
||||
MenuEvent.call(this, app);
|
||||
}
|
||||
|
||||
LoadSceneEvent.prototype = Object.create(MenuEvent.prototype);
|
||||
LoadSceneEvent.prototype.constructor = LoadSceneEvent;
|
||||
|
||||
LoadSceneEvent.prototype.start = function () {
|
||||
var _this = this;
|
||||
this.app.on('mLoadScene.' + this.id, function () {
|
||||
_this.onLoadScene();
|
||||
});
|
||||
};
|
||||
|
||||
LoadSceneEvent.prototype.stop = function () {
|
||||
this.app.on('mLoadScene.' + this.id, null);
|
||||
};
|
||||
|
||||
LoadSceneEvent.prototype.onLoadScene = function () {
|
||||
var editor = this.app.editor;
|
||||
|
||||
if (confirm('所有未保存数据将丢失,确定吗?')) {
|
||||
editor.load();
|
||||
}
|
||||
};
|
||||
|
||||
export default LoadSceneEvent;
|
||||
33
src/event/menu/scene/NewSceneEvent.js
Normal file
33
src/event/menu/scene/NewSceneEvent.js
Normal file
@ -0,0 +1,33 @@
|
||||
import MenuEvent from '../MenuEvent';
|
||||
|
||||
/**
|
||||
* 新建场景
|
||||
* @param {*} app
|
||||
*/
|
||||
function NewSceneEvent(app) {
|
||||
MenuEvent.call(this, app);
|
||||
}
|
||||
|
||||
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();
|
||||
});
|
||||
};
|
||||
|
||||
NewSceneEvent.prototype.stop = function () {
|
||||
this.app.on('mNewScene.' + this.id, null);
|
||||
};
|
||||
|
||||
NewSceneEvent.prototype.onNewScene = function () {
|
||||
var editor = this.app.editor;
|
||||
|
||||
if (confirm('所有未保存数据将丢失,确定吗?')) {
|
||||
editor.clear();
|
||||
}
|
||||
};
|
||||
|
||||
export default NewSceneEvent;
|
||||
101
src/event/menu/scene/PublishSceneEvent.js
Normal file
101
src/event/menu/scene/PublishSceneEvent.js
Normal file
@ -0,0 +1,101 @@
|
||||
import MenuEvent from '../MenuEvent';
|
||||
import MathUtils from '../../../utils/MathUtils';
|
||||
|
||||
/**
|
||||
* 发布场景
|
||||
* @param {*} app
|
||||
*/
|
||||
function PublishSceneEvent(app) {
|
||||
MenuEvent.call(this, app);
|
||||
}
|
||||
|
||||
PublishSceneEvent.prototype = Object.create(MenuEvent.prototype);
|
||||
PublishSceneEvent.prototype.constructor = PublishSceneEvent;
|
||||
|
||||
PublishSceneEvent.prototype.start = function () {
|
||||
var _this = this;
|
||||
this.app.on('mPublishScene.' + this.id, function () {
|
||||
_this.onPublishScene();
|
||||
});
|
||||
|
||||
this.link = document.createElement('a');
|
||||
this.link.style.display = 'none';
|
||||
document.body.appendChild(this.link); // Firefox workaround, see #6594
|
||||
};
|
||||
|
||||
PublishSceneEvent.prototype.stop = function () {
|
||||
this.app.on('mPublishScene.' + this.id, null);
|
||||
};
|
||||
|
||||
PublishSceneEvent.prototype.onPublishScene = function () {
|
||||
var editor = this.app.editor;
|
||||
|
||||
var zip = new JSZip();
|
||||
//
|
||||
|
||||
var output = editor.toJSON();
|
||||
output.metadata.type = 'App';
|
||||
delete output.history;
|
||||
|
||||
var vr = output.project.vr;
|
||||
|
||||
output = JSON.stringify(output, MathUtils.parseNumber, '\t');
|
||||
output = output.replace(/[\n\t]+([\d\.e\-\[\]]+)/g, '$1');
|
||||
|
||||
zip.file('app.json', output);
|
||||
|
||||
//
|
||||
|
||||
var _this = this;
|
||||
var manager = new THREE.LoadingManager(function () {
|
||||
_this.save(zip.generate({ type: 'blob' }), 'download.zip');
|
||||
});
|
||||
|
||||
var loader = new THREE.FileLoader(manager);
|
||||
loader.load('third_party/app/index.html', function (content) {
|
||||
var includes = [];
|
||||
|
||||
if (vr) {
|
||||
includes.push('<script src="third_party/controls/VRControls.js"></script>');
|
||||
includes.push('<script src="third_party/effects/VREffect.js"></script>');
|
||||
includes.push('<script src="third_party/vr/WebVR.js"></script>');
|
||||
}
|
||||
|
||||
content = content.replace('<!-- includes -->', includes.join('\n\t\t'));
|
||||
zip.file('index.html', content);
|
||||
});
|
||||
loader.load('third_party/app.js', function (content) {
|
||||
zip.file('js/app.js', content);
|
||||
});
|
||||
loader.load('node_modules/three/build/three.min.js', function (content) {
|
||||
zip.file('js/three.min.js', content);
|
||||
});
|
||||
|
||||
if (vr) {
|
||||
loader.load('third_party/controls/VRControls.js', function (content) {
|
||||
zip.file('js/VRControls.js', content);
|
||||
});
|
||||
|
||||
loader.load('third_party/effects/VREffect.js', function (content) {
|
||||
zip.file('js/VREffect.js', content);
|
||||
});
|
||||
|
||||
loader.load('third_party/vr/WebVR.js', function (content) {
|
||||
zip.file('js/WebVR.js', content);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
PublishSceneEvent.prototype.save = function (blob, filename) {
|
||||
this.link.href = URL.createObjectURL(blob);
|
||||
this.link.download = filename || 'data.json';
|
||||
this.link.click();
|
||||
|
||||
// URL.revokeObjectURL( url ); breaks Firefox...
|
||||
};
|
||||
|
||||
PublishSceneEvent.prototype.saveString = function (text, filename) {
|
||||
this.save(new Blob([text], { type: 'text/plain' }), filename);
|
||||
};
|
||||
|
||||
export default PublishSceneEvent;
|
||||
31
src/event/menu/scene/SaveSceneEvent.js
Normal file
31
src/event/menu/scene/SaveSceneEvent.js
Normal file
@ -0,0 +1,31 @@
|
||||
import MenuEvent from '../MenuEvent';
|
||||
|
||||
/**
|
||||
* 保存场景
|
||||
* @param {*} app
|
||||
*/
|
||||
function SaveSceneEvent(app) {
|
||||
MenuEvent.call(this, app);
|
||||
}
|
||||
|
||||
SaveSceneEvent.prototype = Object.create(MenuEvent.prototype);
|
||||
SaveSceneEvent.prototype.constructor = SaveSceneEvent;
|
||||
|
||||
SaveSceneEvent.prototype.start = function () {
|
||||
var _this = this;
|
||||
this.app.on('mSaveScene.' + this.id, function () {
|
||||
_this.onSaveScene();
|
||||
});
|
||||
};
|
||||
|
||||
SaveSceneEvent.prototype.stop = function () {
|
||||
this.app.on('mSaveScene.' + this.id, null);
|
||||
};
|
||||
|
||||
SaveSceneEvent.prototype.onSaveScene = function () {
|
||||
var editor = this.app.editor;
|
||||
|
||||
editor.save();
|
||||
};
|
||||
|
||||
export default SaveSceneEvent;
|
||||
23
src/utils/MathUtils.js
Normal file
23
src/utils/MathUtils.js
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 精度
|
||||
*/
|
||||
var NUMBER_PRECISION = 6;
|
||||
|
||||
/**
|
||||
* 打包数字
|
||||
* @param {*} key
|
||||
* @param {*} value
|
||||
*/
|
||||
function parseNumber(key, value) {
|
||||
return typeof value === 'number' ? parseFloat(value.toFixed(NUMBER_PRECISION)) : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数学工具
|
||||
*/
|
||||
const MathUtils = {
|
||||
NUMBER_PRECISION: NUMBER_PRECISION,
|
||||
parseNumber: parseNumber
|
||||
};
|
||||
|
||||
export default MathUtils;
|
||||
Loading…
x
Reference in New Issue
Block a user