@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,321 @@
1
+ import * as Commands from './commands/Commands.js';
2
+
3
+ class History {
4
+
5
+ constructor( editor ) {
6
+
7
+ this.editor = editor;
8
+ this.undos = [];
9
+ this.redos = [];
10
+ this.lastCmdTime = Date.now();
11
+ this.idCounter = 0;
12
+
13
+ this.historyDisabled = false;
14
+ this.config = editor.config;
15
+
16
+ // signals
17
+
18
+ const scope = this;
19
+
20
+ this.editor.signals.startPlayer.add( function () {
21
+
22
+ scope.historyDisabled = true;
23
+
24
+ } );
25
+
26
+ this.editor.signals.stopPlayer.add( function () {
27
+
28
+ scope.historyDisabled = false;
29
+
30
+ } );
31
+
32
+ }
33
+
34
+ execute( cmd, optionalName ) {
35
+
36
+ const lastCmd = this.undos[ this.undos.length - 1 ];
37
+ const timeDifference = Date.now() - this.lastCmdTime;
38
+
39
+ const isUpdatableCmd = lastCmd &&
40
+ lastCmd.updatable &&
41
+ cmd.updatable &&
42
+ lastCmd.object === cmd.object &&
43
+ lastCmd.type === cmd.type &&
44
+ lastCmd.script === cmd.script &&
45
+ lastCmd.attributeName === cmd.attributeName;
46
+
47
+ if ( isUpdatableCmd && cmd.type === 'SetScriptValueCommand' ) {
48
+
49
+ // When the cmd.type is "SetScriptValueCommand" the timeDifference is ignored
50
+
51
+ lastCmd.update( cmd );
52
+ cmd = lastCmd;
53
+
54
+ } else if ( isUpdatableCmd && timeDifference < 500 ) {
55
+
56
+ lastCmd.update( cmd );
57
+ cmd = lastCmd;
58
+
59
+ } else {
60
+
61
+ // the command is not updatable and is added as a new part of the history
62
+
63
+ this.undos.push( cmd );
64
+ cmd.id = ++ this.idCounter;
65
+
66
+ }
67
+
68
+ cmd.name = ( optionalName !== undefined ) ? optionalName : cmd.name;
69
+ cmd.execute();
70
+ cmd.inMemory = true;
71
+
72
+ if ( this.config.getKey( 'settings/history' ) ) {
73
+
74
+ cmd.json = cmd.toJSON(); // serialize the cmd immediately after execution and append the json to the cmd
75
+
76
+ }
77
+
78
+ this.lastCmdTime = Date.now();
79
+
80
+ // clearing all the redo-commands
81
+
82
+ this.redos = [];
83
+ this.editor.signals.historyChanged.dispatch( cmd );
84
+
85
+ }
86
+
87
+ undo() {
88
+
89
+ if ( this.historyDisabled ) {
90
+
91
+ alert( this.editor.strings.getKey( 'prompt/history/forbid' ) );
92
+ return;
93
+
94
+ }
95
+
96
+ let cmd = undefined;
97
+
98
+ if ( this.undos.length > 0 ) {
99
+
100
+ cmd = this.undos.pop();
101
+
102
+ if ( cmd.inMemory === false ) {
103
+
104
+ cmd.fromJSON( cmd.json );
105
+
106
+ }
107
+
108
+ }
109
+
110
+ if ( cmd !== undefined ) {
111
+
112
+ cmd.undo();
113
+ this.redos.push( cmd );
114
+ this.editor.signals.historyChanged.dispatch( cmd );
115
+
116
+ }
117
+
118
+ return cmd;
119
+
120
+ }
121
+
122
+ redo() {
123
+
124
+ if ( this.historyDisabled ) {
125
+
126
+ alert( this.editor.strings.getKey( 'prompt/history/forbid' ) );
127
+ return;
128
+
129
+ }
130
+
131
+ let cmd = undefined;
132
+
133
+ if ( this.redos.length > 0 ) {
134
+
135
+ cmd = this.redos.pop();
136
+
137
+ if ( cmd.inMemory === false ) {
138
+
139
+ cmd.fromJSON( cmd.json );
140
+
141
+ }
142
+
143
+ }
144
+
145
+ if ( cmd !== undefined ) {
146
+
147
+ cmd.execute();
148
+ this.undos.push( cmd );
149
+ this.editor.signals.historyChanged.dispatch( cmd );
150
+
151
+ }
152
+
153
+ return cmd;
154
+
155
+ }
156
+
157
+ toJSON() {
158
+
159
+ const history = {};
160
+ history.undos = [];
161
+ history.redos = [];
162
+
163
+ if ( ! this.config.getKey( 'settings/history' ) ) {
164
+
165
+ return history;
166
+
167
+ }
168
+
169
+ // Append Undos to History
170
+
171
+ for ( let i = 0; i < this.undos.length; i ++ ) {
172
+
173
+ if ( this.undos[ i ].hasOwnProperty( 'json' ) ) {
174
+
175
+ history.undos.push( this.undos[ i ].json );
176
+
177
+ }
178
+
179
+ }
180
+
181
+ // Append Redos to History
182
+
183
+ for ( let i = 0; i < this.redos.length; i ++ ) {
184
+
185
+ if ( this.redos[ i ].hasOwnProperty( 'json' ) ) {
186
+
187
+ history.redos.push( this.redos[ i ].json );
188
+
189
+ }
190
+
191
+ }
192
+
193
+ return history;
194
+
195
+ }
196
+
197
+ fromJSON( json ) {
198
+
199
+ if ( json === undefined ) return;
200
+
201
+ for ( let i = 0; i < json.undos.length; i ++ ) {
202
+
203
+ const cmdJSON = json.undos[ i ];
204
+ const cmd = new Commands[ cmdJSON.type ]( this.editor ); // creates a new object of type "json.type"
205
+ cmd.json = cmdJSON;
206
+ cmd.id = cmdJSON.id;
207
+ cmd.name = cmdJSON.name;
208
+ this.undos.push( cmd );
209
+ this.idCounter = ( cmdJSON.id > this.idCounter ) ? cmdJSON.id : this.idCounter; // set last used idCounter
210
+
211
+ }
212
+
213
+ for ( let i = 0; i < json.redos.length; i ++ ) {
214
+
215
+ const cmdJSON = json.redos[ i ];
216
+ const cmd = new Commands[ cmdJSON.type ]( this.editor ); // creates a new object of type "json.type"
217
+ cmd.json = cmdJSON;
218
+ cmd.id = cmdJSON.id;
219
+ cmd.name = cmdJSON.name;
220
+ this.redos.push( cmd );
221
+ this.idCounter = ( cmdJSON.id > this.idCounter ) ? cmdJSON.id : this.idCounter; // set last used idCounter
222
+
223
+ }
224
+
225
+ // Select the last executed undo-command
226
+ this.editor.signals.historyChanged.dispatch( this.undos[ this.undos.length - 1 ] );
227
+
228
+ }
229
+
230
+ clear() {
231
+
232
+ this.undos = [];
233
+ this.redos = [];
234
+ this.idCounter = 0;
235
+
236
+ this.editor.signals.historyChanged.dispatch();
237
+
238
+ }
239
+
240
+ goToState( id ) {
241
+
242
+ if ( this.historyDisabled ) {
243
+
244
+ alert( this.editor.strings.getKey( 'prompt/history/forbid' ) );
245
+ return;
246
+
247
+ }
248
+
249
+ this.editor.signals.sceneGraphChanged.active = false;
250
+ this.editor.signals.historyChanged.active = false;
251
+
252
+ let cmd = this.undos.length > 0 ? this.undos[ this.undos.length - 1 ] : undefined; // next cmd to pop
253
+
254
+ if ( cmd === undefined || id > cmd.id ) {
255
+
256
+ cmd = this.redo();
257
+ while ( cmd !== undefined && id > cmd.id ) {
258
+
259
+ cmd = this.redo();
260
+
261
+ }
262
+
263
+ } else {
264
+
265
+ while ( true ) {
266
+
267
+ cmd = this.undos[ this.undos.length - 1 ]; // next cmd to pop
268
+
269
+ if ( cmd === undefined || id === cmd.id ) break;
270
+
271
+ this.undo();
272
+
273
+ }
274
+
275
+ }
276
+
277
+ this.editor.signals.sceneGraphChanged.active = true;
278
+ this.editor.signals.historyChanged.active = true;
279
+
280
+ this.editor.signals.sceneGraphChanged.dispatch();
281
+ this.editor.signals.historyChanged.dispatch( cmd );
282
+
283
+ }
284
+
285
+ enableSerialization( id ) {
286
+
287
+ /**
288
+ * because there might be commands in this.undos and this.redos
289
+ * which have not been serialized with .toJSON() we go back
290
+ * to the oldest command and redo one command after the other
291
+ * while also calling .toJSON() on them.
292
+ */
293
+
294
+ this.goToState( - 1 );
295
+
296
+ this.editor.signals.sceneGraphChanged.active = false;
297
+ this.editor.signals.historyChanged.active = false;
298
+
299
+ let cmd = this.redo();
300
+ while ( cmd !== undefined ) {
301
+
302
+ if ( ! cmd.hasOwnProperty( 'json' ) ) {
303
+
304
+ cmd.json = cmd.toJSON();
305
+
306
+ }
307
+
308
+ cmd = this.redo();
309
+
310
+ }
311
+
312
+ this.editor.signals.sceneGraphChanged.active = true;
313
+ this.editor.signals.historyChanged.active = true;
314
+
315
+ this.goToState( id );
316
+
317
+ }
318
+
319
+ }
320
+
321
+ export { History };