entangled-worlds-orbiters-shared 1.0.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 (38) hide show
  1. package/README.md +75 -0
  2. package/package.json +49 -0
  3. package/public/config/textures.json +332 -0
  4. package/src/arrow-ui/BooleanController.js +31 -0
  5. package/src/arrow-ui/ColorController.js +108 -0
  6. package/src/arrow-ui/Controller.js +447 -0
  7. package/src/arrow-ui/FunctionController.js +27 -0
  8. package/src/arrow-ui/GUI.js +595 -0
  9. package/src/arrow-ui/NumberController.js +567 -0
  10. package/src/arrow-ui/OptionController.js +64 -0
  11. package/src/arrow-ui/StringController.js +41 -0
  12. package/src/arrow-ui/index.js +13 -0
  13. package/src/arrow-ui/lilGuiLoader.js +10 -0
  14. package/src/arrow-ui/utils/getColorFormat.js +75 -0
  15. package/src/arrow-ui/utils/injectStyles.js +10 -0
  16. package/src/arrow-ui/utils/normalizeColorString.js +29 -0
  17. package/src/config/index.js +8 -0
  18. package/src/config/textureConfig.js +299 -0
  19. package/src/core/index.js +3 -0
  20. package/src/core/lightFresnel.js +64 -0
  21. package/src/core/lights.js +43 -0
  22. package/src/index.js +8 -0
  23. package/src/loaders/bodyTextureLoader.js +39 -0
  24. package/src/loaders/cubeMapLoader.js +264 -0
  25. package/src/loaders/glbLoader.js +71 -0
  26. package/src/loaders/index.js +4 -0
  27. package/src/moons/index.js +3 -0
  28. package/src/moons/moonsGeneration.js +228 -0
  29. package/src/moons/moonsManager.js +64 -0
  30. package/src/utils/dispose.js +20 -0
  31. package/src/utils/index.js +3 -0
  32. package/src/utils/materials.js +31 -0
  33. package/src/world/cloudShell.js +89 -0
  34. package/src/world/index.js +6 -0
  35. package/src/world/worldGLB.js +7 -0
  36. package/src/world/worldManager.js +93 -0
  37. package/src/world/worldNormal.js +25 -0
  38. package/src/world/worldTexture.js +239 -0
