Add function to duplicate objects

This commit is contained in:
Brian Peiris 2018-06-28 17:35:10 -07:00
Родитель 86a3b24d71
Коммит 2351b794b2
4 изменённых файлов: 34 добавлений и 3 удалений

Просмотреть файл

@ -87,6 +87,7 @@ class EditorContainer extends Component {
rotateTool: "e", rotateTool: "e",
scaleTool: "r", scaleTool: "r",
delete: "del", delete: "del",
duplicate: ["ctrl+d", "command+d"],
save: ["ctrl+s", "command+s"], save: ["ctrl+s", "command+s"],
saveAs: ["ctrl+shift+s", "command+shift+s"], saveAs: ["ctrl+shift+s", "command+shift+s"],
undo: ["ctrl+z", "command+z"], undo: ["ctrl+z", "command+z"],

Просмотреть файл

@ -42,7 +42,8 @@ class HierarchyPanelContainer extends Component {
this.state = { this.state = {
tree: createNodeHierarchy(props.editor.scene), tree: createNodeHierarchy(props.editor.scene),
hierarchyHotKeyHandlers: { hierarchyHotKeyHandlers: {
delete: this.onDeleteSelected delete: this.onDeleteSelected,
duplicate: this.onDuplicateSelected
} }
}; };
@ -102,6 +103,15 @@ class HierarchyPanelContainer extends Component {
this.props.editor.execute(new AddObjectCommand(object, node.object)); this.props.editor.execute(new AddObjectCommand(object, node.object));
}; };
onDuplicateSelected = () => {
this.props.editor.duplicateSelectedObject();
return false;
};
onDuplicateNode = (e, node) => {
this.props.editor.duplicateObject(node.object);
};
onDeleteSelected = () => { onDeleteSelected = () => {
this.props.editor.deleteSelectedObject(); this.props.editor.deleteSelectedObject();
}; };
@ -150,6 +160,7 @@ class HierarchyPanelContainer extends Component {
/> />
<ContextMenu id="hierarchy-node-menu"> <ContextMenu id="hierarchy-node-menu">
<MenuItem onClick={this.onAddNode}>Add Node</MenuItem> <MenuItem onClick={this.onAddNode}>Add Node</MenuItem>
<MenuItem onClick={this.onDuplicateNode}>Duplicate</MenuItem>
<MenuItem onClick={this.onDeleteNode}>Delete</MenuItem> <MenuItem onClick={this.onDeleteNode}>Delete</MenuItem>
</ContextMenu> </ContextMenu>
</HotKeys> </HotKeys>

Просмотреть файл

@ -20,7 +20,8 @@ class ViewportPanelContainer extends Component {
translateTool: this.onTranslateTool, translateTool: this.onTranslateTool,
rotateTool: this.onRotateTool, rotateTool: this.onRotateTool,
scaleTool: this.onScaleTool, scaleTool: this.onScaleTool,
delete: this.onDelete delete: this.onDelete,
duplicate: this.onDuplicate
} }
}; };
@ -49,6 +50,11 @@ class ViewportPanelContainer extends Component {
this.props.editor.signals.transformModeChanged.dispatch("scale"); this.props.editor.signals.transformModeChanged.dispatch("scale");
}; };
onDuplicate = () => {
this.props.editor.duplicateSelectedObject();
return false;
};
onDelete = () => { onDelete = () => {
this.props.editor.deleteSelectedObject(); this.props.editor.deleteSelectedObject();
}; };

Просмотреть файл

@ -5,6 +5,7 @@ import Storage from "./Storage";
import Viewport from "./Viewport"; import Viewport from "./Viewport";
import getFileNameFromURI from "../utlis/getFileNameFromURI"; import getFileNameFromURI from "../utlis/getFileNameFromURI";
import RemoveObjectCommand from "./commands/RemoveObjectCommand"; import RemoveObjectCommand from "./commands/RemoveObjectCommand";
import AddObjectCommand from "./commands/AddObjectCommand";
/** /**
* @author mrdoob / http://mrdoob.com/ * @author mrdoob / http://mrdoob.com/
@ -337,7 +338,7 @@ export default class Editor {
addHelper = (function() { addHelper = (function() {
const geometry = new THREE.SphereBufferGeometry(2, 4, 2); const geometry = new THREE.SphereBufferGeometry(2, 4, 2);
const material = new THREE.MeshBasicMaterial({ color: 0xff0000, visible: false }); const material = new THREE.MeshBasicMaterial({ color: 0xff0000, visible: true, wireframe: true });
return function(object) { return function(object) {
let helper; let helper;
@ -478,6 +479,18 @@ export default class Editor {
this.deleteObject(this.selected); this.deleteObject(this.selected);
} }
duplicateObject(object) {
const clone = object.clone();
clone.traverse(child => {
Object.defineProperty(child.userData, "selectionRoot", { value: clone, enumerable: false });
});
this.execute(new AddObjectCommand(clone, object.parent));
}
duplicateSelectedObject() {
this.duplicateObject(this.selected);
}
clear() { clear() {
this.history.clear(); this.history.clear();
this.storage.clear(); this.storage.clear();