@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.
Files changed (136) hide show
  1. package/README.md +169 -0
  2. package/dist/index.css +921 -0
  3. package/dist/index.js +14076 -0
  4. package/package.json +49 -0
  5. package/src/editor/css/main.css +1030 -0
  6. package/src/editor/js/Animation.js +618 -0
  7. package/src/editor/js/AnimationResizer.js +73 -0
  8. package/src/editor/js/Command.js +40 -0
  9. package/src/editor/js/Config.js +86 -0
  10. package/src/editor/js/Editor.js +1006 -0
  11. package/src/editor/js/EditorControls.js +489 -0
  12. package/src/editor/js/GLTFImportDialog.js +112 -0
  13. package/src/editor/js/History.js +321 -0
  14. package/src/editor/js/Loader.js +1162 -0
  15. package/src/editor/js/LoaderUtils.js +90 -0
  16. package/src/editor/js/Menubar.Add.js +559 -0
  17. package/src/editor/js/Menubar.Edit.js +155 -0
  18. package/src/editor/js/Menubar.File.js +585 -0
  19. package/src/editor/js/Menubar.Help.js +73 -0
  20. package/src/editor/js/Menubar.Render.js +858 -0
  21. package/src/editor/js/Menubar.Status.js +51 -0
  22. package/src/editor/js/Menubar.View.js +193 -0
  23. package/src/editor/js/Menubar.js +29 -0
  24. package/src/editor/js/Player.js +53 -0
  25. package/src/editor/js/Resizer.js +65 -0
  26. package/src/editor/js/Script.js +532 -0
  27. package/src/editor/js/Selector.js +129 -0
  28. package/src/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
  29. package/src/editor/js/Sidebar.Geometry.BufferGeometry.js +124 -0
  30. package/src/editor/js/Sidebar.Geometry.CapsuleGeometry.js +109 -0
  31. package/src/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
  32. package/src/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
  33. package/src/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
  34. package/src/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
  35. package/src/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
  36. package/src/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
  37. package/src/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
  38. package/src/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
  39. package/src/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
  40. package/src/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
  41. package/src/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
  42. package/src/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
  43. package/src/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
  44. package/src/editor/js/Sidebar.Geometry.TextGeometry.js +136 -0
  45. package/src/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
  46. package/src/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
  47. package/src/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
  48. package/src/editor/js/Sidebar.Geometry.js +471 -0
  49. package/src/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
  50. package/src/editor/js/Sidebar.Material.ColorProperty.js +87 -0
  51. package/src/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
  52. package/src/editor/js/Sidebar.Material.MapProperty.js +277 -0
  53. package/src/editor/js/Sidebar.Material.NumberProperty.js +60 -0
  54. package/src/editor/js/Sidebar.Material.Program.js +73 -0
  55. package/src/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
  56. package/src/editor/js/Sidebar.Material.js +751 -0
  57. package/src/editor/js/Sidebar.Object.js +892 -0
  58. package/src/editor/js/Sidebar.Project.App.js +218 -0
  59. package/src/editor/js/Sidebar.Project.Materials.js +82 -0
  60. package/src/editor/js/Sidebar.Project.Renderer.js +193 -0
  61. package/src/editor/js/Sidebar.Project.Resources.js +242 -0
  62. package/src/editor/js/Sidebar.Project.js +21 -0
  63. package/src/editor/js/Sidebar.Properties.js +73 -0
  64. package/src/editor/js/Sidebar.Scene.js +643 -0
  65. package/src/editor/js/Sidebar.Script.js +129 -0
  66. package/src/editor/js/Sidebar.Settings.History.js +146 -0
  67. package/src/editor/js/Sidebar.Settings.Shortcuts.js +198 -0
  68. package/src/editor/js/Sidebar.Settings.js +58 -0
  69. package/src/editor/js/Sidebar.js +41 -0
  70. package/src/editor/js/Storage.js +98 -0
  71. package/src/editor/js/Strings.js +2718 -0
  72. package/src/editor/js/TextureParametersDialog.js +293 -0
  73. package/src/editor/js/Toolbar.js +75 -0
  74. package/src/editor/js/Viewport.Controls.js +98 -0
  75. package/src/editor/js/Viewport.Info.js +144 -0
  76. package/src/editor/js/Viewport.Pathtracer.js +27 -0
  77. package/src/editor/js/Viewport.ViewHelper.js +41 -0
  78. package/src/editor/js/Viewport.XR.js +7 -0
  79. package/src/editor/js/Viewport.js +982 -0
  80. package/src/editor/js/commands/AddObjectCommand.js +68 -0
  81. package/src/editor/js/commands/AddScriptCommand.js +75 -0
  82. package/src/editor/js/commands/Commands.js +24 -0
  83. package/src/editor/js/commands/MoveObjectCommand.js +117 -0
  84. package/src/editor/js/commands/MultiCmdsCommand.js +85 -0
  85. package/src/editor/js/commands/RemoveObjectCommand.js +88 -0
  86. package/src/editor/js/commands/RemoveScriptCommand.js +81 -0
  87. package/src/editor/js/commands/SetColorCommand.js +73 -0
  88. package/src/editor/js/commands/SetGeometryCommand.js +86 -0
  89. package/src/editor/js/commands/SetGeometryValueCommand.js +70 -0
  90. package/src/editor/js/commands/SetMaterialColorCommand.js +87 -0
  91. package/src/editor/js/commands/SetMaterialCommand.js +80 -0
  92. package/src/editor/js/commands/SetMaterialMapCommand.js +144 -0
  93. package/src/editor/js/commands/SetMaterialRangeCommand.js +92 -0
  94. package/src/editor/js/commands/SetMaterialValueCommand.js +91 -0
  95. package/src/editor/js/commands/SetMaterialVectorCommand.js +88 -0
  96. package/src/editor/js/commands/SetPositionCommand.js +84 -0
  97. package/src/editor/js/commands/SetRotationCommand.js +84 -0
  98. package/src/editor/js/commands/SetScaleCommand.js +84 -0
  99. package/src/editor/js/commands/SetSceneCommand.js +104 -0
  100. package/src/editor/js/commands/SetScriptValueCommand.js +80 -0
  101. package/src/editor/js/commands/SetShadowValueCommand.js +73 -0
  102. package/src/editor/js/commands/SetTextureParametersCommand.js +143 -0
  103. package/src/editor/js/commands/SetUuidCommand.js +70 -0
  104. package/src/editor/js/commands/SetValueCommand.js +75 -0
  105. package/src/editor/js/libs/acorn/acorn.js +3236 -0
  106. package/src/editor/js/libs/acorn/acorn_loose.js +1299 -0
  107. package/src/editor/js/libs/acorn/walk.js +344 -0
  108. package/src/editor/js/libs/app/index.html +51 -0
  109. package/src/editor/js/libs/app.js +14 -0
  110. package/src/editor/js/libs/codemirror/addon/dialog.css +32 -0
  111. package/src/editor/js/libs/codemirror/addon/dialog.js +163 -0
  112. package/src/editor/js/libs/codemirror/addon/show-hint.css +36 -0
  113. package/src/editor/js/libs/codemirror/addon/show-hint.js +529 -0
  114. package/src/editor/js/libs/codemirror/addon/tern.css +87 -0
  115. package/src/editor/js/libs/codemirror/addon/tern.js +750 -0
  116. package/src/editor/js/libs/codemirror/codemirror.css +344 -0
  117. package/src/editor/js/libs/codemirror/codemirror.js +9849 -0
  118. package/src/editor/js/libs/codemirror/mode/glsl.js +233 -0
  119. package/src/editor/js/libs/codemirror/mode/javascript.js +959 -0
  120. package/src/editor/js/libs/codemirror/theme/monokai.css +41 -0
  121. package/src/editor/js/libs/esprima.js +6401 -0
  122. package/src/editor/js/libs/jsonlint.js +453 -0
  123. package/src/editor/js/libs/signals.min.js +14 -0
  124. package/src/editor/js/libs/tern-threejs/build-defs.js +233 -0
  125. package/src/editor/js/libs/ternjs/comment.js +87 -0
  126. package/src/editor/js/libs/ternjs/def.js +588 -0
  127. package/src/editor/js/libs/ternjs/doc_comment.js +401 -0
  128. package/src/editor/js/libs/ternjs/infer.js +1635 -0
  129. package/src/editor/js/libs/ternjs/polyfill.js +80 -0
  130. package/src/editor/js/libs/ternjs/signal.js +26 -0
  131. package/src/editor/js/libs/ternjs/tern.js +993 -0
  132. package/src/editor/js/libs/ui.js +1305 -0
  133. package/src/editor/js/libs/ui.three.js +946 -0
  134. package/src/events.js +273 -0
  135. package/src/index.js +284 -0
  136. package/src/presets/machines.js +239 -0
