@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,471 @@
1
+ import * as THREE from 'three';
2
+
3
+ import { UIPanel, UIRow, UIText, UIInput, UIButton, UISpan, UITextArea, UINumber, UIDiv, UIBreak } from './libs/ui.js';
4
+
5
+ import { SetGeometryValueCommand } from './commands/SetGeometryValueCommand.js';
6
+
7
+ import { SidebarGeometryBufferGeometry } from './Sidebar.Geometry.BufferGeometry.js';
8
+ import { SidebarGeometryModifiers } from './Sidebar.Geometry.Modifiers.js';
9
+
10
+ import { GeometryParametersPanel as BoxPanel } from './Sidebar.Geometry.BoxGeometry.js';
11
+ import { GeometryParametersPanel as CapsulePanel } from './Sidebar.Geometry.CapsuleGeometry.js';
12
+ import { GeometryParametersPanel as CirclePanel } from './Sidebar.Geometry.CircleGeometry.js';
13
+ import { GeometryParametersPanel as CylinderPanel } from './Sidebar.Geometry.CylinderGeometry.js';
14
+ import { GeometryParametersPanel as DodecahedronPanel } from './Sidebar.Geometry.DodecahedronGeometry.js';
15
+ import { GeometryParametersPanel as ExtrudePanel } from './Sidebar.Geometry.ExtrudeGeometry.js';
16
+ import { GeometryParametersPanel as IcosahedronPanel } from './Sidebar.Geometry.IcosahedronGeometry.js';
17
+ import { GeometryParametersPanel as LathePanel } from './Sidebar.Geometry.LatheGeometry.js';
18
+ import { GeometryParametersPanel as OctahedronPanel } from './Sidebar.Geometry.OctahedronGeometry.js';
19
+ import { GeometryParametersPanel as PlanePanel } from './Sidebar.Geometry.PlaneGeometry.js';
20
+ import { GeometryParametersPanel as RingPanel } from './Sidebar.Geometry.RingGeometry.js';
21
+ import { GeometryParametersPanel as ShapePanel } from './Sidebar.Geometry.ShapeGeometry.js';
22
+ import { GeometryParametersPanel as SpherePanel } from './Sidebar.Geometry.SphereGeometry.js';
23
+ import { GeometryParametersPanel as TetrahedronPanel } from './Sidebar.Geometry.TetrahedronGeometry.js';
24
+ import { GeometryParametersPanel as TextPanel } from './Sidebar.Geometry.TextGeometry.js';
25
+ import { GeometryParametersPanel as TorusPanel } from './Sidebar.Geometry.TorusGeometry.js';
26
+ import { GeometryParametersPanel as TorusKnotPanel } from './Sidebar.Geometry.TorusKnotGeometry.js';
27
+ import { GeometryParametersPanel as TubePanel } from './Sidebar.Geometry.TubeGeometry.js';
28
+
29
+ import { VertexNormalsHelper } from 'three/addons/helpers/VertexNormalsHelper.js';
30
+
31
+ const _GEOMETRY_PANELS = {
32
+ BoxGeometry: BoxPanel,
33
+ CapsuleGeometry: CapsulePanel,
34
+ CircleGeometry: CirclePanel,
35
+ CylinderGeometry: CylinderPanel,
36
+ DodecahedronGeometry: DodecahedronPanel,
37
+ ExtrudeGeometry: ExtrudePanel,
38
+ IcosahedronGeometry: IcosahedronPanel,
39
+ LatheGeometry: LathePanel,
40
+ OctahedronGeometry: OctahedronPanel,
41
+ PlaneGeometry: PlanePanel,
42
+ RingGeometry: RingPanel,
43
+ ShapeGeometry: ShapePanel,
44
+ SphereGeometry: SpherePanel,
45
+ TetrahedronGeometry: TetrahedronPanel,
46
+ TextGeometry: TextPanel,
47
+ TorusGeometry: TorusPanel,
48
+ TorusKnotGeometry: TorusKnotPanel,
49
+ TubeGeometry: TubePanel
50
+ };
51
+
52
+ function SidebarGeometry( editor ) {
53
+
54
+ const strings = editor.strings;
55
+
56
+ const signals = editor.signals;
57
+
58
+ const container = new UIPanel();
59
+ container.setBorderTop( '0' );
60
+ container.setDisplay( 'none' );
61
+ container.setPaddingTop( '20px' );
62
+
63
+ let currentGeometryType = null;
64
+
65
+ // Actions
66
+
67
+ /*
68
+ let objectActions = new UISelect().setPosition( 'absolute' ).setRight( '8px' ).setFontSize( '11px' );
69
+ objectActions.setOptions( {
70
+
71
+ 'Actions': 'Actions',
72
+ 'Center': 'Center',
73
+ 'Convert': 'Convert',
74
+ 'Flatten': 'Flatten'
75
+
76
+ } );
77
+ objectActions.onClick( function ( event ) {
78
+
79
+ event.stopPropagation(); // Avoid panel collapsing
80
+
81
+ } );
82
+ objectActions.onChange( function ( event ) {
83
+
84
+ let action = this.getValue();
85
+
86
+ let object = editor.selected;
87
+ let geometry = object.geometry;
88
+
89
+ if ( confirm( action + ' ' + object.name + '?' ) === false ) return;
90
+
91
+ switch ( action ) {
92
+
93
+ case 'Center':
94
+
95
+ let offset = geometry.center();
96
+
97
+ let newPosition = object.position.clone();
98
+ newPosition.sub( offset );
99
+ editor.execute( new SetPositionCommand( editor, object, newPosition ) );
100
+
101
+ editor.signals.geometryChanged.dispatch( object );
102
+
103
+ break;
104
+
105
+ case 'Flatten':
106
+
107
+ let newGeometry = geometry.clone();
108
+ newGeometry.uuid = geometry.uuid;
109
+ newGeometry.applyMatrix( object.matrix );
110
+
111
+ let cmds = [ new SetGeometryCommand( editor, object, newGeometry ),
112
+ new SetPositionCommand( editor, object, new THREE.Vector3( 0, 0, 0 ) ),
113
+ new SetRotationCommand( editor, object, new THREE.Euler( 0, 0, 0 ) ),
114
+ new SetScaleCommand( editor, object, new THREE.Vector3( 1, 1, 1 ) ) ];
115
+
116
+ editor.execute( new MultiCmdsCommand( editor, cmds ), 'Flatten Geometry' );
117
+
118
+ break;
119
+
120
+ }
121
+
122
+ this.setValue( 'Actions' );
123
+
124
+ } );
125
+ container.addStatic( objectActions );
126
+ */
127
+
128
+ // type
129
+
130
+ const geometryTypeRow = new UIRow();
131
+ const geometryType = new UIText();
132
+
133
+ geometryTypeRow.add( new UIText( strings.getKey( 'sidebar/geometry/type' ) ).setClass( 'Label' ) );
134
+ geometryTypeRow.add( geometryType );
135
+
136
+ container.add( geometryTypeRow );
137
+
138
+ // uuid
139
+
140
+ const geometryUUIDRow = new UIRow();
141
+ const geometryUUID = new UIInput().setWidth( '102px' ).setFontSize( '12px' ).setDisabled( true );
142
+ const geometryUUIDRenew = new UIButton( strings.getKey( 'sidebar/geometry/new' ) ).setMarginLeft( '7px' ).onClick( function () {
143
+
144
+ geometryUUID.setValue( THREE.MathUtils.generateUUID() );
145
+
146
+ editor.execute( new SetGeometryValueCommand( editor, editor.selected, 'uuid', geometryUUID.getValue() ) );
147
+
148
+ } );
149
+
150
+ geometryUUIDRow.add( new UIText( strings.getKey( 'sidebar/geometry/uuid' ) ).setClass( 'Label' ) );
151
+ geometryUUIDRow.add( geometryUUID );
152
+ geometryUUIDRow.add( geometryUUIDRenew );
153
+
154
+ container.add( geometryUUIDRow );
155
+
156
+ // name
157
+
158
+ const geometryNameRow = new UIRow();
159
+ const geometryName = new UIInput().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
160
+
161
+ editor.execute( new SetGeometryValueCommand( editor, editor.selected, 'name', geometryName.getValue() ) );
162
+
163
+ } );
164
+
165
+ geometryNameRow.add( new UIText( strings.getKey( 'sidebar/geometry/name' ) ).setClass( 'Label' ) );
166
+ geometryNameRow.add( geometryName );
167
+
168
+ container.add( geometryNameRow );
169
+
170
+ // parameters
171
+
172
+ const parameters = new UISpan();
173
+ container.add( parameters );
174
+
175
+ // buffergeometry
176
+
177
+ container.add( new SidebarGeometryBufferGeometry( editor ) );
178
+
179
+ // Size
180
+
181
+ const geometryBoundingBox = new UIText().setFontSize( '12px' );
182
+
183
+ const geometryBoundingBoxRow = new UIRow();
184
+ geometryBoundingBoxRow.add( new UIText( strings.getKey( 'sidebar/geometry/bounds' ) ).setClass( 'Label' ) );
185
+ geometryBoundingBoxRow.add( geometryBoundingBox );
186
+ container.add( geometryBoundingBoxRow );
187
+
188
+ // userData
189
+
190
+ const geometryUserDataRow = new UIRow();
191
+ const geometryUserData = new UITextArea().setValue( '{}' ).setWidth( '150px' ).setHeight( '40px' ).setFontSize( '12px' ).onChange( function () {
192
+
193
+ try {
194
+
195
+ const userData = JSON.parse( geometryUserData.getValue() );
196
+
197
+ if ( JSON.stringify( editor.selected.geometry.userData ) != JSON.stringify( userData ) ) {
198
+
199
+ editor.execute( new SetGeometryValueCommand( editor, editor.selected, 'userData', userData ) );
200
+
201
+ build();
202
+
203
+ }
204
+
205
+ } catch ( exception ) {
206
+
207
+ console.warn( exception );
208
+
209
+ }
210
+
211
+ } );
212
+ geometryUserData.onKeyUp( function () {
213
+
214
+ try {
215
+
216
+ JSON.parse( geometryUserData.getValue() );
217
+
218
+ geometryUserData.dom.classList.add( 'success' );
219
+ geometryUserData.dom.classList.remove( 'fail' );
220
+
221
+ } catch ( error ) {
222
+
223
+ geometryUserData.dom.classList.remove( 'success' );
224
+ geometryUserData.dom.classList.add( 'fail' );
225
+
226
+ }
227
+
228
+ } );
229
+
230
+ geometryUserDataRow.add( new UIText( strings.getKey( 'sidebar/geometry/userdata' ) ).setClass( 'Label' ) );
231
+ geometryUserDataRow.add( geometryUserData );
232
+
233
+ container.add( geometryUserDataRow );
234
+
235
+ // Helpers
236
+
237
+ const helpersRow = new UIRow().setMarginLeft( '120px' );
238
+ container.add( helpersRow );
239
+
240
+ const vertexNormalsButton = new UIButton( strings.getKey( 'sidebar/geometry/show_vertex_normals' ) );
241
+ vertexNormalsButton.onClick( function () {
242
+
243
+ const object = editor.selected;
244
+
245
+ if ( editor.helpers[ object.id ] === undefined ) {
246
+
247
+ editor.addHelper( object, new VertexNormalsHelper( object, vertexNormalsSize.getValue() ) );
248
+
249
+ } else {
250
+
251
+ editor.removeHelper( object );
252
+
253
+ }
254
+
255
+ signals.sceneGraphChanged.dispatch();
256
+
257
+ } );
258
+ helpersRow.add( vertexNormalsButton );
259
+
260
+ const vertexNormalsSize = new UINumber( 1 ).setWidth( '30px' ).setMarginLeft( '7px' ).setRange( 0, Infinity ).onChange( function () {
261
+
262
+ const object = editor.selected;
263
+ const helper = editor.helpers[ object.id ];
264
+
265
+ if ( helper !== undefined && helper.isVertexNormalsHelper === true ) {
266
+
267
+ helper.size = vertexNormalsSize.getValue();
268
+
269
+ signals.objectChanged.dispatch( object );
270
+
271
+ }
272
+
273
+ } );
274
+ helpersRow.add( vertexNormalsSize );
275
+
276
+ // Export JSON
277
+
278
+ const exportJson = new UIButton( strings.getKey( 'sidebar/geometry/export' ) );
279
+ exportJson.setMarginLeft( '120px' );
280
+ exportJson.onClick( function () {
281
+
282
+ const object = editor.selected;
283
+ const geometry = object.geometry;
284
+
285
+ let output = geometry.toJSON();
286
+
287
+ try {
288
+
289
+ output = JSON.stringify( output, null, '\t' );
290
+ output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
291
+
292
+ } catch ( e ) {
293
+
294
+ output = JSON.stringify( output );
295
+
296
+ }
297
+
298
+ editor.utils.save( new Blob( [ output ] ), `${ geometryName.getValue() || 'geometry' }.json` );
299
+
300
+ } );
301
+ container.add( exportJson );
302
+
303
+ // Morph Targets
304
+
305
+ const morphContainer = new UIDiv();
306
+ morphContainer.setMarginTop( '20px' );
307
+ morphContainer.setDisplay( 'none' );
308
+ container.add( morphContainer );
309
+
310
+ morphContainer.add( new UIText( strings.getKey( 'sidebar/geometry/morph' ) ).setTextTransform( 'uppercase' ) );
311
+ morphContainer.add( new UIBreak() );
312
+ morphContainer.add( new UIBreak() );
313
+
314
+ const morphList = new UIDiv();
315
+ morphContainer.add( morphList );
316
+
317
+ //
318
+
319
+ async function build() {
320
+
321
+ const object = editor.selected;
322
+
323
+ if ( object && object.geometry ) {
324
+
325
+ const geometry = object.geometry;
326
+
327
+ container.setDisplay( 'block' );
328
+
329
+ geometryType.setValue( geometry.type );
330
+
331
+ geometryUUID.setValue( geometry.uuid );
332
+ geometryName.setValue( geometry.name );
333
+
334
+ //
335
+
336
+ if ( currentGeometryType !== geometry.type ) {
337
+
338
+ parameters.clear();
339
+
340
+ if ( geometry.type === 'BufferGeometry' || geometry.type === 'InstancedBufferGeometry' ) {
341
+
342
+ parameters.add( new SidebarGeometryModifiers( editor, object ) );
343
+
344
+ } else {
345
+
346
+ const Panel = _GEOMETRY_PANELS[ geometry.type ];
347
+
348
+ if ( Panel !== undefined ) {
349
+
350
+ parameters.add( new Panel( editor, object ) );
351
+
352
+ }
353
+
354
+ }
355
+
356
+ currentGeometryType = geometry.type;
357
+
358
+ }
359
+
360
+ if ( geometry.boundingBox === null ) geometry.computeBoundingBox();
361
+
362
+ const boundingBox = geometry.boundingBox;
363
+ const x = Math.floor( ( boundingBox.max.x - boundingBox.min.x ) * 1000 ) / 1000;
364
+ const y = Math.floor( ( boundingBox.max.y - boundingBox.min.y ) * 1000 ) / 1000;
365
+ const z = Math.floor( ( boundingBox.max.z - boundingBox.min.z ) * 1000 ) / 1000;
366
+
367
+ geometryBoundingBox.setInnerHTML( `${x}<br/>${y}<br/>${z}` );
368
+
369
+ helpersRow.setDisplay( geometry.hasAttribute( 'normal' ) ? '' : 'none' );
370
+
371
+ geometryUserData.setValue( JSON.stringify( geometry.userData, null, ' ' ) );
372
+
373
+ //
374
+
375
+ const helper = editor.helpers[ object.id ];
376
+
377
+ if ( helper !== undefined && helper.isVertexNormalsHelper === true ) {
378
+
379
+ editor.removeHelper( object );
380
+ editor.addHelper( object, new VertexNormalsHelper( object, vertexNormalsSize.getValue() ) );
381
+
382
+ }
383
+
384
+ //
385
+
386
+ morphUIElements.length = 0;
387
+ morphList.clear();
388
+
389
+ if ( object.morphTargetInfluences ) {
390
+
391
+ const morphTargetDictionary = object.morphTargetDictionary;
392
+ const morphTargetInfluences = object.morphTargetInfluences;
393
+ const morphNames = Object.keys( morphTargetDictionary );
394
+
395
+ for ( let i = 0; i < morphNames.length; i ++ ) {
396
+
397
+ const name = morphNames[ i ];
398
+ morphList.add( new Morph( i, name, morphTargetInfluences ) );
399
+
400
+ }
401
+
402
+ morphContainer.setDisplay( '' );
403
+
404
+ } else {
405
+
406
+ morphContainer.setDisplay( 'none' );
407
+
408
+ }
409
+
410
+ }
411
+
412
+ }
413
+
414
+ const morphUIElements = [];
415
+
416
+ function Morph( index, name, morphTargetInfluences ) {
417
+
418
+ const container = new UIRow();
419
+
420
+ const morphName = new UIText( name ).setWidth( '200px' );
421
+ container.add( morphName );
422
+
423
+ const morphInfluence = new UINumber().setWidth( '60px' ).setRange( 0, 1 ).onChange( function updateMorphInfluence() {
424
+
425
+ morphTargetInfluences[ index ] = morphInfluence.getValue();
426
+ signals.objectChanged.dispatch( editor.selected );
427
+
428
+ } );
429
+ morphInfluence.setValue( morphTargetInfluences[ index ] );
430
+
431
+ container.add( morphInfluence );
432
+ morphUIElements.push( morphInfluence );
433
+
434
+ return container;
435
+
436
+ }
437
+
438
+
439
+ function refreshUI() {
440
+
441
+ const object = editor.selected;
442
+
443
+ if ( object !== null && object.morphTargetInfluences ) {
444
+
445
+ for ( let i = 0; i < morphUIElements.length; i ++ ) {
446
+
447
+ const element = morphUIElements[ i ];
448
+ element.setValue( object.morphTargetInfluences[ i ] );
449
+
450
+ }
451
+
452
+ }
453
+
454
+ }
455
+
456
+ signals.objectSelected.add( function () {
457
+
458
+ currentGeometryType = null;
459
+
460
+ build();
461
+
462
+ } );
463
+
464
+ signals.geometryChanged.add( build );
465
+ signals.morphTargetsUpdated.add( refreshUI );
466
+
467
+ return container;
468
+
469
+ }
470
+
471
+ export { SidebarGeometry };
@@ -0,0 +1,60 @@
1
+ import { UICheckbox, UIRow, UIText } from './libs/ui.js';
2
+ import { SetMaterialValueCommand } from './commands/SetMaterialValueCommand.js';
3
+
4
+ function SidebarMaterialBooleanProperty( editor, property, name ) {
5
+
6
+ const signals = editor.signals;
7
+
8
+ const container = new UIRow();
9
+ container.add( new UIText( name ).setClass( 'Label' ) );
10
+
11
+ const boolean = new UICheckbox().setLeft( '100px' ).onChange( onChange );
12
+ container.add( boolean );
13
+
14
+ let object = null;
15
+ let materialSlot = null;
16
+ let material = null;
17
+
18
+ function onChange() {
19
+
20
+ if ( material[ property ] !== boolean.getValue() ) {
21
+
22
+ editor.execute( new SetMaterialValueCommand( editor, object, property, boolean.getValue(), materialSlot ) );
23
+
24
+ }
25
+
26
+ }
27
+
28
+ function update( currentObject, currentMaterialSlot = 0 ) {
29
+
30
+ object = currentObject;
31
+ materialSlot = currentMaterialSlot;
32
+
33
+ if ( object === null ) return;
34
+ if ( object.material === undefined ) return;
35
+
36
+ material = editor.getObjectMaterial( object, materialSlot );
37
+
38
+ if ( property in material ) {
39
+
40
+ boolean.setValue( material[ property ] );
41
+ container.setDisplay( '' );
42
+
43
+ } else {
44
+
45
+ container.setDisplay( 'none' );
46
+
47
+ }
48
+
49
+ }
50
+
51
+ //
52
+
53
+ signals.objectSelected.add( update );
54
+ signals.materialChanged.add( update );
55
+
56
+ return container;
57
+
58
+ }
59
+
60
+ export { SidebarMaterialBooleanProperty };
@@ -0,0 +1,87 @@
1
+ import { UIColor, UINumber, UIRow, UIText } from './libs/ui.js';
2
+ import { SetMaterialColorCommand } from './commands/SetMaterialColorCommand.js';
3
+ import { SetMaterialValueCommand } from './commands/SetMaterialValueCommand.js';
4
+
5
+ function SidebarMaterialColorProperty( editor, property, name ) {
6
+
7
+ const signals = editor.signals;
8
+
9
+ const container = new UIRow();
10
+ container.add( new UIText( name ).setClass( 'Label' ) );
11
+
12
+ const color = new UIColor().onInput( onChange );
13
+ container.add( color );
14
+
15
+ let intensity;
16
+
17
+ if ( property === 'emissive' ) {
18
+
19
+ intensity = new UINumber( 1 ).setWidth( '30px' ).setRange( 0, Infinity ).onChange( onChange );
20
+ container.add( intensity );
21
+
22
+ }
23
+
24
+ let object = null;
25
+ let materialSlot = null;
26
+ let material = null;
27
+
28
+ function onChange() {
29
+
30
+ if ( material[ property ].getHex() !== color.getHexValue() ) {
31
+
32
+ editor.execute( new SetMaterialColorCommand( editor, object, property, color.getHexValue(), materialSlot ) );
33
+
34
+ }
35
+
36
+ if ( intensity !== undefined ) {
37
+
38
+ if ( material[ `${ property }Intensity` ] !== intensity.getValue() ) {
39
+
40
+ editor.execute( new SetMaterialValueCommand( editor, object, `${ property }Intensity`, intensity.getValue(), materialSlot ) );
41
+
42
+ }
43
+
44
+ }
45
+
46
+ }
47
+
48
+ function update( currentObject, currentMaterialSlot = 0 ) {
49
+
50
+ object = currentObject;
51
+ materialSlot = currentMaterialSlot;
52
+
53
+ if ( object === null ) return;
54
+ if ( object.material === undefined ) return;
55
+
56
+ material = editor.getObjectMaterial( object, materialSlot );
57
+
58
+ if ( property in material ) {
59
+
60
+ color.setHexValue( material[ property ].getHexString() );
61
+
62
+ if ( intensity !== undefined ) {
63
+
64
+ intensity.setValue( material[ `${ property }Intensity` ] );
65
+
66
+ }
67
+
68
+ container.setDisplay( '' );
69
+
70
+ } else {
71
+
72
+ container.setDisplay( 'none' );
73
+
74
+ }
75
+
76
+ }
77
+
78
+ //
79
+
80
+ signals.objectSelected.add( update );
81
+ signals.materialChanged.add( update );
82
+
83
+ return container;
84
+
85
+ }
86
+
87
+ export { SidebarMaterialColorProperty };
@@ -0,0 +1,62 @@
1
+ import { UIRow, UISelect, UIText } from './libs/ui.js';
2
+ import { SetMaterialValueCommand } from './commands/SetMaterialValueCommand.js';
3
+
4
+ function SidebarMaterialConstantProperty( editor, property, name, options ) {
5
+
6
+ const signals = editor.signals;
7
+
8
+ const container = new UIRow();
9
+ container.add( new UIText( name ).setClass( 'Label' ) );
10
+
11
+ const constant = new UISelect().setOptions( options ).onChange( onChange );
12
+ container.add( constant );
13
+
14
+ let object = null;
15
+ let materialSlot = null;
16
+ let material = null;
17
+
18
+ function onChange() {
19
+
20
+ const value = parseInt( constant.getValue() );
21
+
22
+ if ( material[ property ] !== value ) {
23
+
24
+ editor.execute( new SetMaterialValueCommand( editor, object, property, value, materialSlot ) );
25
+
26
+ }
27
+
28
+ }
29
+
30
+ function update( currentObject, currentMaterialSlot = 0 ) {
31
+
32
+ object = currentObject;
33
+ materialSlot = currentMaterialSlot;
34
+
35
+ if ( object === null ) return;
36
+ if ( object.material === undefined ) return;
37
+
38
+ material = editor.getObjectMaterial( object, materialSlot );
39
+
40
+ if ( property in material ) {
41
+
42
+ constant.setValue( material[ property ] );
43
+ container.setDisplay( '' );
44
+
45
+ } else {
46
+
47
+ container.setDisplay( 'none' );
48
+
49
+ }
50
+
51
+ }
52
+
53
+ //
54
+
55
+ signals.objectSelected.add( update );
56
+ signals.materialChanged.add( update );
57
+
58
+ return container;
59
+
60
+ }
61
+
62
+ export { SidebarMaterialConstantProperty };