@@ -0,0 +1,447 @@
1
+ /** @module Controller */
2
+
3
+ /**
4
+ * Base class for all controllers.
5
+ */
6
+ export default class Controller {
7
+
8
+ constructor( parent, object, property, className, elementType = 'div' ) {
9
+
10
+ /**
11
+ * The GUI that contains this controller.
12
+ * @type {GUI}
13
+ */
14
+ this.parent = parent;
15
+
16
+ /**
17
+ * The object this controller will modify.
18
+ * @type {object}
19
+ */
20
+ this.object = object;
21
+
22
+ /**
23
+ * The name of the property to control.
24
+ * @type {string}
25
+ */
26
+ this.property = property;
27
+
28
+ /**
29
+ * Used to determine if the controller is disabled.
30
+ * Use `controller.disable( true|false )` to modify this value.
31
+ * @type {boolean}
32
+ */
33
+ this._disabled = false;
34
+
35
+ /**
36
+ * Used to determine if the Controller is hidden.
37
+ * Use `controller.show()` or `controller.hide()` to change this.
38
+ * @type {boolean}
39
+ */
40
+ this._hidden = false;
41
+
42
+ /**
43
+ * The value of `object[ property ]` when the controller was created.
44
+ * @type {any}
45
+ */
46
+ this.initialValue = this.getValue();
47
+
48
+ /**
49
+ * The outermost container DOM element for this controller.
50
+ * @type {HTMLElement}
51
+ */
52
+ this.domElement = document.createElement( elementType );
53
+ this.domElement.classList.add( 'controller' );
54
+ this.domElement.classList.add( className );
55
+
56
+ /**
57
+ * The DOM element that contains the controller's name.
58
+ * @type {HTMLElement}
59
+ */
60
+ this.$name = document.createElement( 'div' );
61
+ this.$name.classList.add( 'name' );
62
+
63
+ Controller.nextNameID = Controller.nextNameID || 0;
64
+ this.$name.id = `lil-gui-name-${++Controller.nextNameID}`;
65
+
66
+ /**
67
+ * The DOM element that contains the controller's "widget" (which differs by controller type).
68
+ * @type {HTMLElement}
69
+ */
70
+ this.$widget = document.createElement( 'div' );
71
+ this.$widget.classList.add( 'widget' );
72
+
73
+ /**
74
+ * The DOM element that receives the disabled attribute when using disable().
75
+ * @type {HTMLElement}
76
+ */
77
+ this.$disable = this.$widget;
78
+
79
+ this.domElement.appendChild( this.$name );
80
+ this.domElement.appendChild( this.$widget );
81
+
82
+ // Don't fire global key events while typing in a controller
83
+ this.domElement.addEventListener( 'keydown', e => e.stopPropagation() );
84
+ this.domElement.addEventListener( 'keyup', e => e.stopPropagation() );
85
+
86
+ this.parent.children.push( this );
87
+ this.parent.controllers.push( this );
88
+
89
+ this.parent.$children.appendChild( this.domElement );
90
+
91
+ this._listenCallback = this._listenCallback.bind( this );
92
+
93
+ this.name( property );
94
+
95
+ }
96
+
97
+ /**
98
+ * Sets the name of the controller and its label in the GUI.
99
+ * @param {string} name
100
+ * @returns {this}
101
+ */
102
+ name( name ) {
103
+ /**
104
+ * The controller's name. Use `controller.name( 'Name' )` to modify this value.
105
+ * @type {string}
106
+ */
107
+ this._name = name;
108
+ this.$name.textContent = name;
109
+ return this;
110
+ }
111
+
112
+ /**
113
+ * Pass a function to be called whenever the value is modified by this controller.
114
+ * The function receives the new value as its first parameter. The value of `this` will be the
115
+ * controller.
116
+ *
117
+ * For function controllers, the `onChange` callback will be fired on click, after the function
118
+ * executes.
119
+ * @param {Function} callback
120
+ * @returns {this}
121
+ * @example
122
+ * const controller = gui.add( object, 'property' );
123
+ *
124
+ * controller.onChange( function( v ) {
125
+ * console.log( 'The value is now ' + v );
126
+ * console.assert( this === controller );
127
+ * } );
128
+ */
129
+ onChange( callback ) {
130
+ /**
131
+ * Used to access the function bound to `onChange` events. Don't modify this value directly.
132
+ * Use the `controller.onChange( callback )` method instead.
133
+ * @type {Function}
134
+ */
135
+ this._onChange = callback;
136
+ return this;
137
+ }
138
+
139
+ /**
140
+ * Calls the onChange methods of this controller and its parent GUI.
141
+ * @protected
142
+ */
143
+ _callOnChange() {
144
+
145
+ this.parent._callOnChange( this );
146
+
147
+ if ( this._onChange !== undefined ) {
148
+ this._onChange.call( this, this.getValue() );
149
+ }
150
+
151
+ this._changed = true;
152
+
153
+ }
154
+
155
+ /**
156
+ * Pass a function to be called after this controller has been modified and loses focus.
157
+ * @param {Function} callback
158
+ * @returns {this}
159
+ * @example
160
+ * const controller = gui.add( object, 'property' );
161
+ *
162
+ * controller.onFinishChange( function( v ) {
163
+ * console.log( 'Changes complete: ' + v );
164
+ * console.assert( this === controller );
165
+ * } );
166
+ */
167
+ onFinishChange( callback ) {
168
+ /**
169
+ * Used to access the function bound to `onFinishChange` events. Don't modify this value
170
+ * directly. Use the `controller.onFinishChange( callback )` method instead.
171
+ * @type {Function}
172
+ */
173
+ this._onFinishChange = callback;
174
+ return this;
175
+ }
176
+
177
+ /**
178
+ * Should be called by Controller when its widgets lose focus.
179
+ * @protected
180
+ */
181
+ _callOnFinishChange() {
182
+
183
+ if ( this._changed ) {
184
+
185
+ this.parent._callOnFinishChange( this );
186
+
187
+ if ( this._onFinishChange !== undefined ) {
188
+ this._onFinishChange.call( this, this.getValue() );
189
+ }
190
+
191
+ }
192
+
193
+ this._changed = false;
194
+
195
+ }
196
+
197
+ /**
198
+ * Sets the controller back to its initial value.
199
+ * @returns {this}
200
+ */
201
+ reset() {
202
+ this.setValue( this.initialValue );
203
+ this._callOnFinishChange();
204
+ return this;
205
+ }
206
+
207
+ /**
208
+ * Enables this controller.
209
+ * @param {boolean} enabled
210
+ * @returns {this}
211
+ * @example
212
+ * controller.enable();
213
+ * controller.enable( false ); // disable
214
+ * controller.enable( controller._disabled ); // toggle
215
+ */
216
+ enable( enabled = true ) {
217
+ return this.disable( !enabled );
218
+ }
219
+
220
+ /**
221
+ * Disables this controller.
222
+ * @param {boolean} disabled
223
+ * @returns {this}
224
+ * @example
225
+ * controller.disable();
226
+ * controller.disable( false ); // enable
227
+ * controller.disable( !controller._disabled ); // toggle
228
+ */
229
+ disable( disabled = true ) {
230
+
231
+ if ( disabled === this._disabled ) return this;
232
+
233
+ this._disabled = disabled;
234
+
235
+ this.domElement.classList.toggle( 'disabled', disabled );
236
+ this.$disable.toggleAttribute( 'disabled', disabled );
237
+
238
+ return this;
239
+
240
+ }
241
+
242
+ /**
243
+ * Shows the Controller after it's been hidden.
244
+ * @param {boolean} show
245
+ * @returns {this}
246
+ * @example
247
+ * controller.show();
248
+ * controller.show( false ); // hide
249
+ * controller.show( controller._hidden ); // toggle
250
+ */
251
+ show( show = true ) {
252
+
253
+ this._hidden = !show;
254
+
255
+ this.domElement.style.display = this._hidden ? 'none' : '';
256
+
257
+ return this;
258
+
259
+ }
260
+
261
+ /**
262
+ * Hides the Controller.
263
+ * @returns {this}
264
+ */
265
+ hide() {
266
+ return this.show( false );
267
+ }
268
+
269
+ /**
270
+ * Changes this controller into a dropdown of options.
271
+ *
272
+ * Calling this method on an option controller will simply update the options. However, if this
273
+ * controller was not already an option controller, old references to this controller are
274
+ * destroyed, and a new controller is added to the end of the GUI.
275
+ * @example
276
+ * // safe usage
277
+ *
278
+ * gui.add( obj, 'prop1' ).options( [ 'a', 'b', 'c' ] );
279
+ * gui.add( obj, 'prop2' ).options( { Big: 10, Small: 1 } );
280
+ * gui.add( obj, 'prop3' );
281
+ *
282
+ * // danger
283
+ *
284
+ * const ctrl1 = gui.add( obj, 'prop1' );
285
+ * gui.add( obj, 'prop2' );
286
+ *
287
+ * // calling options out of order adds a new controller to the end...
288
+ * const ctrl2 = ctrl1.options( [ 'a', 'b', 'c' ] );
289
+ *
290
+ * // ...and ctrl1 now references a controller that doesn't exist
291
+ * assert( ctrl2 !== ctrl1 )
292
+ * @param {object|Array} options
293
+ * @returns {Controller}
294
+ */
295
+ options( options ) {
296
+ const controller = this.parent.add( this.object, this.property, options );
297
+ controller.name( this._name );
298
+ this.destroy();
299
+ return controller;
300
+ }
301
+
302
+ /**
303
+ * Sets the minimum value. Only works on number controllers.
304
+ * @param {number} min
305
+ * @returns {this}
306
+ */
307
+ // eslint-disable-next-line no-unused-vars
308
+ min( min ) {
309
+ return this;
310
+ }
311
+
312
+ /**
313
+ * Sets the maximum value. Only works on number controllers.
314
+ * @param {number} max
315
+ * @returns {this}
316
+ */
317
+ // eslint-disable-next-line no-unused-vars
318
+ max( max ) {
319
+ return this;
320
+ }
321
+
322
+ /**
323
+ * Values set by this controller will be rounded to multiples of `step`. Only works on number
324
+ * controllers.
325
+ * @param {number} step
326
+ * @returns {this}
327
+ */
328
+ // eslint-disable-next-line no-unused-vars
329
+ step( step ) {
330
+ return this;
331
+ }
332
+
333
+ /**
334
+ * Rounds the displayed value to a fixed number of decimals, without affecting the actual value
335
+ * like `step()`. Only works on number controllers.
336
+ * @example
337
+ * gui.add( object, 'property' ).listen().decimals( 4 );
338
+ * @param {number} decimals
339
+ * @returns {this}
340
+ */
341
+ // eslint-disable-next-line no-unused-vars
342
+ decimals( decimals ) {
343
+ return this;
344
+ }
345
+
346
+ /**
347
+ * Calls `updateDisplay()` every animation frame. Pass `false` to stop listening.
348
+ * @param {boolean} listen
349
+ * @returns {this}
350
+ */
351
+ listen( listen = true ) {
352
+
353
+ /**
354
+ * Used to determine if the controller is currently listening. Don't modify this value
355
+ * directly. Use the `controller.listen( true|false )` method instead.
356
+ * @type {boolean}
357
+ */
358
+ this._listening = listen;
359
+
360
+ if ( this._listenCallbackID !== undefined ) {
361
+ cancelAnimationFrame( this._listenCallbackID );
362
+ this._listenCallbackID = undefined;
363
+ }
364
+
365
+ if ( this._listening ) {
366
+ this._listenCallback();
367
+ }
368
+
369
+ return this;
370
+
371
+ }
372
+
373
+ _listenCallback() {
374
+
375
+ this._listenCallbackID = requestAnimationFrame( this._listenCallback );
376
+
377
+ // To prevent framerate loss, make sure the value has changed before updating the display.
378
+ // Note: save() is used here instead of getValue() only because of ColorController. The !== operator
379
+ // won't work for color objects or arrays, but ColorController.save() always returns a string.
380
+
381
+ const curValue = this.save();
382
+
383
+ if ( curValue !== this._listenPrevValue ) {
384
+ this.updateDisplay();
385
+ }
386
+
387
+ this._listenPrevValue = curValue;
388
+
389
+ }
390
+
391
+ /**
392
+ * Returns `object[ property ]`.
393
+ * @returns {any}
394
+ */
395
+ getValue() {
396
+ return this.object[ this.property ];
397
+ }
398
+
399
+ /**
400
+ * Sets the value of `object[ property ]`, invokes any `onChange` handlers and updates the display.
401
+ * @param {any} value
402
+ * @returns {this}
403
+ */
404
+ setValue( value ) {
405
+
406
+ if ( this.getValue() !== value ) {
407
+
408
+ this.object[ this.property ] = value;
409
+ this._callOnChange();
410
+ this.updateDisplay();
411
+
412
+ }
413
+
414
+ return this;
415
+
416
+ }
417
+
418
+ /**
419
+ * Updates the display to keep it in sync with the current value. Useful for updating your
420
+ * controllers when their values have been modified outside of the GUI.
421
+ * @returns {this}
422
+ */
423
+ updateDisplay() {
424
+ return this;
425
+ }
426
+
427
+ load( value ) {
428
+ this.setValue( value );
429
+ this._callOnFinishChange();
430
+ return this;
431
+ }
432
+
433
+ save() {
434
+ return this.getValue();
435
+ }
436
+
437
+ /**
438
+ * Destroys this controller and removes it from the parent GUI.
439
+ */
440
+ destroy() {
441
+ this.listen( false );
442
+ this.parent.children.splice( this.parent.children.indexOf( this ), 1 );
443
+ this.parent.controllers.splice( this.parent.controllers.indexOf( this ), 1 );
444
+ this.parent.$children.removeChild( this.domElement );
445
+ }
446
+
447
+ }
@@ -0,0 +1,27 @@
1
+ import Controller from './Controller';
2
+
3
+ export default class FunctionController extends Controller {
4
+
5
+ constructor( parent, object, property ) {
6
+
7
+ super( parent, object, property, 'function' );
8
+
9
+ // Buttons are the only case where widget contains name
10
+ this.$button = document.createElement( 'button' );
11
+ this.$button.appendChild( this.$name );
12
+ this.$widget.appendChild( this.$button );
13
+
14
+ this.$button.addEventListener( 'click', e => {
15
+ e.preventDefault();
16
+ this.getValue().call( this.object );
17
+ this._callOnChange();
18
+ } );
19
+
20
+ // enables :active pseudo class on mobile
21
+ this.$button.addEventListener( 'touchstart', () => {}, { passive: true } );
22
+
23
+ this.$disable = this.$button;
24
+
25
+ }
26
+
27
+ }