Copy & Paste (#566)

This commit is contained in:
Miles Ryan authored and GitHub committed 2024-07-02 12:36:27 -04:00
1 parent 7675e08455
commit 2f8bba85f9
4 files changed
+53 -1

No files matched your search

@@ -123,6 +123,7 @@ export class MouseControls {
}
selectObject(currentObject: THREE.Object3D) {
this.selected = [currentObject];
this.setSelected(this.selected);
this.publishSelect();
@@ -211,6 +212,18 @@ export class MouseControls {
await this.sceneManager?.redo();
this.isProcessing = false;
return;
} else if (event.key === "c") {
// redo
this.isProcessing = true;
await this.sceneManager?.copy();
this.isProcessing = false;
return;
} else if (event.key === "v") {
// redo
this.isProcessing = true;
await this.sceneManager?.paste();
this.isProcessing = false;
return;
}
}
@@ -63,6 +63,7 @@ export class SceneManager implements SceneManagerAPI {
public undoStack: ICommand<CommandInputTypes>[] = [];
private undoIndex: number = 0;
private lastSceneState: SceneState;
private copiedObject: THREE.Object3D | undefined;
constructor(
version: number,
@@ -230,6 +231,34 @@ export class SceneManager implements SceneManagerAPI {
};
}
public async copy() {
this.copiedObject = this.mouse_controls.selected?.at(0);
}
public async paste() {
if(this.copiedObject && this.copiedObject.name != "::CAM::") {
const userdata = this.copiedObject.userData;
const position = this.copiedObject.position.clone();
const rotation = this.copiedObject.rotation.clone();
const scale = this.copiedObject.scale.clone();
const media_id = userdata["media_id"];
const color = userdata["color"];
const name = this.copiedObject.name;
const obj = await this.create(media_id, name, position);
this.scene.setColor(obj.uuid, color);
obj.position.copy(position.add(new THREE.Vector3(0.5,0.0,0.5)));
obj.rotation.copy(rotation);
obj.scale.copy(scale);
this.mouse_controls.selectObject(obj);
this.updateOutliner();
await this.copy();
await this.add_creation_undostack(obj);
}
}
public onMouseMove(event: MouseEvent) {
this.mouse_controls.onMouseMove(event);
}
+1 -1
View File
@@ -344,7 +344,7 @@ export class TimeLine {
public async addShape(data: MediaItem) {
const pos = this.getPos();
const parim = this.editorEngine.create_parim(data.media_id, pos);
const parim = await this.editorEngine.create_parim(data.media_id, pos);
await this.editorEngine.sceneManager?.add_creation_undostack(parim);
return parim;
}
@@ -107,6 +107,16 @@ export const Help = () => {
<Shortcut label="Focus">
<Key button="F" />
</Shortcut>
<Shortcut label="Copy">
<Key button="Ctrl" />
<Plus></Plus>
<Key button="C" />
</Shortcut>
<Shortcut label="Paste">
<Key button="Ctrl" />
<Plus></Plus>
<Key button="V" />
</Shortcut>
</ShortcutsGroup>
<ShortcutsGroup label="Interaction">