@thanhthbm/scene-editor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -0
- package/dist/index.css +921 -0
- package/dist/index.js +14076 -0
- package/package.json +49 -0
- package/src/editor/css/main.css +1030 -0
- package/src/editor/js/Animation.js +618 -0
- package/src/editor/js/AnimationResizer.js +73 -0
- package/src/editor/js/Command.js +40 -0
- package/src/editor/js/Config.js +86 -0
- package/src/editor/js/Editor.js +1006 -0
- package/src/editor/js/EditorControls.js +489 -0
- package/src/editor/js/GLTFImportDialog.js +112 -0
- package/src/editor/js/History.js +321 -0
- package/src/editor/js/Loader.js +1162 -0
- package/src/editor/js/LoaderUtils.js +90 -0
- package/src/editor/js/Menubar.Add.js +559 -0
- package/src/editor/js/Menubar.Edit.js +155 -0
- package/src/editor/js/Menubar.File.js +585 -0
- package/src/editor/js/Menubar.Help.js +73 -0
- package/src/editor/js/Menubar.Render.js +858 -0
- package/src/editor/js/Menubar.Status.js +51 -0
- package/src/editor/js/Menubar.View.js +193 -0
- package/src/editor/js/Menubar.js +29 -0
- package/src/editor/js/Player.js +53 -0
- package/src/editor/js/Resizer.js +65 -0
- package/src/editor/js/Script.js +532 -0
- package/src/editor/js/Selector.js +129 -0
- package/src/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
- package/src/editor/js/Sidebar.Geometry.BufferGeometry.js +124 -0
- package/src/editor/js/Sidebar.Geometry.CapsuleGeometry.js +109 -0
- package/src/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
- package/src/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
- package/src/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
- package/src/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
- package/src/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
- package/src/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
- package/src/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
- package/src/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
- package/src/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
- package/src/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
- package/src/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
- package/src/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
- package/src/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
- package/src/editor/js/Sidebar.Geometry.TextGeometry.js +136 -0
- package/src/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
- package/src/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
- package/src/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
- package/src/editor/js/Sidebar.Geometry.js +471 -0
- package/src/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
- package/src/editor/js/Sidebar.Material.ColorProperty.js +87 -0
- package/src/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
- package/src/editor/js/Sidebar.Material.MapProperty.js +277 -0
- package/src/editor/js/Sidebar.Material.NumberProperty.js +60 -0
- package/src/editor/js/Sidebar.Material.Program.js +73 -0
- package/src/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
- package/src/editor/js/Sidebar.Material.js +751 -0
- package/src/editor/js/Sidebar.Object.js +892 -0
- package/src/editor/js/Sidebar.Project.App.js +218 -0
- package/src/editor/js/Sidebar.Project.Materials.js +82 -0
- package/src/editor/js/Sidebar.Project.Renderer.js +193 -0
- package/src/editor/js/Sidebar.Project.Resources.js +242 -0
- package/src/editor/js/Sidebar.Project.js +21 -0
- package/src/editor/js/Sidebar.Properties.js +73 -0
- package/src/editor/js/Sidebar.Scene.js +643 -0
- package/src/editor/js/Sidebar.Script.js +129 -0
- package/src/editor/js/Sidebar.Settings.History.js +146 -0
- package/src/editor/js/Sidebar.Settings.Shortcuts.js +198 -0
- package/src/editor/js/Sidebar.Settings.js +58 -0
- package/src/editor/js/Sidebar.js +41 -0
- package/src/editor/js/Storage.js +98 -0
- package/src/editor/js/Strings.js +2718 -0
- package/src/editor/js/TextureParametersDialog.js +293 -0
- package/src/editor/js/Toolbar.js +75 -0
- package/src/editor/js/Viewport.Controls.js +98 -0
- package/src/editor/js/Viewport.Info.js +144 -0
- package/src/editor/js/Viewport.Pathtracer.js +27 -0
- package/src/editor/js/Viewport.ViewHelper.js +41 -0
- package/src/editor/js/Viewport.XR.js +7 -0
- package/src/editor/js/Viewport.js +982 -0
- package/src/editor/js/commands/AddObjectCommand.js +68 -0
- package/src/editor/js/commands/AddScriptCommand.js +75 -0
- package/src/editor/js/commands/Commands.js +24 -0
- package/src/editor/js/commands/MoveObjectCommand.js +117 -0
- package/src/editor/js/commands/MultiCmdsCommand.js +85 -0
- package/src/editor/js/commands/RemoveObjectCommand.js +88 -0
- package/src/editor/js/commands/RemoveScriptCommand.js +81 -0
- package/src/editor/js/commands/SetColorCommand.js +73 -0
- package/src/editor/js/commands/SetGeometryCommand.js +86 -0
- package/src/editor/js/commands/SetGeometryValueCommand.js +70 -0
- package/src/editor/js/commands/SetMaterialColorCommand.js +87 -0
- package/src/editor/js/commands/SetMaterialCommand.js +80 -0
- package/src/editor/js/commands/SetMaterialMapCommand.js +144 -0
- package/src/editor/js/commands/SetMaterialRangeCommand.js +92 -0
- package/src/editor/js/commands/SetMaterialValueCommand.js +91 -0
- package/src/editor/js/commands/SetMaterialVectorCommand.js +88 -0
- package/src/editor/js/commands/SetPositionCommand.js +84 -0
- package/src/editor/js/commands/SetRotationCommand.js +84 -0
- package/src/editor/js/commands/SetScaleCommand.js +84 -0
- package/src/editor/js/commands/SetSceneCommand.js +104 -0
- package/src/editor/js/commands/SetScriptValueCommand.js +80 -0
- package/src/editor/js/commands/SetShadowValueCommand.js +73 -0
- package/src/editor/js/commands/SetTextureParametersCommand.js +143 -0
- package/src/editor/js/commands/SetUuidCommand.js +70 -0
- package/src/editor/js/commands/SetValueCommand.js +75 -0
- package/src/editor/js/libs/acorn/acorn.js +3236 -0
- package/src/editor/js/libs/acorn/acorn_loose.js +1299 -0
- package/src/editor/js/libs/acorn/walk.js +344 -0
- package/src/editor/js/libs/app/index.html +51 -0
- package/src/editor/js/libs/app.js +14 -0
- package/src/editor/js/libs/codemirror/addon/dialog.css +32 -0
- package/src/editor/js/libs/codemirror/addon/dialog.js +163 -0
- package/src/editor/js/libs/codemirror/addon/show-hint.css +36 -0
- package/src/editor/js/libs/codemirror/addon/show-hint.js +529 -0
- package/src/editor/js/libs/codemirror/addon/tern.css +87 -0
- package/src/editor/js/libs/codemirror/addon/tern.js +750 -0
- package/src/editor/js/libs/codemirror/codemirror.css +344 -0
- package/src/editor/js/libs/codemirror/codemirror.js +9849 -0
- package/src/editor/js/libs/codemirror/mode/glsl.js +233 -0
- package/src/editor/js/libs/codemirror/mode/javascript.js +959 -0
- package/src/editor/js/libs/codemirror/theme/monokai.css +41 -0
- package/src/editor/js/libs/esprima.js +6401 -0
- package/src/editor/js/libs/jsonlint.js +453 -0
- package/src/editor/js/libs/signals.min.js +14 -0
- package/src/editor/js/libs/tern-threejs/build-defs.js +233 -0
- package/src/editor/js/libs/ternjs/comment.js +87 -0
- package/src/editor/js/libs/ternjs/def.js +588 -0
- package/src/editor/js/libs/ternjs/doc_comment.js +401 -0
- package/src/editor/js/libs/ternjs/infer.js +1635 -0
- package/src/editor/js/libs/ternjs/polyfill.js +80 -0
- package/src/editor/js/libs/ternjs/signal.js +26 -0
- package/src/editor/js/libs/ternjs/tern.js +993 -0
- package/src/editor/js/libs/ui.js +1305 -0
- package/src/editor/js/libs/ui.three.js +946 -0
- package/src/events.js +273 -0
- package/src/index.js +284 -0
- package/src/presets/machines.js +239 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Command } from '../Command.js';
|
|
2
|
+
import { ObjectLoader } from 'three';
|
|
3
|
+
|
|
4
|
+
class AddObjectCommand extends Command {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {Editor} editor
|
|
8
|
+
* @param {THREE.Object3D|null} [object=null]
|
|
9
|
+
* @constructor
|
|
10
|
+
*/
|
|
11
|
+
constructor( editor, object = null ) {
|
|
12
|
+
|
|
13
|
+
super( editor );
|
|
14
|
+
|
|
15
|
+
this.type = 'AddObjectCommand';
|
|
16
|
+
|
|
17
|
+
this.object = object;
|
|
18
|
+
|
|
19
|
+
if ( object !== null ) {
|
|
20
|
+
|
|
21
|
+
this.name = editor.strings.getKey( 'command/AddObject' ) + ': ' + object.name;
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
execute() {
|
|
28
|
+
|
|
29
|
+
this.editor.addObject( this.object );
|
|
30
|
+
this.editor.select( this.object );
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
undo() {
|
|
35
|
+
|
|
36
|
+
this.editor.removeObject( this.object );
|
|
37
|
+
this.editor.deselect();
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
toJSON() {
|
|
42
|
+
|
|
43
|
+
const output = super.toJSON( this );
|
|
44
|
+
|
|
45
|
+
output.object = this.object.toJSON();
|
|
46
|
+
|
|
47
|
+
return output;
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fromJSON( json ) {
|
|
52
|
+
|
|
53
|
+
super.fromJSON( json );
|
|
54
|
+
|
|
55
|
+
this.object = this.editor.objectByUuid( json.object.object.uuid );
|
|
56
|
+
|
|
57
|
+
if ( this.object === undefined ) {
|
|
58
|
+
|
|
59
|
+
const loader = new ObjectLoader();
|
|
60
|
+
this.object = loader.parse( json.object );
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { AddObjectCommand };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Command } from '../Command.js';
|
|
2
|
+
|
|
3
|
+
class AddScriptCommand extends Command {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Editor} editor
|
|
7
|
+
* @param {THREE.Object3D|null} [object=null]
|
|
8
|
+
* @param {string} [script='']
|
|
9
|
+
* @constructor
|
|
10
|
+
*/
|
|
11
|
+
constructor( editor, object = null, script = '' ) {
|
|
12
|
+
|
|
13
|
+
super( editor );
|
|
14
|
+
|
|
15
|
+
this.type = 'AddScriptCommand';
|
|
16
|
+
this.name = editor.strings.getKey( 'command/AddScript' );
|
|
17
|
+
|
|
18
|
+
this.object = object;
|
|
19
|
+
this.script = script;
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
execute() {
|
|
24
|
+
|
|
25
|
+
if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
|
|
26
|
+
|
|
27
|
+
this.editor.scripts[ this.object.uuid ] = [];
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.editor.scripts[ this.object.uuid ].push( this.script );
|
|
32
|
+
|
|
33
|
+
this.editor.signals.scriptAdded.dispatch( this.script );
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
undo() {
|
|
38
|
+
|
|
39
|
+
if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
|
|
40
|
+
|
|
41
|
+
const index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
|
|
42
|
+
|
|
43
|
+
if ( index !== - 1 ) {
|
|
44
|
+
|
|
45
|
+
this.editor.scripts[ this.object.uuid ].splice( index, 1 );
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.editor.signals.scriptRemoved.dispatch( this.script );
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
toJSON() {
|
|
54
|
+
|
|
55
|
+
const output = super.toJSON( this );
|
|
56
|
+
|
|
57
|
+
output.objectUuid = this.object.uuid;
|
|
58
|
+
output.script = this.script;
|
|
59
|
+
|
|
60
|
+
return output;
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fromJSON( json ) {
|
|
65
|
+
|
|
66
|
+
super.fromJSON( json );
|
|
67
|
+
|
|
68
|
+
this.script = json.script;
|
|
69
|
+
this.object = this.editor.objectByUuid( json.objectUuid );
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { AddScriptCommand };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { AddObjectCommand } from './AddObjectCommand.js';
|
|
2
|
+
export { AddScriptCommand } from './AddScriptCommand.js';
|
|
3
|
+
export { MoveObjectCommand } from './MoveObjectCommand.js';
|
|
4
|
+
export { MultiCmdsCommand } from './MultiCmdsCommand.js';
|
|
5
|
+
export { RemoveObjectCommand } from './RemoveObjectCommand.js';
|
|
6
|
+
export { RemoveScriptCommand } from './RemoveScriptCommand.js';
|
|
7
|
+
export { SetColorCommand } from './SetColorCommand.js';
|
|
8
|
+
export { SetGeometryCommand } from './SetGeometryCommand.js';
|
|
9
|
+
export { SetGeometryValueCommand } from './SetGeometryValueCommand.js';
|
|
10
|
+
export { SetMaterialColorCommand } from './SetMaterialColorCommand.js';
|
|
11
|
+
export { SetMaterialCommand } from './SetMaterialCommand.js';
|
|
12
|
+
export { SetMaterialMapCommand } from './SetMaterialMapCommand.js';
|
|
13
|
+
export { SetMaterialRangeCommand } from './SetMaterialRangeCommand.js';
|
|
14
|
+
export { SetMaterialValueCommand } from './SetMaterialValueCommand.js';
|
|
15
|
+
export { SetMaterialVectorCommand } from './SetMaterialVectorCommand.js';
|
|
16
|
+
export { SetPositionCommand } from './SetPositionCommand.js';
|
|
17
|
+
export { SetRotationCommand } from './SetRotationCommand.js';
|
|
18
|
+
export { SetScaleCommand } from './SetScaleCommand.js';
|
|
19
|
+
export { SetSceneCommand } from './SetSceneCommand.js';
|
|
20
|
+
export { SetScriptValueCommand } from './SetScriptValueCommand.js';
|
|
21
|
+
export { SetShadowValueCommand } from './SetShadowValueCommand.js';
|
|
22
|
+
export { SetTextureParametersCommand } from './SetTextureParametersCommand.js';
|
|
23
|
+
export { SetUuidCommand } from './SetUuidCommand.js';
|
|
24
|
+
export { SetValueCommand } from './SetValueCommand.js';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Command } from '../Command.js';
|
|
2
|
+
|
|
3
|
+
class MoveObjectCommand extends Command {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Editor} editor
|
|
7
|
+
* @param {THREE.Object3D|null} [object=null]
|
|
8
|
+
* @param {THREE.Object3D|null} [newParent=null]
|
|
9
|
+
* @param {THREE.Object3D|null} [newBefore=null]
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
constructor( editor, object = null, newParent = null, newBefore = null ) {
|
|
13
|
+
|
|
14
|
+
super( editor );
|
|
15
|
+
|
|
16
|
+
this.type = 'MoveObjectCommand';
|
|
17
|
+
this.name = editor.strings.getKey( 'command/MoveObject' );
|
|
18
|
+
|
|
19
|
+
this.object = object;
|
|
20
|
+
this.oldParent = ( object !== null ) ? object.parent : null;
|
|
21
|
+
this.oldIndex = ( this.oldParent !== null ) ? this.oldParent.children.indexOf( this.object ) : null;
|
|
22
|
+
this.newParent = newParent;
|
|
23
|
+
|
|
24
|
+
if ( newBefore !== null ) {
|
|
25
|
+
|
|
26
|
+
this.newIndex = ( newParent !== null ) ? newParent.children.indexOf( newBefore ) : null;
|
|
27
|
+
|
|
28
|
+
} else {
|
|
29
|
+
|
|
30
|
+
this.newIndex = ( newParent !== null ) ? newParent.children.length : null;
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if ( this.oldParent === this.newParent && this.newIndex > this.oldIndex ) {
|
|
35
|
+
|
|
36
|
+
this.newIndex --;
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.newBefore = newBefore;
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
execute() {
|
|
45
|
+
|
|
46
|
+
this.oldParent.remove( this.object );
|
|
47
|
+
|
|
48
|
+
const children = this.newParent.children;
|
|
49
|
+
children.splice( this.newIndex, 0, this.object );
|
|
50
|
+
this.object.parent = this.newParent;
|
|
51
|
+
|
|
52
|
+
this.object.dispatchEvent( { type: 'added' } );
|
|
53
|
+
this.editor.signals.objectChanged.dispatch( this.object );
|
|
54
|
+
this.editor.signals.objectChanged.dispatch( this.newParent );
|
|
55
|
+
this.editor.signals.objectChanged.dispatch( this.oldParent );
|
|
56
|
+
this.editor.signals.sceneGraphChanged.dispatch();
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
undo() {
|
|
61
|
+
|
|
62
|
+
this.newParent.remove( this.object );
|
|
63
|
+
|
|
64
|
+
const children = this.oldParent.children;
|
|
65
|
+
children.splice( this.oldIndex, 0, this.object );
|
|
66
|
+
this.object.parent = this.oldParent;
|
|
67
|
+
|
|
68
|
+
this.object.dispatchEvent( { type: 'added' } );
|
|
69
|
+
this.editor.signals.objectChanged.dispatch( this.object );
|
|
70
|
+
this.editor.signals.objectChanged.dispatch( this.newParent );
|
|
71
|
+
this.editor.signals.objectChanged.dispatch( this.oldParent );
|
|
72
|
+
this.editor.signals.sceneGraphChanged.dispatch();
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
toJSON() {
|
|
77
|
+
|
|
78
|
+
const output = super.toJSON( this );
|
|
79
|
+
|
|
80
|
+
output.objectUuid = this.object.uuid;
|
|
81
|
+
output.newParentUuid = this.newParent.uuid;
|
|
82
|
+
output.oldParentUuid = this.oldParent.uuid;
|
|
83
|
+
output.newIndex = this.newIndex;
|
|
84
|
+
output.oldIndex = this.oldIndex;
|
|
85
|
+
|
|
86
|
+
return output;
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
fromJSON( json ) {
|
|
91
|
+
|
|
92
|
+
super.fromJSON( json );
|
|
93
|
+
|
|
94
|
+
this.object = this.editor.objectByUuid( json.objectUuid );
|
|
95
|
+
this.oldParent = this.editor.objectByUuid( json.oldParentUuid );
|
|
96
|
+
if ( this.oldParent === undefined ) {
|
|
97
|
+
|
|
98
|
+
this.oldParent = this.editor.scene;
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.newParent = this.editor.objectByUuid( json.newParentUuid );
|
|
103
|
+
|
|
104
|
+
if ( this.newParent === undefined ) {
|
|
105
|
+
|
|
106
|
+
this.newParent = this.editor.scene;
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.newIndex = json.newIndex;
|
|
111
|
+
this.oldIndex = json.oldIndex;
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { MoveObjectCommand };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Command } from '../Command.js';
|
|
2
|
+
|
|
3
|
+
class MultiCmdsCommand extends Command {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Editor} editor
|
|
7
|
+
* @param {Array<Command>} [cmdArray=[]]
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
constructor( editor, cmdArray = [] ) {
|
|
11
|
+
|
|
12
|
+
super( editor );
|
|
13
|
+
|
|
14
|
+
this.type = 'MultiCmdsCommand';
|
|
15
|
+
this.name = editor.strings.getKey( 'command/MultiCmds' );
|
|
16
|
+
|
|
17
|
+
this.cmdArray = cmdArray;
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
execute() {
|
|
22
|
+
|
|
23
|
+
this.editor.signals.sceneGraphChanged.active = false;
|
|
24
|
+
|
|
25
|
+
for ( let i = 0; i < this.cmdArray.length; i ++ ) {
|
|
26
|
+
|
|
27
|
+
this.cmdArray[ i ].execute();
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.editor.signals.sceneGraphChanged.active = true;
|
|
32
|
+
this.editor.signals.sceneGraphChanged.dispatch();
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
undo() {
|
|
37
|
+
|
|
38
|
+
this.editor.signals.sceneGraphChanged.active = false;
|
|
39
|
+
|
|
40
|
+
for ( let i = this.cmdArray.length - 1; i >= 0; i -- ) {
|
|
41
|
+
|
|
42
|
+
this.cmdArray[ i ].undo();
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.editor.signals.sceneGraphChanged.active = true;
|
|
47
|
+
this.editor.signals.sceneGraphChanged.dispatch();
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toJSON() {
|
|
52
|
+
|
|
53
|
+
const output = super.toJSON( this );
|
|
54
|
+
|
|
55
|
+
const cmds = [];
|
|
56
|
+
for ( let i = 0; i < this.cmdArray.length; i ++ ) {
|
|
57
|
+
|
|
58
|
+
cmds.push( this.cmdArray[ i ].toJSON() );
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
output.cmds = cmds;
|
|
63
|
+
|
|
64
|
+
return output;
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fromJSON( json ) {
|
|
69
|
+
|
|
70
|
+
super.fromJSON( json );
|
|
71
|
+
|
|
72
|
+
const cmds = json.cmds;
|
|
73
|
+
for ( let i = 0; i < cmds.length; i ++ ) {
|
|
74
|
+
|
|
75
|
+
const cmd = new window[ cmds[ i ].type ](); // creates a new object of type "json.type"
|
|
76
|
+
cmd.fromJSON( cmds[ i ] );
|
|
77
|
+
this.cmdArray.push( cmd );
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { MultiCmdsCommand };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Command } from '../Command.js';
|
|
2
|
+
|
|
3
|
+
import { ObjectLoader } from 'three';
|
|
4
|
+
|
|
5
|
+
class RemoveObjectCommand extends Command {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {Editor} editor
|
|
9
|
+
* @param {THREE.Object3D|null} [object=null]
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
constructor( editor, object = null ) {
|
|
13
|
+
|
|
14
|
+
super( editor );
|
|
15
|
+
|
|
16
|
+
this.type = 'RemoveObjectCommand';
|
|
17
|
+
|
|
18
|
+
this.object = object;
|
|
19
|
+
this.parent = ( object !== null ) ? object.parent : null;
|
|
20
|
+
|
|
21
|
+
if ( this.parent !== null ) {
|
|
22
|
+
|
|
23
|
+
this.index = this.parent.children.indexOf( this.object );
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if ( object !== null ) {
|
|
28
|
+
|
|
29
|
+
this.name = editor.strings.getKey( 'command/RemoveObject' ) + ': ' + object.name;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
execute() {
|
|
37
|
+
|
|
38
|
+
this.editor.removeObject( this.object );
|
|
39
|
+
this.editor.deselect();
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
undo() {
|
|
44
|
+
|
|
45
|
+
this.editor.addObject( this.object, this.parent, this.index );
|
|
46
|
+
this.editor.select( this.object );
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
toJSON() {
|
|
51
|
+
|
|
52
|
+
const output = super.toJSON( this );
|
|
53
|
+
|
|
54
|
+
output.object = this.object.toJSON();
|
|
55
|
+
output.index = this.index;
|
|
56
|
+
output.parentUuid = this.parent.uuid;
|
|
57
|
+
|
|
58
|
+
return output;
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fromJSON( json ) {
|
|
63
|
+
|
|
64
|
+
super.fromJSON( json );
|
|
65
|
+
|
|
66
|
+
this.parent = this.editor.objectByUuid( json.parentUuid );
|
|
67
|
+
if ( this.parent === undefined ) {
|
|
68
|
+
|
|
69
|
+
this.parent = this.editor.scene;
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.index = json.index;
|
|
74
|
+
|
|
75
|
+
this.object = this.editor.objectByUuid( json.object.object.uuid );
|
|
76
|
+
|
|
77
|
+
if ( this.object === undefined ) {
|
|
78
|
+
|
|
79
|
+
const loader = new ObjectLoader();
|
|
80
|
+
this.object = loader.parse( json.object );
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { RemoveObjectCommand };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Command } from '../Command.js';
|
|
2
|
+
|
|
3
|
+
class RemoveScriptCommand extends Command {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Editor} editor
|
|
7
|
+
* @param {THREE.Object3D|null} [object=null]
|
|
8
|
+
* @param {string} [script='']
|
|
9
|
+
* @constructor
|
|
10
|
+
*/
|
|
11
|
+
constructor( editor, object = null, script = '' ) {
|
|
12
|
+
|
|
13
|
+
super( editor );
|
|
14
|
+
|
|
15
|
+
this.type = 'RemoveScriptCommand';
|
|
16
|
+
this.name = editor.strings.getKey( 'command/RemoveScript' );
|
|
17
|
+
|
|
18
|
+
this.object = object;
|
|
19
|
+
this.script = script;
|
|
20
|
+
|
|
21
|
+
if ( this.object !== null && this.script !== '' ) {
|
|
22
|
+
|
|
23
|
+
this.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
execute() {
|
|
30
|
+
|
|
31
|
+
if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
|
|
32
|
+
|
|
33
|
+
if ( this.index !== - 1 ) {
|
|
34
|
+
|
|
35
|
+
this.editor.scripts[ this.object.uuid ].splice( this.index, 1 );
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.editor.signals.scriptRemoved.dispatch( this.script );
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
undo() {
|
|
44
|
+
|
|
45
|
+
if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
|
|
46
|
+
|
|
47
|
+
this.editor.scripts[ this.object.uuid ] = [];
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.editor.scripts[ this.object.uuid ].splice( this.index, 0, this.script );
|
|
52
|
+
|
|
53
|
+
this.editor.signals.scriptAdded.dispatch( this.script );
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
toJSON() {
|
|
58
|
+
|
|
59
|
+
const output = super.toJSON( this );
|
|
60
|
+
|
|
61
|
+
output.objectUuid = this.object.uuid;
|
|
62
|
+
output.script = this.script;
|
|
63
|
+
output.index = this.index;
|
|
64
|
+
|
|
65
|
+
return output;
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fromJSON( json ) {
|
|
70
|
+
|
|
71
|
+
super.fromJSON( json );
|
|
72
|
+
|
|
73
|
+
this.script = json.script;
|
|
74
|
+
this.index = json.index;
|
|
75
|
+
this.object = this.editor.objectByUuid( json.objectUuid );
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { RemoveScriptCommand };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Command } from '../Command.js';
|
|
2
|
+
|
|
3
|
+
class SetColorCommand extends Command {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Editor} editor
|
|
7
|
+
* @param {THREE.Object3D|null} [object=null]
|
|
8
|
+
* @param {string} attributeName
|
|
9
|
+
* @param {?number} [newValue=null] Integer representing a hex color value
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
constructor( editor, object = null, attributeName = '', newValue = null ) {
|
|
13
|
+
|
|
14
|
+
super( editor );
|
|
15
|
+
|
|
16
|
+
this.type = 'SetColorCommand';
|
|
17
|
+
this.name = editor.strings.getKey( 'command/SetColor' ) + ': ' + attributeName;
|
|
18
|
+
this.updatable = true;
|
|
19
|
+
|
|
20
|
+
this.object = object;
|
|
21
|
+
this.attributeName = attributeName;
|
|
22
|
+
this.oldValue = ( object !== null ) ? this.object[ this.attributeName ].getHex() : null;
|
|
23
|
+
this.newValue = newValue;
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
execute() {
|
|
28
|
+
|
|
29
|
+
this.object[ this.attributeName ].setHex( this.newValue );
|
|
30
|
+
this.editor.signals.objectChanged.dispatch( this.object );
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
undo() {
|
|
35
|
+
|
|
36
|
+
this.object[ this.attributeName ].setHex( this.oldValue );
|
|
37
|
+
this.editor.signals.objectChanged.dispatch( this.object );
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
update( cmd ) {
|
|
42
|
+
|
|
43
|
+
this.newValue = cmd.newValue;
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
toJSON() {
|
|
48
|
+
|
|
49
|
+
const output = super.toJSON( this );
|
|
50
|
+
|
|
51
|
+
output.objectUuid = this.object.uuid;
|
|
52
|
+
output.attributeName = this.attributeName;
|
|
53
|
+
output.oldValue = this.oldValue;
|
|
54
|
+
output.newValue = this.newValue;
|
|
55
|
+
|
|
56
|
+
return output;
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fromJSON( json ) {
|
|
61
|
+
|
|
62
|
+
super.fromJSON( json );
|
|
63
|
+
|
|
64
|
+
this.object = this.editor.objectByUuid( json.objectUuid );
|
|
65
|
+
this.attributeName = json.attributeName;
|
|
66
|
+
this.oldValue = json.oldValue;
|
|
67
|
+
this.newValue = json.newValue;
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { SetColorCommand };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Command } from '../Command.js';
|
|
2
|
+
import { ObjectLoader } from 'three';
|
|
3
|
+
|
|
4
|
+
class SetGeometryCommand extends Command {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {Editor} editor
|
|
8
|
+
* @param {THREE.Object3D|null} [object=null]
|
|
9
|
+
* @param {THREE.Geometry|null} [newGeometry=null]
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
constructor( editor, object = null, newGeometry = null ) {
|
|
13
|
+
|
|
14
|
+
super( editor );
|
|
15
|
+
|
|
16
|
+
this.type = 'SetGeometryCommand';
|
|
17
|
+
this.name = editor.strings.getKey( 'command/SetGeometry' );
|
|
18
|
+
this.updatable = true;
|
|
19
|
+
|
|
20
|
+
this.object = object;
|
|
21
|
+
this.oldGeometry = ( object !== null ) ? object.geometry : null;
|
|
22
|
+
this.newGeometry = newGeometry;
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
execute() {
|
|
27
|
+
|
|
28
|
+
this.object.geometry.dispose();
|
|
29
|
+
this.object.geometry = this.newGeometry;
|
|
30
|
+
this.object.geometry.computeBoundingSphere();
|
|
31
|
+
|
|
32
|
+
this.editor.signals.geometryChanged.dispatch( this.object );
|
|
33
|
+
this.editor.signals.sceneGraphChanged.dispatch();
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
undo() {
|
|
38
|
+
|
|
39
|
+
this.object.geometry.dispose();
|
|
40
|
+
this.object.geometry = this.oldGeometry;
|
|
41
|
+
this.object.geometry.computeBoundingSphere();
|
|
42
|
+
|
|
43
|
+
this.editor.signals.geometryChanged.dispatch( this.object );
|
|
44
|
+
this.editor.signals.sceneGraphChanged.dispatch();
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
update( cmd ) {
|
|
49
|
+
|
|
50
|
+
this.newGeometry = cmd.newGeometry;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
toJSON() {
|
|
55
|
+
|
|
56
|
+
const output = super.toJSON( this );
|
|
57
|
+
|
|
58
|
+
output.objectUuid = this.object.uuid;
|
|
59
|
+
output.oldGeometry = this.oldGeometry.toJSON();
|
|
60
|
+
output.newGeometry = this.newGeometry.toJSON();
|
|
61
|
+
|
|
62
|
+
return output;
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fromJSON( json ) {
|
|
67
|
+
|
|
68
|
+
super.fromJSON( json );
|
|
69
|
+
|
|
70
|
+
this.object = this.editor.objectByUuid( json.objectUuid );
|
|
71
|
+
|
|
72
|
+
this.oldGeometry = parseGeometry( json.oldGeometry );
|
|
73
|
+
this.newGeometry = parseGeometry( json.newGeometry );
|
|
74
|
+
|
|
75
|
+
function parseGeometry( data ) {
|
|
76
|
+
|
|
77
|
+
const loader = new ObjectLoader();
|
|
78
|
+
return loader.parseGeometries( [ data ] )[ data.uuid ];
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { SetGeometryCommand };
|