@@ -0,0 +1,84 @@
1
+ import { Command } from '../Command.js';
2
+ import { Vector3 } from 'three';
3
+
4
+ class SetPositionCommand extends Command {
5
+
6
+ /**
7
+ * @param {Editor} editor
8
+ * @param {THREE.Object3D|null} object
9
+ * @param {THREE.Vector3|null} newPosition
10
+ * @param {THREE.Vector3|null} optionalOldPosition
11
+ * @constructor
12
+ */
13
+ constructor( editor, object = null, newPosition = null, optionalOldPosition = null ) {
14
+
15
+ super( editor );
16
+
17
+ this.type = 'SetPositionCommand';
18
+ this.name = editor.strings.getKey( 'command/SetPosition' );
19
+ this.updatable = true;
20
+
21
+ this.object = object;
22
+
23
+ if ( object !== null && newPosition !== null ) {
24
+
25
+ this.oldPosition = object.position.clone();
26
+ this.newPosition = newPosition.clone();
27
+
28
+ }
29
+
30
+ if ( optionalOldPosition !== null ) {
31
+
32
+ this.oldPosition = optionalOldPosition.clone();
33
+
34
+ }
35
+
36
+ }
37
+
38
+ execute() {
39
+
40
+ this.object.position.copy( this.newPosition );
41
+ this.object.updateMatrixWorld( true );
42
+ this.editor.signals.objectChanged.dispatch( this.object );
43
+
44
+ }
45
+
46
+ undo() {
47
+
48
+ this.object.position.copy( this.oldPosition );
49
+ this.object.updateMatrixWorld( true );
50
+ this.editor.signals.objectChanged.dispatch( this.object );
51
+
52
+ }
53
+
54
+ update( command ) {
55
+
56
+ this.newPosition.copy( command.newPosition );
57
+
58
+ }
59
+
60
+ toJSON() {
61
+
62
+ const output = super.toJSON( this );
63
+
64
+ output.objectUuid = this.object.uuid;
65
+ output.oldPosition = this.oldPosition.toArray();
66
+ output.newPosition = this.newPosition.toArray();
67
+
68
+ return output;
69
+
70
+ }
71
+
72
+ fromJSON( json ) {
73
+
74
+ super.fromJSON( json );
75
+
76
+ this.object = this.editor.objectByUuid( json.objectUuid );
77
+ this.oldPosition = new Vector3().fromArray( json.oldPosition );
78
+ this.newPosition = new Vector3().fromArray( json.newPosition );
79
+
80
+ }
81
+
82
+ }
83
+
84
+ export { SetPositionCommand };
@@ -0,0 +1,84 @@
1
+ import { Command } from '../Command.js';
2
+ import { Euler } from 'three';
3
+
4
+ class SetRotationCommand extends Command {
5
+
6
+ /**
7
+ * @param {Editor} editor
8
+ * @param {THREE.Object3D|null} object
9
+ * @param {THREE.Euler|null} newRotation
10
+ * @param {THREE.Euler|null} optionalOldRotation
11
+ * @constructor
12
+ */
13
+ constructor( editor, object = null, newRotation = null, optionalOldRotation = null ) {
14
+
15
+ super( editor );
16
+
17
+ this.type = 'SetRotationCommand';
18
+ this.name = editor.strings.getKey( 'command/SetRotation' );
19
+ this.updatable = true;
20
+
21
+ this.object = object;
22
+
23
+ if ( object !== null && newRotation !== null ) {
24
+
25
+ this.oldRotation = object.rotation.clone();
26
+ this.newRotation = newRotation.clone();
27
+
28
+ }
29
+
30
+ if ( optionalOldRotation !== null ) {
31
+
32
+ this.oldRotation = optionalOldRotation.clone();
33
+
34
+ }
35
+
36
+ }
37
+
38
+ execute() {
39
+
40
+ this.object.rotation.copy( this.newRotation );
41
+ this.object.updateMatrixWorld( true );
42
+ this.editor.signals.objectChanged.dispatch( this.object );
43
+
44
+ }
45
+
46
+ undo() {
47
+
48
+ this.object.rotation.copy( this.oldRotation );
49
+ this.object.updateMatrixWorld( true );
50
+ this.editor.signals.objectChanged.dispatch( this.object );
51
+
52
+ }
53
+
54
+ update( command ) {
55
+
56
+ this.newRotation.copy( command.newRotation );
57
+
58
+ }
59
+
60
+ toJSON() {
61
+
62
+ const output = super.toJSON( this );
63
+
64
+ output.objectUuid = this.object.uuid;
65
+ output.oldRotation = this.oldRotation.toArray();
66
+ output.newRotation = this.newRotation.toArray();
67
+
68
+ return output;
69
+
70
+ }
71
+
72
+ fromJSON( json ) {
73
+
74
+ super.fromJSON( json );
75
+
76
+ this.object = this.editor.objectByUuid( json.objectUuid );
77
+ this.oldRotation = new Euler().fromArray( json.oldRotation );
78
+ this.newRotation = new Euler().fromArray( json.newRotation );
79
+
80
+ }
81
+
82
+ }
83
+
84
+ export { SetRotationCommand };
@@ -0,0 +1,84 @@
1
+ import { Command } from '../Command.js';
2
+ import { Vector3 } from 'three';
3
+
4
+ class SetScaleCommand extends Command {
5
+
6
+ /**
7
+ * @param {Editor} editor
8
+ * @param {THREE.Object3D|null} object
9
+ * @param {THREE.Vector3|null} newScale
10
+ * @param {THREE.Vector3|null} optionalOldScale
11
+ * @constructor
12
+ */
13
+ constructor( editor, object = null, newScale = null, optionalOldScale = null ) {
14
+
15
+ super( editor );
16
+
17
+ this.type = 'SetScaleCommand';
18
+ this.name = editor.strings.getKey( 'command/SetScale' );
19
+ this.updatable = true;
20
+
21
+ this.object = object;
22
+
23
+ if ( object !== null && newScale !== null ) {
24
+
25
+ this.oldScale = object.scale.clone();
26
+ this.newScale = newScale.clone();
27
+
28
+ }
29
+
30
+ if ( optionalOldScale !== null ) {
31
+
32
+ this.oldScale = optionalOldScale.clone();
33
+
34
+ }
35
+
36
+ }
37
+
38
+ execute() {
39
+
40
+ this.object.scale.copy( this.newScale );
41
+ this.object.updateMatrixWorld( true );
42
+ this.editor.signals.objectChanged.dispatch( this.object );
43
+
44
+ }
45
+
46
+ undo() {
47
+
48
+ this.object.scale.copy( this.oldScale );
49
+ this.object.updateMatrixWorld( true );
50
+ this.editor.signals.objectChanged.dispatch( this.object );
51
+
52
+ }
53
+
54
+ update( command ) {
55
+
56
+ this.newScale.copy( command.newScale );
57
+
58
+ }
59
+
60
+ toJSON() {
61
+
62
+ const output = super.toJSON( this );
63
+
64
+ output.objectUuid = this.object.uuid;
65
+ output.oldScale = this.oldScale.toArray();
66
+ output.newScale = this.newScale.toArray();
67
+
68
+ return output;
69
+
70
+ }
71
+
72
+ fromJSON( json ) {
73
+
74
+ super.fromJSON( json );
75
+
76
+ this.object = this.editor.objectByUuid( json.objectUuid );
77
+ this.oldScale = new Vector3().fromArray( json.oldScale );
78
+ this.newScale = new Vector3().fromArray( json.newScale );
79
+
80
+ }
81
+
82
+ }
83
+
84
+ export { SetScaleCommand };
@@ -0,0 +1,104 @@
1
+ import { Command } from '../Command.js';
2
+ import { SetUuidCommand } from './SetUuidCommand.js';
3
+ import { SetValueCommand } from './SetValueCommand.js';
4
+ import { AddObjectCommand } from './AddObjectCommand.js';
5
+
6
+ class SetSceneCommand extends Command {
7
+
8
+ /**
9
+ * @param {Editor} editor
10
+ * @param {THREE.Scene|null} [scene=null]
11
+ * @constructor
12
+ */
13
+ constructor( editor, scene = null ) {
14
+
15
+ super( editor );
16
+
17
+ this.type = 'SetSceneCommand';
18
+ this.name = editor.strings.getKey( 'command/SetScene' );
19
+
20
+ this.cmdArray = [];
21
+
22
+ if ( scene !== null ) {
23
+
24
+ this.cmdArray.push( new SetUuidCommand( this.editor, this.editor.scene, scene.uuid ) );
25
+ this.cmdArray.push( new SetValueCommand( this.editor, this.editor.scene, 'name', scene.name ) );
26
+ this.cmdArray.push( new SetValueCommand( this.editor, this.editor.scene, 'userData', JSON.parse( JSON.stringify( scene.userData ) ) ) );
27
+ this.cmdArray.push( new SetValueCommand( this.editor, this.editor.scene, 'animations', scene.animations ) );
28
+
29
+ while ( scene.children.length > 0 ) {
30
+
31
+ const child = scene.children.pop();
32
+ this.cmdArray.push( new AddObjectCommand( this.editor, child ) );
33
+
34
+ }
35
+
36
+ }
37
+
38
+ }
39
+
40
+ execute() {
41
+
42
+ this.editor.signals.sceneGraphChanged.active = false;
43
+
44
+ for ( let i = 0; i < this.cmdArray.length; i ++ ) {
45
+
46
+ this.cmdArray[ i ].execute();
47
+
48
+ }
49
+
50
+ this.editor.signals.sceneGraphChanged.active = true;
51
+ this.editor.signals.sceneGraphChanged.dispatch();
52
+
53
+ }
54
+
55
+ undo() {
56
+
57
+ this.editor.signals.sceneGraphChanged.active = false;
58
+
59
+ for ( let i = this.cmdArray.length - 1; i >= 0; i -- ) {
60
+
61
+ this.cmdArray[ i ].undo();
62
+
63
+ }
64
+
65
+ this.editor.signals.sceneGraphChanged.active = true;
66
+ this.editor.signals.sceneGraphChanged.dispatch();
67
+
68
+ }
69
+
70
+ toJSON() {
71
+
72
+ const output = super.toJSON( this );
73
+
74
+ const cmds = [];
75
+ for ( let i = 0; i < this.cmdArray.length; i ++ ) {
76
+
77
+ cmds.push( this.cmdArray[ i ].toJSON() );
78
+
79
+ }
80
+
81
+ output.cmds = cmds;
82
+
83
+ return output;
84
+
85
+ }
86
+
87
+ fromJSON( json ) {
88
+
89
+ super.fromJSON( json );
90
+
91
+ const cmds = json.cmds;
92
+ for ( let i = 0; i < cmds.length; i ++ ) {
93
+
94
+ const cmd = new window[ cmds[ i ].type ](); // creates a new object of type "json.type"
95
+ cmd.fromJSON( cmds[ i ] );
96
+ this.cmdArray.push( cmd );
97
+
98
+ }
99
+
100
+ }
101
+
102
+ }
103
+
104
+ export { SetSceneCommand };
@@ -0,0 +1,80 @@
1
+ import { Command } from '../Command.js';
2
+
3
+ class SetScriptValueCommand extends Command {
4
+
5
+ /**
6
+ * @param {Editor} editor
7
+ * @param {THREE.Object3D|null} object
8
+ * @param {string} script
9
+ * @param {string} attributeName
10
+ * @param {string} newValue
11
+ * @constructor
12
+ */
13
+ constructor( editor, object = null, script = '', attributeName = '', newValue = null ) {
14
+
15
+ super( editor );
16
+
17
+ this.type = 'SetScriptValueCommand';
18
+ this.name = editor.strings.getKey( 'command/SetScriptValue' ) + ': ' + attributeName;
19
+ this.updatable = true;
20
+
21
+ this.object = object;
22
+ this.script = script;
23
+
24
+ this.attributeName = attributeName;
25
+ this.oldValue = ( script !== '' ) ? script[ this.attributeName ] : null;
26
+ this.newValue = newValue;
27
+
28
+ }
29
+
30
+ execute() {
31
+
32
+ this.script[ this.attributeName ] = this.newValue;
33
+
34
+ this.editor.signals.scriptChanged.dispatch( this.script );
35
+
36
+ }
37
+
38
+ undo() {
39
+
40
+ this.script[ this.attributeName ] = this.oldValue;
41
+
42
+ this.editor.signals.scriptChanged.dispatch( this.script );
43
+
44
+ }
45
+
46
+ update( cmd ) {
47
+
48
+ this.newValue = cmd.newValue;
49
+
50
+ }
51
+
52
+ toJSON() {
53
+
54
+ const output = super.toJSON( this );
55
+
56
+ output.objectUuid = this.object.uuid;
57
+ output.index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
58
+ output.attributeName = this.attributeName;
59
+ output.oldValue = this.oldValue;
60
+ output.newValue = this.newValue;
61
+
62
+ return output;
63
+
64
+ }
65
+
66
+ fromJSON( json ) {
67
+
68
+ super.fromJSON( json );
69
+
70
+ this.oldValue = json.oldValue;
71
+ this.newValue = json.newValue;
72
+ this.attributeName = json.attributeName;
73
+ this.object = this.editor.objectByUuid( json.objectUuid );
74
+ this.script = this.editor.scripts[ json.objectUuid ][ json.index ];
75
+
76
+ }
77
+
78
+ }
79
+
80
+ export { SetScriptValueCommand };
@@ -0,0 +1,73 @@
1
+ import { Command } from '../Command.js';
2
+
3
+ class SetShadowValueCommand extends Command {
4
+
5
+ /**
6
+ * @param {Editor} editor
7
+ * @param {THREE.Object3D|null} object
8
+ * @param {string} attributeName
9
+ * @param {number|string|boolean|Object|null} newValue
10
+ * @constructor
11
+ */
12
+ constructor( editor, object = null, attributeName = '', newValue = null ) {
13
+
14
+ super( editor );
15
+
16
+ this.type = 'SetShadowValueCommand';
17
+ this.name = editor.strings.getKey( 'command/SetShadowValue' ) + ': ' + attributeName;
18
+ this.updatable = true;
19
+
20
+ this.object = object;
21
+ this.attributeName = attributeName;
22
+ this.oldValue = ( object !== null ) ? object.shadow[ attributeName ] : null;
23
+ this.newValue = newValue;
24
+
25
+ }
26
+
27
+ execute() {
28
+
29
+ this.object.shadow[ this.attributeName ] = this.newValue;
30
+ this.editor.signals.objectChanged.dispatch( this.object );
31
+
32
+ }
33
+
34
+ undo() {
35
+
36
+ this.object.shadow[ this.attributeName ] = 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 { SetShadowValueCommand };
@@ -0,0 +1,143 @@
1
+ import { Command } from '../Command.js';
2
+
3
+ const VECTOR_KEYS = [ 'offset', 'repeat', 'center' ];
4
+
5
+ class SetTextureParametersCommand extends Command {
6
+
7
+ /**
8
+ * @param {Editor} editor
9
+ * @param {THREE.Texture} texture
10
+ * @param {Object} newParameters
11
+ * @constructor
12
+ */
13
+ constructor( editor, texture = null, newParameters = {} ) {
14
+
15
+ super( editor );
16
+
17
+ this.type = 'SetTextureParametersCommand';
18
+ this.name = editor.strings.getKey( 'command/SetTextureParameters' );
19
+
20
+ this.texture = texture;
21
+
22
+ this.oldParameters = ( texture !== null ) ? extractParameters( texture, newParameters ) : {};
23
+ this.newParameters = newParameters;
24
+
25
+ }
26
+
27
+ execute() {
28
+
29
+ applyParameters( this.texture, this.newParameters );
30
+ this.editor.signals.sceneGraphChanged.dispatch();
31
+
32
+ }
33
+
34
+ undo() {
35
+
36
+ applyParameters( this.texture, this.oldParameters );
37
+ this.editor.signals.sceneGraphChanged.dispatch();
38
+
39
+ }
40
+
41
+ toJSON() {
42
+
43
+ const output = super.toJSON( this );
44
+
45
+ output.textureUuid = this.texture.uuid;
46
+ output.oldParameters = this.oldParameters;
47
+ output.newParameters = this.newParameters;
48
+
49
+ return output;
50
+
51
+ }
52
+
53
+ fromJSON( json ) {
54
+
55
+ super.fromJSON( json );
56
+
57
+ this.texture = findTextureByUuid( this.editor, json.textureUuid );
58
+ this.oldParameters = json.oldParameters;
59
+ this.newParameters = json.newParameters;
60
+
61
+ }
62
+
63
+ }
64
+
65
+ function extractParameters( texture, reference ) {
66
+
67
+ const result = {};
68
+
69
+ for ( const key in reference ) {
70
+
71
+ const value = texture[ key ];
72
+
73
+ if ( VECTOR_KEYS.includes( key ) ) {
74
+
75
+ result[ key ] = { x: value.x, y: value.y };
76
+
77
+ } else {
78
+
79
+ result[ key ] = value;
80
+
81
+ }
82
+
83
+ }
84
+
85
+ return result;
86
+
87
+ }
88
+
89
+ function applyParameters( texture, parameters ) {
90
+
91
+ for ( const key in parameters ) {
92
+
93
+ const value = parameters[ key ];
94
+
95
+ if ( VECTOR_KEYS.includes( key ) ) {
96
+
97
+ texture[ key ].set( value.x, value.y );
98
+
99
+ } else {
100
+
101
+ texture[ key ] = value;
102
+
103
+ }
104
+
105
+ }
106
+
107
+ texture.needsUpdate = true;
108
+
109
+ }
110
+
111
+ function findTextureByUuid( editor, uuid ) {
112
+
113
+ let result = null;
114
+
115
+ editor.scene.traverse( ( object ) => {
116
+
117
+ if ( object.material === undefined ) return;
118
+
119
+ const materials = Array.isArray( object.material ) ? object.material : [ object.material ];
120
+
121
+ for ( const material of materials ) {
122
+
123
+ for ( const key in material ) {
124
+
125
+ const value = material[ key ];
126
+
127
+ if ( value && value.isTexture === true && value.uuid === uuid ) {
128
+
129
+ result = value;
130
+
131
+ }
132
+
133
+ }
134
+
135
+ }
136
+
137
+ } );
138
+
139
+ return result;
140
+
141
+ }
142
+
143
+ export { SetTextureParametersCommand };
@@ -0,0 +1,70 @@
1
+ import { Command } from '../Command.js';
2
+
3
+ class SetUuidCommand extends Command {
4
+
5
+ /**
6
+ * @param {Editor} editor
7
+ * @param {THREE.Object3D|null} object
8
+ * @param {string|null} newUuid
9
+ * @constructor
10
+ */
11
+ constructor( editor, object = null, newUuid = null ) {
12
+
13
+ super( editor );
14
+
15
+ this.type = 'SetUuidCommand';
16
+ this.name = editor.strings.getKey( 'command/SetUuid' );
17
+
18
+ this.object = object;
19
+
20
+ this.oldUuid = ( object !== null ) ? object.uuid : null;
21
+ this.newUuid = newUuid;
22
+
23
+ }
24
+
25
+ execute() {
26
+
27
+ this.object.uuid = this.newUuid;
28
+ this.editor.signals.objectChanged.dispatch( this.object );
29
+ this.editor.signals.sceneGraphChanged.dispatch();
30
+
31
+ }
32
+
33
+ undo() {
34
+
35
+ this.object.uuid = this.oldUuid;
36
+ this.editor.signals.objectChanged.dispatch( this.object );
37
+ this.editor.signals.sceneGraphChanged.dispatch();
38
+
39
+ }
40
+
41
+ toJSON() {
42
+
43
+ const output = super.toJSON( this );
44
+
45
+ output.oldUuid = this.oldUuid;
46
+ output.newUuid = this.newUuid;
47
+
48
+ return output;
49
+
50
+ }
51
+
52
+ fromJSON( json ) {
53
+
54
+ super.fromJSON( json );
55
+
56
+ this.oldUuid = json.oldUuid;
57
+ this.newUuid = json.newUuid;
58
+ this.object = this.editor.objectByUuid( json.oldUuid );
59
+
60
+ if ( this.object === undefined ) {
61
+
62
+ this.object = this.editor.objectByUuid( json.newUuid );
63
+
64
+ }
65
+
66
+ }
67
+
68
+ }
69
+
70
+ export { SetUuidCommand };