@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,70 @@
1
+ import { Command } from '../Command.js';
2
+
3
+ class SetGeometryValueCommand extends Command {
4
+
5
+ /**
6
+ * @param {Editor} editor
7
+ * @param {THREE.Object3D|null} [object=null]
8
+ * @param {string} [attributeName='']
9
+ * @param {number|string|boolean|Object|null} [newValue=null]
10
+ * @constructor
11
+ */
12
+ constructor( editor, object = null, attributeName = '', newValue = null ) {
13
+
14
+ super( editor );
15
+
16
+ this.type = 'SetGeometryValueCommand';
17
+ this.name = editor.strings.getKey( 'command/SetGeometryValue' ) + ': ' + attributeName;
18
+
19
+ this.object = object;
20
+ this.attributeName = attributeName;
21
+ this.oldValue = ( object !== null ) ? object.geometry[ attributeName ] : null;
22
+ this.newValue = newValue;
23
+
24
+ }
25
+
26
+ execute() {
27
+
28
+ this.object.geometry[ this.attributeName ] = this.newValue;
29
+ this.editor.signals.objectChanged.dispatch( this.object );
30
+ this.editor.signals.geometryChanged.dispatch();
31
+ this.editor.signals.sceneGraphChanged.dispatch();
32
+
33
+ }
34
+
35
+ undo() {
36
+
37
+ this.object.geometry[ this.attributeName ] = this.oldValue;
38
+ this.editor.signals.objectChanged.dispatch( this.object );
39
+ this.editor.signals.geometryChanged.dispatch();
40
+ this.editor.signals.sceneGraphChanged.dispatch();
41
+
42
+ }
43
+
44
+ toJSON() {
45
+
46
+ const output = super.toJSON( this );
47
+
48
+ output.objectUuid = this.object.uuid;
49
+ output.attributeName = this.attributeName;
50
+ output.oldValue = this.oldValue;
51
+ output.newValue = this.newValue;
52
+
53
+ return output;
54
+
55
+ }
56
+
57
+ fromJSON( json ) {
58
+
59
+ super.fromJSON( json );
60
+
61
+ this.object = this.editor.objectByUuid( json.objectUuid );
62
+ this.attributeName = json.attributeName;
63
+ this.oldValue = json.oldValue;
64
+ this.newValue = json.newValue;
65
+
66
+ }
67
+
68
+ }
69
+
70
+ export { SetGeometryValueCommand };
@@ -0,0 +1,87 @@
1
+ import { Command } from '../Command.js';
2
+
3
+ class SetMaterialColorCommand 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
+ * @param {number} [materialSlot=-1]
11
+ * @constructor
12
+ */
13
+ constructor( editor, object = null, attributeName = '', newValue = null, materialSlot = - 1 ) {
14
+
15
+ super( editor );
16
+
17
+ this.type = 'SetMaterialColorCommand';
18
+ this.name = editor.strings.getKey( 'command/SetMaterialColor' ) + ': ' + attributeName;
19
+ this.updatable = true;
20
+
21
+ this.object = object;
22
+ this.materialSlot = materialSlot;
23
+
24
+ const material = ( object !== null ) ? editor.getObjectMaterial( object, materialSlot ) : null;
25
+
26
+ this.oldValue = ( material !== null ) ? material[ attributeName ].getHex() : null;
27
+ this.newValue = newValue;
28
+
29
+ this.attributeName = attributeName;
30
+
31
+ }
32
+
33
+ execute() {
34
+
35
+ const material = this.editor.getObjectMaterial( this.object, this.materialSlot );
36
+
37
+ material[ this.attributeName ].setHex( this.newValue );
38
+
39
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
40
+
41
+ }
42
+
43
+ undo() {
44
+
45
+ const material = this.editor.getObjectMaterial( this.object, this.materialSlot );
46
+
47
+ material[ this.attributeName ].setHex( this.oldValue );
48
+
49
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
50
+
51
+ }
52
+
53
+ update( cmd ) {
54
+
55
+ this.newValue = cmd.newValue;
56
+
57
+ }
58
+
59
+ toJSON() {
60
+
61
+ const output = super.toJSON( this );
62
+
63
+ output.objectUuid = this.object.uuid;
64
+ output.attributeName = this.attributeName;
65
+ output.oldValue = this.oldValue;
66
+ output.newValue = this.newValue;
67
+ output.materialSlot = this.materialSlot;
68
+
69
+ return output;
70
+
71
+ }
72
+
73
+ fromJSON( json ) {
74
+
75
+ super.fromJSON( json );
76
+
77
+ this.object = this.editor.objectByUuid( json.objectUuid );
78
+ this.attributeName = json.attributeName;
79
+ this.oldValue = json.oldValue;
80
+ this.newValue = json.newValue;
81
+ this.materialSlot = json.materialSlot;
82
+
83
+ }
84
+
85
+ }
86
+
87
+ export { SetMaterialColorCommand };
@@ -0,0 +1,80 @@
1
+ import { Command } from '../Command.js';
2
+ import { ObjectLoader } from 'three';
3
+
4
+ class SetMaterialCommand extends Command {
5
+
6
+ /**
7
+ * @param {Editor} editor
8
+ * @param {THREE.Object3D|null} object
9
+ * @param {THREE.Material|null} newMaterial
10
+ * @param {number} [materialSlot=-1]
11
+ * @constructor
12
+ */
13
+ constructor( editor, object = null, newMaterial = null, materialSlot = - 1 ) {
14
+
15
+ super( editor );
16
+
17
+ this.type = 'SetMaterialCommand';
18
+ this.name = editor.strings.getKey( 'command/SetMaterial' );
19
+
20
+ this.object = object;
21
+ this.materialSlot = materialSlot;
22
+
23
+ this.oldMaterial = ( object !== null ) ? editor.getObjectMaterial( object, materialSlot ) : null;
24
+ this.newMaterial = newMaterial;
25
+
26
+ }
27
+
28
+ execute() {
29
+
30
+ this.editor.setObjectMaterial( this.object, this.materialSlot, this.newMaterial );
31
+
32
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
33
+
34
+ }
35
+
36
+ undo() {
37
+
38
+ this.editor.setObjectMaterial( this.object, this.materialSlot, this.oldMaterial );
39
+
40
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
41
+
42
+ }
43
+
44
+ toJSON() {
45
+
46
+ const output = super.toJSON( this );
47
+
48
+ output.objectUuid = this.object.uuid;
49
+ output.oldMaterial = this.oldMaterial.toJSON();
50
+ output.newMaterial = this.newMaterial.toJSON();
51
+ output.materialSlot = this.materialSlot;
52
+
53
+ return output;
54
+
55
+ }
56
+
57
+ fromJSON( json ) {
58
+
59
+ super.fromJSON( json );
60
+
61
+ this.object = this.editor.objectByUuid( json.objectUuid );
62
+ this.oldMaterial = parseMaterial( json.oldMaterial );
63
+ this.newMaterial = parseMaterial( json.newMaterial );
64
+ this.materialSlot = json.materialSlot;
65
+
66
+ function parseMaterial( json ) {
67
+
68
+ const loader = new ObjectLoader();
69
+ const images = loader.parseImages( json.images );
70
+ const textures = loader.parseTextures( json.textures, images );
71
+ const materials = loader.parseMaterials( [ json ], textures );
72
+ return materials[ json.uuid ];
73
+
74
+ }
75
+
76
+ }
77
+
78
+ }
79
+
80
+ export { SetMaterialCommand };
@@ -0,0 +1,144 @@
1
+ import { Command } from '../Command.js';
2
+ import { ObjectLoader } from 'three';
3
+
4
+ class SetMaterialMapCommand extends Command {
5
+
6
+ /**
7
+ * @param {Editor} editor
8
+ * @param {THREE.Object3D|null} [object=null]
9
+ * @param {string} [mapName='']
10
+ * @param {THREE.Texture|null} [newMap=null]
11
+ * @param {number} [materialSlot=-1]
12
+ * @constructor
13
+ */
14
+ constructor( editor, object = null, mapName = '', newMap = null, materialSlot = - 1 ) {
15
+
16
+ super( editor );
17
+
18
+ this.type = 'SetMaterialMapCommand';
19
+ this.name = editor.strings.getKey( 'command/SetMaterialMap' ) + ': ' + mapName;
20
+
21
+ this.object = object;
22
+ this.materialSlot = materialSlot;
23
+
24
+ const material = ( object !== null ) ? editor.getObjectMaterial( object, materialSlot ) : null;
25
+
26
+ this.oldMap = ( object !== null ) ? material[ mapName ] : undefined;
27
+ this.newMap = newMap;
28
+
29
+ this.mapName = mapName;
30
+
31
+ }
32
+
33
+ execute() {
34
+
35
+ if ( this.oldMap !== null && this.oldMap !== undefined ) this.oldMap.dispose();
36
+
37
+ const material = this.editor.getObjectMaterial( this.object, this.materialSlot );
38
+
39
+ material[ this.mapName ] = this.newMap;
40
+ material.needsUpdate = true;
41
+
42
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
43
+
44
+ }
45
+
46
+ undo() {
47
+
48
+ const material = this.editor.getObjectMaterial( this.object, this.materialSlot );
49
+
50
+ material[ this.mapName ] = this.oldMap;
51
+ material.needsUpdate = true;
52
+
53
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
54
+
55
+ }
56
+
57
+ toJSON() {
58
+
59
+ const output = super.toJSON( this );
60
+
61
+ output.objectUuid = this.object.uuid;
62
+ output.mapName = this.mapName;
63
+ output.newMap = serializeMap( this.newMap );
64
+ output.oldMap = serializeMap( this.oldMap );
65
+ output.materialSlot = this.materialSlot;
66
+
67
+ return output;
68
+
69
+ // serializes a map (THREE.Texture)
70
+
71
+ function serializeMap( map ) {
72
+
73
+ if ( map === null || map === undefined ) return null;
74
+
75
+ const meta = {
76
+ geometries: {},
77
+ materials: {},
78
+ textures: {},
79
+ images: {}
80
+ };
81
+
82
+ const json = map.toJSON( meta );
83
+ const images = extractFromCache( meta.images );
84
+ if ( images.length > 0 ) json.images = images;
85
+ json.sourceFile = map.sourceFile;
86
+
87
+ return json;
88
+
89
+ }
90
+
91
+ // Note: The function 'extractFromCache' is copied from Object3D.toJSON()
92
+
93
+ // extract data from the cache hash
94
+ // remove metadata on each item
95
+ // and return as array
96
+ function extractFromCache( cache ) {
97
+
98
+ const values = [];
99
+ for ( const key in cache ) {
100
+
101
+ const data = cache[ key ];
102
+ delete data.metadata;
103
+ values.push( data );
104
+
105
+ }
106
+
107
+ return values;
108
+
109
+ }
110
+
111
+ }
112
+
113
+ fromJSON( json ) {
114
+
115
+ super.fromJSON( json );
116
+
117
+ this.object = this.editor.objectByUuid( json.objectUuid );
118
+ this.mapName = json.mapName;
119
+ this.oldMap = parseTexture( json.oldMap );
120
+ this.newMap = parseTexture( json.newMap );
121
+ this.materialSlot = json.materialSlot;
122
+
123
+ function parseTexture( json ) {
124
+
125
+ let map = null;
126
+ if ( json !== null ) {
127
+
128
+ const loader = new ObjectLoader();
129
+ const images = loader.parseImages( json.images );
130
+ const textures = loader.parseTextures( [ json ], images );
131
+ map = textures[ json.uuid ];
132
+ map.sourceFile = json.sourceFile;
133
+
134
+ }
135
+
136
+ return map;
137
+
138
+ }
139
+
140
+ }
141
+
142
+ }
143
+
144
+ export { SetMaterialMapCommand };
@@ -0,0 +1,92 @@
1
+ import { Command } from '../Command.js';
2
+
3
+ class SetMaterialRangeCommand extends Command {
4
+
5
+ /**
6
+ * @param {Editor} editor
7
+ * @param {THREE.Object3D|null} [object=null]
8
+ * @param {string} [attributeName='']
9
+ * @param {number} [newMinValue=-Infinity]
10
+ * @param {number} [newMaxValue=Infinity]
11
+ * @param {number} [materialSlot=-1]
12
+ * @constructor
13
+ */
14
+ constructor( editor, object = null, attributeName = '', newMinValue = - Infinity, newMaxValue = Infinity, materialSlot = - 1 ) {
15
+
16
+ super( editor );
17
+
18
+ this.type = 'SetMaterialRangeCommand';
19
+ this.name = editor.strings.getKey( 'command/SetMaterialRange' ) + ': ' + attributeName;
20
+ this.updatable = true;
21
+
22
+ this.object = object;
23
+ this.materialSlot = materialSlot;
24
+
25
+ const material = ( object !== null ) ? editor.getObjectMaterial( object, materialSlot ) : null;
26
+
27
+ this.oldRange = ( material !== null && material[ attributeName ] !== undefined ) ? [ ... material[ attributeName ] ] : null;
28
+ this.newRange = [ newMinValue, newMaxValue ];
29
+
30
+ this.attributeName = attributeName;
31
+
32
+ }
33
+
34
+ execute() {
35
+
36
+ const material = this.editor.getObjectMaterial( this.object, this.materialSlot );
37
+
38
+ material[ this.attributeName ] = [ ...this.newRange ];
39
+ material.needsUpdate = true;
40
+
41
+ this.editor.signals.objectChanged.dispatch( this.object );
42
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
43
+
44
+ }
45
+
46
+ undo() {
47
+
48
+ const material = this.editor.getObjectMaterial( this.object, this.materialSlot );
49
+
50
+ material[ this.attributeName ] = [ ...this.oldRange ];
51
+ material.needsUpdate = true;
52
+
53
+ this.editor.signals.objectChanged.dispatch( this.object );
54
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
55
+
56
+ }
57
+
58
+ update( cmd ) {
59
+
60
+ this.newRange = [ ...cmd.newRange ];
61
+
62
+ }
63
+
64
+ toJSON() {
65
+
66
+ const output = super.toJSON( this );
67
+
68
+ output.objectUuid = this.object.uuid;
69
+ output.attributeName = this.attributeName;
70
+ output.oldRange = [ ...this.oldRange ];
71
+ output.newRange = [ ...this.newRange ];
72
+ output.materialSlot = this.materialSlot;
73
+
74
+ return output;
75
+
76
+ }
77
+
78
+ fromJSON( json ) {
79
+
80
+ super.fromJSON( json );
81
+
82
+ this.attributeName = json.attributeName;
83
+ this.oldRange = [ ...json.oldRange ];
84
+ this.newRange = [ ...json.newRange ];
85
+ this.object = this.editor.objectByUuid( json.objectUuid );
86
+ this.materialSlot = json.materialSlot;
87
+
88
+ }
89
+
90
+ }
91
+
92
+ export { SetMaterialRangeCommand };
@@ -0,0 +1,91 @@
1
+ import { Command } from '../Command.js';
2
+
3
+ class SetMaterialValueCommand extends Command {
4
+
5
+ /**
6
+ * @param {Editor} editor
7
+ * @param {THREE.Object3D|null} [object=null]
8
+ * @param {string} [attributeName='']
9
+ * @param {number|string|boolean|Object|null} [newValue=null]
10
+ * @param {number} [materialSlot=-1]
11
+ * @constructor
12
+ */
13
+ constructor( editor, object = null, attributeName = '', newValue = null, materialSlot = - 1 ) {
14
+
15
+ super( editor );
16
+
17
+ this.type = 'SetMaterialValueCommand';
18
+ this.name = editor.strings.getKey( 'command/SetMaterialValue' ) + ': ' + attributeName;
19
+ this.updatable = true;
20
+
21
+ this.object = object;
22
+ this.materialSlot = materialSlot;
23
+
24
+ const material = ( object !== null ) ? editor.getObjectMaterial( object, materialSlot ) : null;
25
+
26
+ this.oldValue = ( material !== null ) ? material[ attributeName ] : null;
27
+ this.newValue = newValue;
28
+
29
+ this.attributeName = attributeName;
30
+
31
+ }
32
+
33
+ execute() {
34
+
35
+ const material = this.editor.getObjectMaterial( this.object, this.materialSlot );
36
+
37
+ material[ this.attributeName ] = this.newValue;
38
+ material.needsUpdate = true;
39
+
40
+ this.editor.signals.objectChanged.dispatch( this.object );
41
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
42
+
43
+ }
44
+
45
+ undo() {
46
+
47
+ const material = this.editor.getObjectMaterial( this.object, this.materialSlot );
48
+
49
+ material[ this.attributeName ] = this.oldValue;
50
+ material.needsUpdate = true;
51
+
52
+ this.editor.signals.objectChanged.dispatch( this.object );
53
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
54
+
55
+ }
56
+
57
+ update( cmd ) {
58
+
59
+ this.newValue = cmd.newValue;
60
+
61
+ }
62
+
63
+ toJSON() {
64
+
65
+ const output = super.toJSON( this );
66
+
67
+ output.objectUuid = this.object.uuid;
68
+ output.attributeName = this.attributeName;
69
+ output.oldValue = this.oldValue;
70
+ output.newValue = this.newValue;
71
+ output.materialSlot = this.materialSlot;
72
+
73
+ return output;
74
+
75
+ }
76
+
77
+ fromJSON( json ) {
78
+
79
+ super.fromJSON( json );
80
+
81
+ this.attributeName = json.attributeName;
82
+ this.oldValue = json.oldValue;
83
+ this.newValue = json.newValue;
84
+ this.object = this.editor.objectByUuid( json.objectUuid );
85
+ this.materialSlot = json.materialSlot;
86
+
87
+ }
88
+
89
+ }
90
+
91
+ export { SetMaterialValueCommand };
@@ -0,0 +1,88 @@
1
+ import { Command } from '../Command.js';
2
+
3
+ class SetMaterialVectorCommand extends Command {
4
+
5
+ /**
6
+ *
7
+ * @param {Editor} editor
8
+ * @param {THREE.Object3D|null} [object=null]
9
+ * @param {string} [attributeName='']
10
+ * @param {THREE.Vector2|THREE.Vector3|THREE.Vector4|null} [newValue=null]
11
+ * @param {number} [materialSlot=-1]
12
+ * @constructor
13
+ */
14
+ constructor( editor, object = null, attributeName = '', newValue = null, materialSlot = - 1 ) {
15
+
16
+ super( editor );
17
+
18
+ this.type = 'SetMaterialVectorCommand';
19
+ this.name = editor.strings.getKey( 'command/SetMaterialVector' ) + ': ' + attributeName;
20
+ this.updatable = true;
21
+
22
+ this.object = object;
23
+ this.materialSlot = materialSlot;
24
+
25
+ const material = ( object !== null ) ? editor.getObjectMaterial( object, materialSlot ) : null;
26
+
27
+ this.oldValue = ( material !== null ) ? material[ attributeName ].toArray() : null;
28
+ this.newValue = newValue;
29
+
30
+ this.attributeName = attributeName;
31
+
32
+ }
33
+
34
+ execute() {
35
+
36
+ const material = this.editor.getObjectMaterial( this.object, this.materialSlot );
37
+
38
+ material[ this.attributeName ].fromArray( this.newValue );
39
+
40
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
41
+
42
+ }
43
+
44
+ undo() {
45
+
46
+ const material = this.editor.getObjectMaterial( this.object, this.materialSlot );
47
+
48
+ material[ this.attributeName ].fromArray( this.oldValue );
49
+
50
+ this.editor.signals.materialChanged.dispatch( this.object, this.materialSlot );
51
+
52
+ }
53
+
54
+ update( cmd ) {
55
+
56
+ this.newValue = cmd.newValue;
57
+
58
+ }
59
+
60
+ toJSON() {
61
+
62
+ const output = super.toJSON( this );
63
+
64
+ output.objectUuid = this.object.uuid;
65
+ output.attributeName = this.attributeName;
66
+ output.oldValue = this.oldValue;
67
+ output.newValue = this.newValue;
68
+ output.materialSlot = this.materialSlot;
69
+
70
+ return output;
71
+
72
+ }
73
+
74
+ fromJSON( json ) {
75
+
76
+ super.fromJSON( json );
77
+
78
+ this.object = this.editor.objectByUuid( json.objectUuid );
79
+ this.attributeName = json.attributeName;
80
+ this.oldValue = json.oldValue;
81
+ this.newValue = json.newValue;
82
+ this.materialSlot = json.materialSlot;
83
+
84
+ }
85
+
86
+ }
87
+
88
+ export { SetMaterialVectorCommand };