@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,643 @@
1
+ import * as THREE from 'three';
2
+
3
+ import { UIPanel, UIBreak, UIRow, UIColor, UISelect, UIText, UINumber, UIButton } from './libs/ui.js';
4
+ import { UIOutliner, UITexture } from './libs/ui.three.js';
5
+
6
+ function SidebarScene( editor ) {
7
+
8
+ const signals = editor.signals;
9
+ const strings = editor.strings;
10
+
11
+ const container = new UIPanel();
12
+ container.setBorderTop( '0' );
13
+ container.setPaddingTop( '20px' );
14
+
15
+ // outliner
16
+
17
+ const nodeStates = new WeakMap();
18
+
19
+ function buildOption( object, draggable ) {
20
+
21
+ const option = document.createElement( 'div' );
22
+ option.draggable = draggable;
23
+ option.innerHTML = buildHTML( object );
24
+ option.value = object.id;
25
+
26
+ // opener
27
+
28
+ if ( nodeStates.has( object ) ) {
29
+
30
+ const state = nodeStates.get( object );
31
+
32
+ const opener = document.createElement( 'span' );
33
+ opener.classList.add( 'opener' );
34
+
35
+ if ( object.children.length > 0 ) {
36
+
37
+ opener.classList.add( state ? 'open' : 'closed' );
38
+
39
+ }
40
+
41
+ opener.addEventListener( 'click', function () {
42
+
43
+ nodeStates.set( object, nodeStates.get( object ) === false ); // toggle
44
+ refreshUI();
45
+
46
+ } );
47
+
48
+ option.insertBefore( opener, option.firstChild );
49
+
50
+ }
51
+
52
+ return option;
53
+
54
+ }
55
+
56
+ function getMaterialName( material ) {
57
+
58
+ if ( Array.isArray( material ) ) {
59
+
60
+ const array = [];
61
+
62
+ for ( let i = 0; i < material.length; i ++ ) {
63
+
64
+ array.push( material[ i ].name );
65
+
66
+ }
67
+
68
+ return array.join( ',' );
69
+
70
+ }
71
+
72
+ return material.name;
73
+
74
+ }
75
+
76
+ function escapeHTML( html ) {
77
+
78
+ return html
79
+ .replace( /&/g, '&amp;' )
80
+ .replace( /"/g, '&quot;' )
81
+ .replace( /'/g, '&#39;' )
82
+ .replace( /</g, '&lt;' )
83
+ .replace( />/g, '&gt;' );
84
+
85
+ }
86
+
87
+ function getObjectType( object ) {
88
+
89
+ if ( object.isScene ) return 'Scene';
90
+ if ( object.isCamera ) return 'Camera';
91
+ if ( object.isLight ) return 'Light';
92
+ if ( object.isMesh ) return 'Mesh';
93
+ if ( object.isLine ) return 'Line';
94
+ if ( object.isPoints ) return 'Points';
95
+
96
+ return 'Object3D';
97
+
98
+ }
99
+
100
+ function buildHTML( object ) {
101
+
102
+ let html = `<span class="type ${ getObjectType( object ) }"></span> ${ escapeHTML( object.name ) }`;
103
+
104
+ if ( object.isMesh ) {
105
+
106
+ const geometry = object.geometry;
107
+ const material = object.material;
108
+
109
+ html += ` <span class="type Geometry"></span> ${ escapeHTML( geometry.name ) }`;
110
+ html += ` <span class="type Material"></span> ${ escapeHTML( getMaterialName( material ) ) }`;
111
+
112
+ }
113
+
114
+ html += getScript( object.uuid );
115
+
116
+ return html;
117
+
118
+ }
119
+
120
+ function getScript( uuid ) {
121
+
122
+ if ( editor.scripts[ uuid ] === undefined ) return '';
123
+
124
+ if ( editor.scripts[ uuid ].length === 0 ) return '';
125
+
126
+ return ' <span class="type Script"></span>';
127
+
128
+ }
129
+
130
+ let ignoreObjectSelectedSignal = false;
131
+
132
+ const outliner = new UIOutliner( editor );
133
+ outliner.setId( 'outliner' );
134
+ outliner.onChange( function () {
135
+
136
+ ignoreObjectSelectedSignal = true;
137
+
138
+ const multi = outliner.selectedValues && outliner.selectedValues.length > 1;
139
+ if ( multi ) {
140
+
141
+ const objects = [];
142
+ for ( const id of outliner.selectedValues ) {
143
+
144
+ const o = editor.scene.getObjectById( parseInt( id ) );
145
+ if ( o ) objects.push( o );
146
+
147
+ }
148
+ editor.selectMultiple( objects );
149
+
150
+ } else {
151
+
152
+ const v = outliner.getValue();
153
+ if ( v !== null ) editor.selectById( parseInt( v ) );
154
+ else editor.selectMultiple( [] );
155
+
156
+ }
157
+
158
+ ignoreObjectSelectedSignal = false;
159
+
160
+ } );
161
+ outliner.onDblClick( function () {
162
+
163
+ editor.focusById( parseInt( outliner.getValue() ) );
164
+
165
+ } );
166
+ container.add( outliner );
167
+
168
+ const selectionActions = new UIRow();
169
+ selectionActions.setPaddingTop( '4px' );
170
+ const mergeGroupBtn = new UIButton( 'Group' );
171
+ mergeGroupBtn.setMarginRight( '4px' );
172
+ mergeGroupBtn.onClick( function () {
173
+
174
+ const group = editor.mergeSelectionIntoGroup();
175
+ if ( group ) refreshUI();
176
+
177
+ } );
178
+ const ungroupBtn = new UIButton( 'Ungroup' );
179
+ ungroupBtn.onClick( function () {
180
+
181
+ editor.ungroupBySelection();
182
+ refreshUI();
183
+
184
+ } );
185
+ selectionActions.add( mergeGroupBtn );
186
+ selectionActions.add( ungroupBtn );
187
+ container.add( selectionActions );
188
+
189
+ container.add( new UIBreak() );
190
+
191
+ // background
192
+
193
+ const backgroundRow = new UIRow();
194
+
195
+ const backgroundType = new UISelect().setOptions( {
196
+
197
+ 'Default': 'Default',
198
+ 'Color': 'Color',
199
+ 'Texture': 'Texture',
200
+ 'Equirectangular': 'Equirect'
201
+
202
+ } ).setWidth( '150px' );
203
+ backgroundType.setValue( 'Default' );
204
+ backgroundType.onChange( function () {
205
+
206
+ onBackgroundChanged();
207
+ refreshBackgroundUI();
208
+
209
+ } );
210
+
211
+ backgroundRow.add( new UIText( strings.getKey( 'sidebar/scene/background' ) ).setClass( 'Label' ) );
212
+ backgroundRow.add( backgroundType );
213
+
214
+ const backgroundColor = new UIColor().setValue( '#000000' ).setMarginLeft( '8px' ).onInput( onBackgroundChanged );
215
+ backgroundRow.add( backgroundColor );
216
+
217
+ const backgroundTexture = new UITexture( editor ).setMarginLeft( '8px' ).onChange( onBackgroundChanged );
218
+ backgroundTexture.setDisplay( 'none' );
219
+ backgroundRow.add( backgroundTexture );
220
+
221
+ const backgroundEquirectangularTexture = new UITexture( editor ).setMarginLeft( '8px' ).onChange( onBackgroundChanged );
222
+ backgroundEquirectangularTexture.setDisplay( 'none' );
223
+ backgroundRow.add( backgroundEquirectangularTexture );
224
+
225
+ const backgroundColorSpaceRow = new UIRow();
226
+ backgroundColorSpaceRow.setDisplay( 'none' );
227
+ backgroundColorSpaceRow.setMarginLeft( '120px' );
228
+
229
+ const backgroundColorSpace = new UISelect().setOptions( {
230
+
231
+ [ THREE.NoColorSpace ]: 'No Color Space',
232
+ [ THREE.LinearSRGBColorSpace ]: 'srgb-linear',
233
+ [ THREE.SRGBColorSpace ]: 'srgb',
234
+
235
+ } ).setWidth( '150px' );
236
+ backgroundColorSpace.setValue( THREE.NoColorSpace );
237
+ backgroundColorSpace.onChange( onBackgroundChanged );
238
+ backgroundColorSpaceRow.add( backgroundColorSpace );
239
+
240
+ container.add( backgroundRow );
241
+ container.add( backgroundColorSpaceRow );
242
+
243
+ const backgroundEquirectRow = new UIRow();
244
+ backgroundEquirectRow.setDisplay( 'none' );
245
+ backgroundEquirectRow.setMarginLeft( '120px' );
246
+
247
+ const backgroundBlurriness = new UINumber( 0 ).setWidth( '40px' ).setRange( 0, 1 ).onChange( onBackgroundChanged );
248
+ backgroundEquirectRow.add( backgroundBlurriness );
249
+
250
+ const backgroundIntensity = new UINumber( 1 ).setWidth( '40px' ).setRange( 0, Infinity ).onChange( onBackgroundChanged );
251
+ backgroundEquirectRow.add( backgroundIntensity );
252
+
253
+ const backgroundRotation = new UINumber( 0 ).setWidth( '40px' ).setRange( - 180, 180 ).setStep( 10 ).setNudge( 0.1 ).setUnit( '°' ).onChange( onBackgroundChanged );
254
+ backgroundEquirectRow.add( backgroundRotation );
255
+
256
+ container.add( backgroundEquirectRow );
257
+
258
+ function onBackgroundChanged() {
259
+
260
+ signals.sceneBackgroundChanged.dispatch(
261
+ backgroundType.getValue(),
262
+ backgroundColor.getHexValue(),
263
+ backgroundTexture.getValue(),
264
+ backgroundEquirectangularTexture.getValue(),
265
+ backgroundColorSpace.getValue(),
266
+ backgroundBlurriness.getValue(),
267
+ backgroundIntensity.getValue(),
268
+ backgroundRotation.getValue()
269
+ );
270
+
271
+ }
272
+
273
+ function refreshBackgroundUI() {
274
+
275
+ const type = backgroundType.getValue();
276
+
277
+ backgroundType.setWidth( type === 'Default' ? '150px' : '110px' );
278
+ backgroundColor.setDisplay( type === 'Color' ? '' : 'none' );
279
+ backgroundTexture.setDisplay( type === 'Texture' ? '' : 'none' );
280
+ backgroundEquirectangularTexture.setDisplay( type === 'Equirectangular' ? '' : 'none' );
281
+ backgroundEquirectRow.setDisplay( type === 'Equirectangular' ? '' : 'none' );
282
+
283
+ if ( type === 'Texture' || type === 'Equirectangular' ) {
284
+
285
+ backgroundColorSpaceRow.setDisplay( '' );
286
+
287
+ } else {
288
+
289
+ backgroundColorSpaceRow.setDisplay( 'none' );
290
+
291
+ }
292
+
293
+ }
294
+
295
+ // environment
296
+
297
+ const environmentRow = new UIRow();
298
+
299
+ const environmentType = new UISelect().setOptions( {
300
+
301
+ 'Default': 'Default',
302
+ 'Equirectangular': 'Equirect',
303
+ 'None': 'None'
304
+
305
+ } ).setWidth( '150px' );
306
+ environmentType.setValue( 'Default' );
307
+ environmentType.onChange( function () {
308
+
309
+ onEnvironmentChanged();
310
+ refreshEnvironmentUI();
311
+
312
+ } );
313
+
314
+ environmentRow.add( new UIText( strings.getKey( 'sidebar/scene/environment' ) ).setClass( 'Label' ) );
315
+ environmentRow.add( environmentType );
316
+
317
+ const environmentEquirectangularTexture = new UITexture( editor ).setMarginLeft( '8px' ).onChange( onEnvironmentChanged );
318
+ environmentEquirectangularTexture.setDisplay( 'none' );
319
+ environmentRow.add( environmentEquirectangularTexture );
320
+
321
+ container.add( environmentRow );
322
+
323
+ function onEnvironmentChanged() {
324
+
325
+ signals.sceneEnvironmentChanged.dispatch(
326
+ environmentType.getValue(),
327
+ environmentEquirectangularTexture.getValue()
328
+ );
329
+
330
+ }
331
+
332
+ function refreshEnvironmentUI() {
333
+
334
+ const type = environmentType.getValue();
335
+
336
+ environmentType.setWidth( type !== 'Equirectangular' ? '150px' : '110px' );
337
+ environmentEquirectangularTexture.setDisplay( type === 'Equirectangular' ? '' : 'none' );
338
+
339
+ }
340
+
341
+ // fog
342
+
343
+ function onFogChanged() {
344
+
345
+ signals.sceneFogChanged.dispatch(
346
+ fogType.getValue(),
347
+ fogColor.getHexValue(),
348
+ fogNear.getValue(),
349
+ fogFar.getValue(),
350
+ fogDensity.getValue()
351
+ );
352
+
353
+ }
354
+
355
+ function onFogSettingsChanged() {
356
+
357
+ signals.sceneFogSettingsChanged.dispatch(
358
+ fogType.getValue(),
359
+ fogColor.getHexValue(),
360
+ fogNear.getValue(),
361
+ fogFar.getValue(),
362
+ fogDensity.getValue()
363
+ );
364
+
365
+ }
366
+
367
+ const fogTypeRow = new UIRow();
368
+ const fogType = new UISelect().setOptions( {
369
+
370
+ 'None': 'None',
371
+ 'Fog': 'Linear',
372
+ 'FogExp2': 'Exponential'
373
+
374
+ } ).setWidth( '150px' );
375
+ fogType.onChange( function () {
376
+
377
+ onFogChanged();
378
+ refreshFogUI();
379
+
380
+ } );
381
+
382
+ fogTypeRow.add( new UIText( strings.getKey( 'sidebar/scene/fog' ) ).setClass( 'Label' ) );
383
+ fogTypeRow.add( fogType );
384
+
385
+ container.add( fogTypeRow );
386
+
387
+ // fog color
388
+
389
+ const fogPropertiesRow = new UIRow();
390
+ fogPropertiesRow.setDisplay( 'none' );
391
+ fogPropertiesRow.setMarginLeft( '120px' );
392
+ container.add( fogPropertiesRow );
393
+
394
+ const fogColor = new UIColor().setValue( '#aaaaaa' );
395
+ fogColor.onInput( onFogSettingsChanged );
396
+ fogPropertiesRow.add( fogColor );
397
+
398
+ // fog near
399
+
400
+ const fogNear = new UINumber( 0.1 ).setWidth( '40px' ).setRange( 0, Infinity ).onChange( onFogSettingsChanged );
401
+ fogPropertiesRow.add( fogNear );
402
+
403
+ // fog far
404
+
405
+ const fogFar = new UINumber( 50 ).setWidth( '40px' ).setRange( 0, Infinity ).onChange( onFogSettingsChanged );
406
+ fogPropertiesRow.add( fogFar );
407
+
408
+ // fog density
409
+
410
+ const fogDensity = new UINumber( 0.05 ).setWidth( '40px' ).setRange( 0, 0.1 ).setStep( 0.001 ).setPrecision( 3 ).onChange( onFogSettingsChanged );
411
+ fogPropertiesRow.add( fogDensity );
412
+
413
+ //
414
+
415
+ function refreshUI() {
416
+
417
+ const camera = editor.camera;
418
+ const scene = editor.scene;
419
+
420
+ const options = [];
421
+
422
+ options.push( buildOption( camera, false ) );
423
+ options.push( buildOption( scene, false ) );
424
+
425
+ ( function addObjects( objects, pad ) {
426
+
427
+ for ( let i = 0, l = objects.length; i < l; i ++ ) {
428
+
429
+ const object = objects[ i ];
430
+
431
+ if ( nodeStates.has( object ) === false ) {
432
+
433
+ nodeStates.set( object, false );
434
+
435
+ }
436
+
437
+ const option = buildOption( object, true );
438
+ option.style.paddingLeft = ( pad * 18 ) + 'px';
439
+ options.push( option );
440
+
441
+ if ( nodeStates.get( object ) === true ) {
442
+
443
+ addObjects( object.children, pad + 1 );
444
+
445
+ }
446
+
447
+ }
448
+
449
+ } )( scene.children, 0 );
450
+
451
+ outliner.setOptions( options );
452
+
453
+ if ( editor.selected !== null ) {
454
+
455
+ outliner.setValue( editor.selected.id );
456
+
457
+ }
458
+
459
+ backgroundType.setValue( editor.backgroundType );
460
+
461
+ switch ( editor.backgroundType ) {
462
+
463
+ case 'Color':
464
+ backgroundColor.setHexValue( scene.background.getHex() );
465
+ break;
466
+
467
+ case 'Texture':
468
+ backgroundTexture.setValue( scene.background );
469
+ backgroundColorSpace.setValue( scene.background.colorSpace );
470
+ break;
471
+
472
+ case 'Equirectangular':
473
+ backgroundEquirectangularTexture.setValue( scene.background );
474
+ backgroundBlurriness.setValue( scene.backgroundBlurriness );
475
+ backgroundIntensity.setValue( scene.backgroundIntensity );
476
+ backgroundColorSpace.setValue( scene.background.colorSpace );
477
+ break;
478
+
479
+ default:
480
+ backgroundTexture.setValue( null );
481
+ backgroundEquirectangularTexture.setValue( null );
482
+ backgroundColorSpace.setValue( THREE.NoColorSpace );
483
+
484
+ }
485
+
486
+ environmentType.setValue( editor.environmentType );
487
+
488
+ if ( editor.environmentType === 'Equirectangular' ) {
489
+
490
+ environmentEquirectangularTexture.setValue( scene.environment );
491
+
492
+ } else {
493
+
494
+ environmentEquirectangularTexture.setValue( null );
495
+
496
+ }
497
+
498
+ if ( scene.fog ) {
499
+
500
+ fogColor.setHexValue( scene.fog.color.getHex() );
501
+
502
+ if ( scene.fog.isFog ) {
503
+
504
+ fogType.setValue( 'Fog' );
505
+ fogNear.setValue( scene.fog.near );
506
+ fogFar.setValue( scene.fog.far );
507
+
508
+ } else if ( scene.fog.isFogExp2 ) {
509
+
510
+ fogType.setValue( 'FogExp2' );
511
+ fogDensity.setValue( scene.fog.density );
512
+
513
+ }
514
+
515
+ } else {
516
+
517
+ fogType.setValue( 'None' );
518
+
519
+ }
520
+
521
+ refreshBackgroundUI();
522
+ refreshEnvironmentUI();
523
+ refreshFogUI();
524
+
525
+ }
526
+
527
+ function refreshFogUI() {
528
+
529
+ const type = fogType.getValue();
530
+
531
+ fogPropertiesRow.setDisplay( type === 'None' ? 'none' : '' );
532
+ fogNear.setDisplay( type === 'Fog' ? '' : 'none' );
533
+ fogFar.setDisplay( type === 'Fog' ? '' : 'none' );
534
+ fogDensity.setDisplay( type === 'FogExp2' ? '' : 'none' );
535
+
536
+ }
537
+
538
+ refreshUI();
539
+
540
+ // events
541
+
542
+ signals.editorCleared.add( refreshUI );
543
+
544
+ signals.sceneGraphChanged.add( refreshUI );
545
+
546
+ signals.cameraResetted.add( refreshUI );
547
+
548
+ signals.objectChanged.add( function ( object ) {
549
+
550
+ const options = outliner.options;
551
+
552
+ for ( let i = 0; i < options.length; i ++ ) {
553
+
554
+ const option = options[ i ];
555
+
556
+ if ( option.value === object.id ) {
557
+
558
+ const openerElement = option.querySelector( ':scope > .opener' );
559
+
560
+ option.innerHTML = buildHTML( object );
561
+
562
+ if ( openerElement !== null ) option.insertBefore( openerElement, option.firstChild );
563
+
564
+ return;
565
+
566
+ }
567
+
568
+ }
569
+
570
+ } );
571
+
572
+ signals.scriptAdded.add( function () {
573
+
574
+ if ( editor.selected !== null ) signals.objectChanged.dispatch( editor.selected );
575
+
576
+ } );
577
+
578
+ signals.scriptRemoved.add( function () {
579
+
580
+ if ( editor.selected !== null ) signals.objectChanged.dispatch( editor.selected );
581
+
582
+ } );
583
+
584
+
585
+ signals.objectSelected.add( function ( object ) {
586
+
587
+ if ( ignoreObjectSelectedSignal === true ) return;
588
+
589
+ if ( object !== null && object.parent !== null ) {
590
+
591
+ let needsRefresh = false;
592
+ let parent = object.parent;
593
+
594
+ while ( parent !== editor.scene ) {
595
+
596
+ if ( nodeStates.get( parent ) !== true ) {
597
+
598
+ nodeStates.set( parent, true );
599
+ needsRefresh = true;
600
+
601
+ }
602
+
603
+ parent = parent.parent;
604
+
605
+ }
606
+
607
+ if ( needsRefresh ) refreshUI();
608
+
609
+ outliner.setValue( object.id );
610
+
611
+ } else {
612
+
613
+ outliner.setValue( null );
614
+
615
+ }
616
+
617
+ } );
618
+
619
+ signals.objectMultiSelected.add( function ( objects ) {
620
+
621
+ if ( ignoreObjectSelectedSignal ) return;
622
+ if ( ! objects || objects.length <= 1 ) return; // single-select handled above
623
+ const ids = objects.map( o => o.id );
624
+ outliner.setMultiValue( ids );
625
+
626
+ } );
627
+
628
+ signals.sceneBackgroundChanged.add( function () {
629
+
630
+ if ( environmentType.getValue() === 'Background' ) {
631
+
632
+ onEnvironmentChanged();
633
+ refreshEnvironmentUI();
634
+
635
+ }
636
+
637
+ } );
638
+
639
+ return container;
640
+
641
+ }
642
+
643
+ export { SidebarScene };