mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-02-01 16:08:17 +00:00
1、清空场景事件。
2、加载场景事件。 3、保存场景事件。 4、选择事件。
This commit is contained in:
parent
95eeecf697
commit
e40ae9cd03
@ -57,6 +57,10 @@ Editor.prototype = {
|
||||
|
||||
// ------------------ 物体 --------------------------
|
||||
|
||||
objectByUuid: function (uuid) { // 根据uuid获取物体
|
||||
return this.scene.getObjectByProperty('uuid', uuid, true);
|
||||
},
|
||||
|
||||
addObject: function (object) { // 添加物体
|
||||
this.app.call('addObject', this, object);
|
||||
},
|
||||
@ -113,120 +117,61 @@ Editor.prototype = {
|
||||
this.app.call('removeScript', this, object, script);
|
||||
},
|
||||
|
||||
//
|
||||
|
||||
select: function (object) {
|
||||
|
||||
if (this.selected === object) return;
|
||||
|
||||
var uuid = null;
|
||||
|
||||
if (object !== null) {
|
||||
|
||||
uuid = object.uuid;
|
||||
|
||||
}
|
||||
|
||||
this.selected = object;
|
||||
|
||||
this.config.setKey('selected', uuid);
|
||||
this.signals.objectSelected.dispatch(object);
|
||||
// ----------------------- 选择事件 ---------------------------
|
||||
|
||||
select: function (object) { // 选中物体
|
||||
this.app.call('select', this, object);
|
||||
},
|
||||
|
||||
selectById: function (id) {
|
||||
|
||||
selectById: function (id) { // 根据id选中物体
|
||||
if (id === this.camera.id) {
|
||||
|
||||
this.select(this.camera);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
this.select(this.scene.getObjectById(id, true));
|
||||
|
||||
},
|
||||
|
||||
selectByUuid: function (uuid) {
|
||||
|
||||
var scope = this;
|
||||
|
||||
selectByUuid: function (uuid) { // 根据uuid选中物体
|
||||
var _this = this;
|
||||
this.scene.traverse(function (child) {
|
||||
|
||||
if (child.uuid === uuid) {
|
||||
|
||||
scope.select(child);
|
||||
|
||||
_this.select(child);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
deselect: function () {
|
||||
|
||||
deselect: function () { // 取消选中物体
|
||||
this.select(null);
|
||||
|
||||
},
|
||||
|
||||
focus: function (object) {
|
||||
// -------------------- 设置焦点事件 --------------------------
|
||||
|
||||
focus: function (object) { // 设置焦点
|
||||
this.signals.objectFocused.dispatch(object);
|
||||
|
||||
},
|
||||
|
||||
focusById: function (id) {
|
||||
|
||||
focusById: function (id) { // 根据id设置交点
|
||||
this.focus(this.scene.getObjectById(id, true));
|
||||
|
||||
},
|
||||
|
||||
clear: function () {
|
||||
|
||||
this.history.clear();
|
||||
this.storage.clear();
|
||||
|
||||
this.camera.copy(this.DEFAULT_CAMERA);
|
||||
this.scene.background.setHex(0xaaaaaa);
|
||||
this.scene.fog = null;
|
||||
|
||||
var objects = this.scene.children;
|
||||
|
||||
while (objects.length > 0) {
|
||||
|
||||
this.removeObject(objects[0]);
|
||||
|
||||
}
|
||||
|
||||
this.geometries = {};
|
||||
this.materials = {};
|
||||
this.textures = {};
|
||||
this.scripts = {};
|
||||
|
||||
this.deselect();
|
||||
|
||||
this.signals.editorCleared.dispatch();
|
||||
// -------------------------- 场景事件 ---------------------------
|
||||
|
||||
clear: function () { // 清空场景
|
||||
this.app.call('clear', this);
|
||||
},
|
||||
|
||||
load: function () {
|
||||
alert('开发中');
|
||||
load: function () { // 加载场景
|
||||
this.app.call('load', this);
|
||||
},
|
||||
|
||||
save: function () {
|
||||
var obj = SceneUtils.toJSON(this.scene);
|
||||
Ajax.post(this.app.options.server + '/Service/SceneService.ashx?cmd=Save', {
|
||||
name: 'Scene1',
|
||||
data: JSON.stringify(obj)
|
||||
}, function (result) {
|
||||
var obj = JSON.parse(result);
|
||||
alert(obj.Msg);
|
||||
});
|
||||
save: function () { // 保存场景
|
||||
this.app.call('save', this);
|
||||
},
|
||||
|
||||
//
|
||||
// --------------------------- 场景序列化 ------------------------------
|
||||
|
||||
fromJSON: function (json) {
|
||||
fromJSON: function (json) { // 根据json创建场景
|
||||
|
||||
var loader = new THREE.ObjectLoader();
|
||||
|
||||
@ -252,7 +197,7 @@ Editor.prototype = {
|
||||
|
||||
},
|
||||
|
||||
toJSON: function () {
|
||||
toJSON: function () { // 将json转换为场景
|
||||
|
||||
// scripts clean up
|
||||
|
||||
@ -291,28 +236,18 @@ Editor.prototype = {
|
||||
|
||||
},
|
||||
|
||||
objectByUuid: function (uuid) {
|
||||
|
||||
return this.scene.getObjectByProperty('uuid', uuid, true);
|
||||
|
||||
},
|
||||
|
||||
execute: function (cmd, optionalName) {
|
||||
// ----------------------- 命令 ---------------------------
|
||||
|
||||
execute: function (cmd, optionalName) { // 执行事件
|
||||
this.history.execute(cmd, optionalName);
|
||||
|
||||
},
|
||||
|
||||
undo: function () {
|
||||
|
||||
undo: function () { // 撤销事件
|
||||
this.history.undo();
|
||||
|
||||
},
|
||||
|
||||
redo: function () {
|
||||
|
||||
redo: function () { // 重做事件
|
||||
this.history.redo();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -78,7 +78,7 @@ function Toolbar(editor) {
|
||||
function update() {
|
||||
|
||||
signals.snapChanged.dispatch(snap.getValue() === true ? grid.getValue() : null);
|
||||
signals.spaceChanged.dispatch(local.getValue() === true ? "本地" : "世界");
|
||||
signals.spaceChanged.dispatch(local.getValue() === true ? "local" : "world");
|
||||
signals.showGridChanged.dispatch(showGrid.getValue());
|
||||
|
||||
}
|
||||
|
||||
@ -26,6 +26,10 @@ import AddHelperEvent from './editor/AddHelperEvent';
|
||||
import RemoveHelperEvent from './editor/RemoveHelperEvent';
|
||||
import AddScriptEvent from './editor/AddScriptEvent';
|
||||
import RemoveScriptEvent from './editor/RemoveScriptEvent';
|
||||
import SelectEvent from './editor/SelectEvent';
|
||||
import ClearEvent from './editor/ClearEvent';
|
||||
import LoadEvent from './editor/LoadEvent';
|
||||
import SaveEvent from './editor/SaveEvent';
|
||||
|
||||
/**
|
||||
* 事件执行器
|
||||
@ -62,6 +66,10 @@ function EventDispatcher(app) {
|
||||
new RemoveHelperEvent(this.app),
|
||||
new AddScriptEvent(this.app),
|
||||
new RemoveScriptEvent(this.app),
|
||||
new SelectEvent(this.app),
|
||||
new ClearEvent(this.app),
|
||||
new LoadEvent(this.app),
|
||||
new SaveEvent(this.app),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +32,10 @@ var EventList = [
|
||||
'removeHelper', // 移除脚本
|
||||
'addScript', // 添加脚本
|
||||
'removeScript', // 移除脚本
|
||||
'select', // 选中事件
|
||||
'clear', // 清空场景
|
||||
'load', // 加载场景
|
||||
'save', // 保存场景
|
||||
];
|
||||
|
||||
export default EventList;
|
||||
51
src/event/editor/ClearEvent.js
Normal file
51
src/event/editor/ClearEvent.js
Normal file
@ -0,0 +1,51 @@
|
||||
import BaseEvent from '../BaseEvent';
|
||||
|
||||
/**
|
||||
* 清空场景事件
|
||||
* @param {*} app
|
||||
*/
|
||||
function ClearEvent(app) {
|
||||
BaseEvent.call(this, app);
|
||||
}
|
||||
|
||||
ClearEvent.prototype = Object.create(BaseEvent.prototype);
|
||||
ClearEvent.prototype.constructor = ClearEvent;
|
||||
|
||||
ClearEvent.prototype.start = function () {
|
||||
var _this = this;
|
||||
this.app.on('clear.' + this.id, function () {
|
||||
_this.onClear();
|
||||
});
|
||||
};
|
||||
|
||||
ClearEvent.prototype.stop = function () {
|
||||
this.app.on('clear.' + this.id, null);
|
||||
};
|
||||
|
||||
ClearEvent.prototype.onClear = function () {
|
||||
var editor = this.app.editor;
|
||||
|
||||
editor.history.clear();
|
||||
editor.storage.clear();
|
||||
|
||||
editor.camera.copy(editor.DEFAULT_CAMERA);
|
||||
editor.scene.background.setHex(0xaaaaaa);
|
||||
editor.scene.fog = null;
|
||||
|
||||
var objects = editor.scene.children;
|
||||
|
||||
while (objects.length > 0) {
|
||||
editor.removeObject(objects[0]);
|
||||
}
|
||||
|
||||
editor.geometries = {};
|
||||
editor.materials = {};
|
||||
editor.textures = {};
|
||||
editor.scripts = {};
|
||||
|
||||
editor.deselect();
|
||||
|
||||
editor.signals.editorCleared.dispatch();
|
||||
};
|
||||
|
||||
export default ClearEvent;
|
||||
29
src/event/editor/LoadEvent.js
Normal file
29
src/event/editor/LoadEvent.js
Normal file
@ -0,0 +1,29 @@
|
||||
import BaseEvent from '../BaseEvent';
|
||||
|
||||
/**
|
||||
* 加载场景事件
|
||||
* @param {*} app
|
||||
*/
|
||||
function LoadEvent(app) {
|
||||
BaseEvent.call(this, app);
|
||||
}
|
||||
|
||||
LoadEvent.prototype = Object.create(BaseEvent.prototype);
|
||||
LoadEvent.prototype.constructor = LoadEvent;
|
||||
|
||||
LoadEvent.prototype.start = function () {
|
||||
var _this = this;
|
||||
this.app.on('load.' + this.id, function () {
|
||||
_this.onLoad();
|
||||
});
|
||||
};
|
||||
|
||||
LoadEvent.prototype.stop = function () {
|
||||
this.app.on('load.' + this.id, null);
|
||||
};
|
||||
|
||||
LoadEvent.prototype.onLoad = function () {
|
||||
alert('加载场景成功!');
|
||||
};
|
||||
|
||||
export default LoadEvent;
|
||||
40
src/event/editor/SaveEvent.js
Normal file
40
src/event/editor/SaveEvent.js
Normal file
@ -0,0 +1,40 @@
|
||||
import BaseEvent from '../BaseEvent';
|
||||
import SceneUtils from '../../utils/SceneUtils';
|
||||
import Ajax from '../../utils/Ajax';
|
||||
|
||||
/**
|
||||
* 保存场景事件
|
||||
* @param {*} app
|
||||
*/
|
||||
function SaveEvent(app) {
|
||||
BaseEvent.call(this, app);
|
||||
}
|
||||
|
||||
SaveEvent.prototype = Object.create(BaseEvent.prototype);
|
||||
SaveEvent.prototype.constructor = SaveEvent;
|
||||
|
||||
SaveEvent.prototype.start = function () {
|
||||
var _this = this;
|
||||
this.app.on('save.' + this.id, function () {
|
||||
_this.onSave();
|
||||
});
|
||||
};
|
||||
|
||||
SaveEvent.prototype.stop = function () {
|
||||
this.app.on('save.' + this.id, null);
|
||||
};
|
||||
|
||||
SaveEvent.prototype.onSave = function () {
|
||||
var editor = this.app.editor;
|
||||
|
||||
var obj = SceneUtils.toJSON(editor.scene);
|
||||
Ajax.post(this.app.options.server + '/Service/SceneService.ashx?cmd=Save', {
|
||||
name: 'Scene1',
|
||||
data: JSON.stringify(obj)
|
||||
}, function (result) {
|
||||
var obj = JSON.parse(result);
|
||||
alert(obj.Msg);
|
||||
});
|
||||
};
|
||||
|
||||
export default SaveEvent;
|
||||
42
src/event/editor/SelectEvent.js
Normal file
42
src/event/editor/SelectEvent.js
Normal file
@ -0,0 +1,42 @@
|
||||
import BaseEvent from '../BaseEvent';
|
||||
|
||||
/**
|
||||
* 选中事件
|
||||
* @param {*} app
|
||||
*/
|
||||
function SelectEvent(app) {
|
||||
BaseEvent.call(this, app);
|
||||
}
|
||||
|
||||
SelectEvent.prototype = Object.create(BaseEvent.prototype);
|
||||
SelectEvent.prototype.constructor = SelectEvent;
|
||||
|
||||
SelectEvent.prototype.start = function () {
|
||||
var _this = this;
|
||||
this.app.on('select.' + this.id, function (object) {
|
||||
_this.onSelect(object);
|
||||
});
|
||||
};
|
||||
|
||||
SelectEvent.prototype.stop = function () {
|
||||
this.app.on('select.' + this.id, null);
|
||||
};
|
||||
|
||||
SelectEvent.prototype.onSelect = function (object) {
|
||||
var editor = this.app.editor;
|
||||
|
||||
if (editor.selected === object) return;
|
||||
|
||||
var uuid = null;
|
||||
|
||||
if (object !== null) {
|
||||
uuid = object.uuid;
|
||||
}
|
||||
|
||||
editor.selected = object;
|
||||
|
||||
editor.config.setKey('selected', uuid);
|
||||
editor.signals.objectSelected.dispatch(object);
|
||||
};
|
||||
|
||||
export default SelectEvent;
|
||||
Loading…
x
Reference in New Issue
Block a user