@needle-tools/engine 4.2.5 → 4.3.0-alpha.1

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 (121) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/components.needle.json +1 -1
  3. package/dist/needle-engine.bundle.js +4245 -2977
  4. package/dist/needle-engine.bundle.light.js +4236 -2968
  5. package/dist/needle-engine.bundle.light.min.js +73 -73
  6. package/dist/needle-engine.bundle.light.umd.cjs +61 -61
  7. package/dist/needle-engine.bundle.min.js +62 -62
  8. package/dist/needle-engine.bundle.umd.cjs +61 -61
  9. package/dist/needle-engine.light.d.ts +9 -9
  10. package/dist/three-examples.js +825 -794
  11. package/dist/three-examples.light.js +825 -794
  12. package/dist/three-examples.light.min.js +12 -12
  13. package/dist/three-examples.light.umd.cjs +10 -10
  14. package/dist/three-examples.min.js +12 -12
  15. package/dist/three-examples.umd.cjs +10 -10
  16. package/lib/engine/engine_addressables.d.ts +3 -0
  17. package/lib/engine/engine_addressables.js +18 -0
  18. package/lib/engine/engine_addressables.js.map +1 -1
  19. package/lib/engine/engine_input.d.ts +20 -1
  20. package/lib/engine/engine_input.js.map +1 -1
  21. package/lib/engine/engine_types.d.ts +162 -17
  22. package/lib/engine-components/Animator.d.ts +129 -21
  23. package/lib/engine-components/Animator.js +115 -21
  24. package/lib/engine-components/Animator.js.map +1 -1
  25. package/lib/engine-components/AnimatorController.d.ts +161 -32
  26. package/lib/engine-components/AnimatorController.js +176 -29
  27. package/lib/engine-components/AnimatorController.js.map +1 -1
  28. package/lib/engine-components/AudioListener.d.ts +16 -5
  29. package/lib/engine-components/AudioListener.js +16 -5
  30. package/lib/engine-components/AudioListener.js.map +1 -1
  31. package/lib/engine-components/AudioSource.d.ts +120 -28
  32. package/lib/engine-components/AudioSource.js +120 -37
  33. package/lib/engine-components/AudioSource.js.map +1 -1
  34. package/lib/engine-components/AvatarLoader.d.ts +61 -0
  35. package/lib/engine-components/AvatarLoader.js +61 -1
  36. package/lib/engine-components/AvatarLoader.js.map +1 -1
  37. package/lib/engine-components/AxesHelper.d.ts +19 -1
  38. package/lib/engine-components/AxesHelper.js +19 -1
  39. package/lib/engine-components/AxesHelper.js.map +1 -1
  40. package/lib/engine-components/BoxHelperComponent.d.ts +26 -0
  41. package/lib/engine-components/BoxHelperComponent.js +26 -0
  42. package/lib/engine-components/BoxHelperComponent.js.map +1 -1
  43. package/lib/engine-components/Camera.d.ts +126 -37
  44. package/lib/engine-components/Camera.js +139 -37
  45. package/lib/engine-components/Camera.js.map +1 -1
  46. package/lib/engine-components/CameraUtils.js +20 -0
  47. package/lib/engine-components/CameraUtils.js.map +1 -1
  48. package/lib/engine-components/Collider.d.ts +95 -21
  49. package/lib/engine-components/Collider.js +100 -23
  50. package/lib/engine-components/Collider.js.map +1 -1
  51. package/lib/engine-components/Component.d.ts +554 -106
  52. package/lib/engine-components/Component.js +352 -81
  53. package/lib/engine-components/Component.js.map +1 -1
  54. package/lib/engine-components/DragControls.d.ts +95 -21
  55. package/lib/engine-components/DragControls.js +126 -32
  56. package/lib/engine-components/DragControls.js.map +1 -1
  57. package/lib/engine-components/DropListener.d.ts +99 -16
  58. package/lib/engine-components/DropListener.js +119 -14
  59. package/lib/engine-components/DropListener.js.map +1 -1
  60. package/lib/engine-components/Light.d.ts +102 -5
  61. package/lib/engine-components/Light.js +102 -44
  62. package/lib/engine-components/Light.js.map +1 -1
  63. package/lib/engine-components/NeedleMenu.d.ts +28 -11
  64. package/lib/engine-components/NeedleMenu.js +28 -11
  65. package/lib/engine-components/NeedleMenu.js.map +1 -1
  66. package/lib/engine-components/Networking.d.ts +37 -5
  67. package/lib/engine-components/Networking.js +37 -5
  68. package/lib/engine-components/Networking.js.map +1 -1
  69. package/lib/engine-components/SceneSwitcher.d.ts +8 -0
  70. package/lib/engine-components/SceneSwitcher.js +72 -8
  71. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  72. package/lib/engine-components/SpatialTrigger.d.ts +66 -1
  73. package/lib/engine-components/SpatialTrigger.js +74 -2
  74. package/lib/engine-components/SpatialTrigger.js.map +1 -1
  75. package/lib/engine-components/SpectatorCamera.d.ts +66 -4
  76. package/lib/engine-components/SpectatorCamera.js +132 -6
  77. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  78. package/lib/engine-components/SyncedTransform.d.ts +45 -6
  79. package/lib/engine-components/SyncedTransform.js +45 -6
  80. package/lib/engine-components/SyncedTransform.js.map +1 -1
  81. package/lib/engine-components/TransformGizmo.d.ts +49 -3
  82. package/lib/engine-components/TransformGizmo.js +49 -3
  83. package/lib/engine-components/TransformGizmo.js.map +1 -1
  84. package/lib/engine-components/ui/EventSystem.d.ts +1 -0
  85. package/lib/engine-components/ui/EventSystem.js +8 -5
  86. package/lib/engine-components/ui/EventSystem.js.map +1 -1
  87. package/lib/engine-components/webxr/WebXR.d.ts +131 -22
  88. package/lib/engine-components/webxr/WebXR.js +132 -23
  89. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  90. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +82 -9
  91. package/lib/engine-components-experimental/networking/PlayerSync.js +76 -11
  92. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  93. package/package.json +1 -1
  94. package/plugins/vite/alias.js +6 -3
  95. package/src/engine/engine_addressables.ts +21 -0
  96. package/src/engine/engine_input.ts +20 -1
  97. package/src/engine/engine_types.ts +179 -18
  98. package/src/engine-components/Animator.ts +142 -22
  99. package/src/engine-components/AnimatorController.ts +184 -34
  100. package/src/engine-components/AudioListener.ts +16 -5
  101. package/src/engine-components/AudioSource.ts +126 -37
  102. package/src/engine-components/AvatarLoader.ts +61 -2
  103. package/src/engine-components/AxesHelper.ts +21 -1
  104. package/src/engine-components/BoxHelperComponent.ts +26 -0
  105. package/src/engine-components/Camera.ts +147 -41
  106. package/src/engine-components/CameraUtils.ts +20 -0
  107. package/src/engine-components/Collider.ts +102 -27
  108. package/src/engine-components/Component.ts +605 -129
  109. package/src/engine-components/DragControls.ts +134 -38
  110. package/src/engine-components/DropListener.ts +143 -23
  111. package/src/engine-components/Light.ts +105 -44
  112. package/src/engine-components/NeedleMenu.ts +29 -11
  113. package/src/engine-components/Networking.ts +37 -6
  114. package/src/engine-components/SceneSwitcher.ts +78 -9
  115. package/src/engine-components/SpatialTrigger.ts +80 -3
  116. package/src/engine-components/SpectatorCamera.ts +136 -18
  117. package/src/engine-components/SyncedTransform.ts +50 -7
  118. package/src/engine-components/TransformGizmo.ts +49 -4
  119. package/src/engine-components/ui/EventSystem.ts +9 -7
  120. package/src/engine-components/webxr/WebXR.ts +144 -27
  121. package/src/engine-components-experimental/networking/PlayerSync.ts +85 -13
@@ -13,8 +13,11 @@ import { RGBAColor } from "../engine/js-extensions/index.js";
13
13
  import { Behaviour, GameObject } from "./Component.js";
14
14
  import { OrbitControls } from "./OrbitControls.js";
15
15
 
16
- /** The ClearFlags enum is used to determine how the camera clears the background */
16
+ /**
17
+ * The ClearFlags enum is used to determine how the camera clears the background
18
+ */
17
19
  export enum ClearFlags {
20
+ /** Don't clear the background */
18
21
  None = 0,
19
22
  /** Clear the background with a skybox */
20
23
  Skybox = 1,
@@ -28,16 +31,28 @@ const debug = getParam("debugcam");
28
31
  const debugscreenpointtoray = getParam("debugscreenpointtoray");
29
32
 
30
33
  /**
34
+ * Camera component that handles rendering from a specific viewpoint in the scene.
35
+ * Supports both perspective and orthographic cameras with various rendering options.
36
+ * Internally, this component uses {@link PerspectiveCamera} and {@link OrthographicCamera} three.js objects.
37
+ *
31
38
  * @category Camera Controls
32
39
  * @group Components
33
40
  */
34
41
  export class Camera extends Behaviour implements ICamera {
35
42
 
43
+ /**
44
+ * Returns whether this component is a camera
45
+ * @returns {boolean} Always returns true
46
+ */
36
47
  get isCamera() {
37
48
  return true;
38
49
  }
39
50
 
40
- /** The camera's aspect ratio (width divided by height) if it is a perspective camera */
51
+ /**
52
+ * Gets or sets the camera's aspect ratio (width divided by height).
53
+ * For perspective cameras, this directly affects the camera's projection matrix.
54
+ * When set, automatically updates the projection matrix.
55
+ */
41
56
  get aspect(): number {
42
57
  if (this._cam instanceof PerspectiveCamera) return this._cam.aspect;
43
58
  return (this.context.domWidth / this.context.domHeight);
@@ -51,7 +66,11 @@ export class Camera extends Behaviour implements ICamera {
51
66
  }
52
67
  }
53
68
  }
54
- /** The camera's field of view in degrees if it is a perspective camera. Calls updateProjectionMatrix when set */
69
+
70
+ /**
71
+ * Gets or sets the camera's field of view in degrees for perspective cameras.
72
+ * When set, automatically updates the projection matrix.
73
+ */
55
74
  get fieldOfView(): number | undefined {
56
75
  if (this._cam instanceof PerspectiveCamera) {
57
76
  return this._cam.fov;
@@ -74,7 +93,11 @@ export class Camera extends Behaviour implements ICamera {
74
93
  }
75
94
  }
76
95
 
77
- /** The camera's near clipping plane. Calls updateProjectionMatrix when set */
96
+ /**
97
+ * Gets or sets the camera's near clipping plane distance.
98
+ * Objects closer than this distance won't be rendered.
99
+ * When set, automatically updates the projection matrix.
100
+ */
78
101
  get nearClipPlane(): number { return this._nearClipPlane; }
79
102
  @serializable()
80
103
  set nearClipPlane(val) {
@@ -87,7 +110,11 @@ export class Camera extends Behaviour implements ICamera {
87
110
  }
88
111
  private _nearClipPlane: number = 0.1;
89
112
 
90
- /** The camera's far clipping plane. Calls updateProjectionMatrix when set */
113
+ /**
114
+ * Gets or sets the camera's far clipping plane distance.
115
+ * Objects farther than this distance won't be rendered.
116
+ * When set, automatically updates the projection matrix.
117
+ */
91
118
  get farClipPlane(): number { return this._farClipPlane; }
92
119
  @serializable()
93
120
  set farClipPlane(val) {
@@ -101,7 +128,8 @@ export class Camera extends Behaviour implements ICamera {
101
128
  private _farClipPlane: number = 1000;
102
129
 
103
130
  /**
104
- * Applys both the camera's near and far plane and calls updateProjectionMatrix on the camera.
131
+ * Applies both the camera's near and far clipping planes and updates the projection matrix.
132
+ * This ensures rendering occurs only within the specified distance range.
105
133
  */
106
134
  applyClippingPlane() {
107
135
  if (this._cam) {
@@ -111,7 +139,10 @@ export class Camera extends Behaviour implements ICamera {
111
139
  }
112
140
  }
113
141
 
114
- /** The camera's clear flags - determines if the background is a skybox or a solid color or transparent */
142
+ /**
143
+ * Gets or sets the camera's clear flags that determine how the background is rendered.
144
+ * Options include skybox, solid color, or transparent background.
145
+ */
115
146
  @serializable()
116
147
  public get clearFlags(): ClearFlags {
117
148
  return this._clearFlags;
@@ -121,18 +152,31 @@ export class Camera extends Behaviour implements ICamera {
121
152
  this._clearFlags = val;
122
153
  this.applyClearFlagsIfIsActiveCamera();
123
154
  }
155
+
156
+ /**
157
+ * Determines if the camera should use orthographic projection instead of perspective.
158
+ */
124
159
  @serializable()
125
160
  public orthographic: boolean = false;
161
+
162
+ /**
163
+ * The size of the orthographic camera's view volume when in orthographic mode.
164
+ * Larger values show more of the scene.
165
+ */
126
166
  @serializable()
127
167
  public orthographicSize: number = 5;
128
168
 
169
+ /**
170
+ * Controls the transparency level of the camera background in AR mode on supported devices.
171
+ * Value from 0 (fully transparent) to 1 (fully opaque).
172
+ */
129
173
  @serializable()
130
174
  public ARBackgroundAlpha: number = 0;
131
175
 
132
176
  /**
133
- * The [`mask`](https://threejs.org/docs/#api/en/core/Layers.mask) value of the three camera object layers
134
- * If you want to just see objects on one layer (e.g. layer 2) then you can use `cullingLayer = 2` on this camera component instead
135
- */
177
+ * Gets or sets the layers mask that determines which objects this camera will render.
178
+ * Uses the {@link https://threejs.org/docs/#api/en/core/Layers.mask|three.js layers mask} convention.
179
+ */
136
180
  @serializable()
137
181
  public set cullingMask(val: number) {
138
182
  this._cullingMask = val;
@@ -146,14 +190,19 @@ export class Camera extends Behaviour implements ICamera {
146
190
  }
147
191
  private _cullingMask: number = 0xffffffff;
148
192
 
149
- /** Set only a specific layer active to be rendered by the camera.
150
- * This is equivalent to calling `layers.set(val)`
151
- **/
193
+ /**
194
+ * Sets only a specific layer to be active for rendering by this camera.
195
+ * This is equivalent to calling `layers.set(val)` on the three.js camera object.
196
+ * @param val The layer index to set active
197
+ */
152
198
  public set cullingLayer(val: number) {
153
199
  this.cullingMask = (1 << val | 0) >>> 0;
154
200
  }
155
201
 
156
- /** The blurriness of the background texture (when using a skybox) */
202
+ /**
203
+ * Gets or sets the blurriness of the skybox background.
204
+ * Values range from 0 (sharp) to 1 (maximum blur).
205
+ */
157
206
  @serializable()
158
207
  public set backgroundBlurriness(val: number | undefined) {
159
208
  if (val === this._backgroundBlurriness) return;
@@ -168,7 +217,10 @@ export class Camera extends Behaviour implements ICamera {
168
217
  }
169
218
  private _backgroundBlurriness?: number = undefined;
170
219
 
171
- /** The intensity of the background texture (when using a skybox) */
220
+ /**
221
+ * Gets or sets the intensity of the skybox background.
222
+ * Values range from 0 (dark) to 10 (very bright).
223
+ */
172
224
  @serializable()
173
225
  public set backgroundIntensity(val: number | undefined) {
174
226
  if (val === this._backgroundIntensity) return;
@@ -183,7 +235,10 @@ export class Camera extends Behaviour implements ICamera {
183
235
  }
184
236
  private _backgroundIntensity?: number = undefined;
185
237
 
186
- /** the rotation of the background texture (when using a skybox) */
238
+ /**
239
+ * Gets or sets the rotation of the skybox background.
240
+ * Controls the orientation of the environment map.
241
+ */
187
242
  @serializable(Euler)
188
243
  public set backgroundRotation(val: Euler | undefined) {
189
244
  if (val === this._backgroundRotation) return;
@@ -198,7 +253,10 @@ export class Camera extends Behaviour implements ICamera {
198
253
  }
199
254
  private _backgroundRotation?: Euler = undefined;
200
255
 
201
- /** The intensity of the environment map */
256
+ /**
257
+ * Gets or sets the intensity of the environment lighting.
258
+ * Controls how strongly the environment map affects scene lighting.
259
+ */
202
260
  @serializable()
203
261
  public set environmentIntensity(val: number | undefined) {
204
262
  this._environmentIntensity = val;
@@ -208,7 +266,10 @@ export class Camera extends Behaviour implements ICamera {
208
266
  }
209
267
  private _environmentIntensity?: number = undefined;
210
268
 
211
- /** The background color of the camera when {@link ClearFlags} are set to `SolidColor` */
269
+ /**
270
+ * Gets or sets the background color of the camera when {@link ClearFlags} is set to {@link ClearFlags.SolidColor}.
271
+ * The alpha component controls transparency.
272
+ */
212
273
  @serializable(RGBAColor)
213
274
  public get backgroundColor(): RGBAColor | null {
214
275
  return this._backgroundColor ?? null;
@@ -225,9 +286,10 @@ export class Camera extends Behaviour implements ICamera {
225
286
  this.applyClearFlagsIfIsActiveCamera();
226
287
  }
227
288
 
228
- /** The texture that the camera should render to
229
- * It can be used to render to a {@link Texture} instead of the screen.
230
- */
289
+ /**
290
+ * Gets or sets the texture that the camera should render to instead of the screen.
291
+ * Useful for creating effects like mirrors, portals or custom post processing.
292
+ */
231
293
  @serializable(RenderTexture)
232
294
  public set targetTexture(rt: RenderTexture | null) {
233
295
  this._targetTexture = rt;
@@ -244,16 +306,17 @@ export class Camera extends Behaviour implements ICamera {
244
306
  private _skybox?: CameraSkybox;
245
307
 
246
308
  /**
247
- * Get the three.js camera object. This will create a camera if it does not exist yet.
248
- * @returns {PerspectiveCamera | OrthographicCamera} the three camera
249
- * @deprecated use {@link threeCamera} instead
309
+ * Gets the three.js camera object. Creates one if it doesn't exist yet.
310
+ * @returns {PerspectiveCamera | OrthographicCamera} The three.js camera object
311
+ * @deprecated Use {@link threeCamera} instead
250
312
  */
251
313
  public get cam(): PerspectiveCamera | OrthographicCamera {
252
314
  return this.threeCamera;
253
315
  }
316
+
254
317
  /**
255
- * Get the three.js camera object. This will create a camera if it does not exist yet.
256
- * @returns {PerspectiveCamera | OrthographicCamera} the three camera
318
+ * Gets the three.js camera object. Creates one if it doesn't exist yet.
319
+ * @returns {PerspectiveCamera | OrthographicCamera} The three.js camera object
257
320
  */
258
321
  public get threeCamera(): PerspectiveCamera | OrthographicCamera {
259
322
  if (this.activeAndEnabled)
@@ -263,6 +326,16 @@ export class Camera extends Behaviour implements ICamera {
263
326
 
264
327
  private static _origin: Vector3 = new Vector3();
265
328
  private static _direction: Vector3 = new Vector3();
329
+
330
+ /**
331
+ * Converts screen coordinates to a ray in world space.
332
+ * Useful for implementing picking or raycasting from screen to world.
333
+ *
334
+ * @param x The x screen coordinate
335
+ * @param y The y screen coordinate
336
+ * @param ray Optional ray object to reuse instead of creating a new one
337
+ * @returns {Ray} A ray originating from the camera position pointing through the screen point
338
+ */
266
339
  public screenPointToRay(x: number, y: number, ray?: Ray): Ray {
267
340
  const cam = this.threeCamera;
268
341
  const origin = Camera._origin;
@@ -285,9 +358,12 @@ export class Camera extends Behaviour implements ICamera {
285
358
  }
286
359
 
287
360
  private _frustum?: Frustum;
361
+
288
362
  /**
289
- * Get a frustum - it will be created the first time this method is called and updated every frame in onBeforeRender when it exists.
290
- * You can also manually update it using the updateFrustum method.
363
+ * Gets the camera's view frustum for culling and visibility checks.
364
+ * Creates the frustum if it doesn't exist and returns it.
365
+ *
366
+ * @returns {Frustum} The camera's view frustum
291
367
  */
292
368
  public getFrustum(): Frustum {
293
369
  if (!this._frustum) {
@@ -296,13 +372,22 @@ export class Camera extends Behaviour implements ICamera {
296
372
  }
297
373
  return this._frustum;
298
374
  }
299
- /** Force frustum update - note that this also happens automatically every frame in onBeforeRender */
375
+
376
+ /**
377
+ * Forces an update of the camera's frustum.
378
+ * This is automatically called every frame in onBeforeRender.
379
+ */
300
380
  public updateFrustum() {
301
381
  if (!this._frustum) this._frustum = new Frustum();
302
382
  this._frustum.setFromProjectionMatrix(this.getProjectionScreenMatrix(this._projScreenMatrix, true), this.context.renderer.coordinateSystem);
303
383
  }
384
+
304
385
  /**
305
- * @returns {Matrix4} this camera's projection screen matrix.
386
+ * Gets this camera's projection-screen matrix.
387
+ *
388
+ * @param target Matrix4 object to store the result in
389
+ * @param forceUpdate Whether to force recalculation of the matrix
390
+ * @returns {Matrix4} The requested projection screen matrix
306
391
  */
307
392
  public getProjectionScreenMatrix(target: Matrix4, forceUpdate?: boolean) {
308
393
  if (forceUpdate) {
@@ -313,7 +398,6 @@ export class Camera extends Behaviour implements ICamera {
313
398
  }
314
399
  private readonly _projScreenMatrix = new Matrix4();
315
400
 
316
-
317
401
  /** @internal */
318
402
  awake() {
319
403
  if (debugscreenpointtoray) {
@@ -382,8 +466,9 @@ export class Camera extends Behaviour implements ICamera {
382
466
  }
383
467
 
384
468
  /**
385
- * Creates a {@link PerspectiveCamera} if it does not exist yet and set the camera's properties. This is internally also called when accessing the {@link cam} property.
386
- **/
469
+ * Creates a three.js camera object if it doesn't exist yet and sets its properties.
470
+ * This is called internally when accessing the {@link threeCamera} property.
471
+ */
387
472
  buildCamera() {
388
473
  if (this._cam) return;
389
474
 
@@ -428,13 +513,21 @@ export class Camera extends Behaviour implements ICamera {
428
513
  }
429
514
  }
430
515
 
516
+ /**
517
+ * Applies clear flags if this is the active main camera.
518
+ * @param opts Options for applying clear flags
519
+ */
431
520
  applyClearFlagsIfIsActiveCamera(opts?: { applySkybox: boolean }) {
432
521
  if (this.context.mainCameraComponent === this) {
433
522
  this.applyClearFlags(opts);
434
523
  }
435
524
  }
436
525
 
437
- /** Apply this camera's clear flags and related settings to the renderer */
526
+ /**
527
+ * Applies this camera's clear flags and related settings to the renderer.
528
+ * This controls how the background is rendered (skybox, solid color, transparent).
529
+ * @param opts Options for applying clear flags
530
+ */
438
531
  applyClearFlags(opts?: { applySkybox: boolean }) {
439
532
  if (!this._cam) {
440
533
  if (debug) console.log("Camera does not exist (apply clear flags)")
@@ -503,7 +596,7 @@ export class Camera extends Behaviour implements ICamera {
503
596
  }
504
597
 
505
598
  /**
506
- * Apply the skybox to the scene
599
+ * Applies the skybox texture to the scene background.
507
600
  */
508
601
  applySceneSkybox() {
509
602
  if (!this._skybox)
@@ -511,9 +604,12 @@ export class Camera extends Behaviour implements ICamera {
511
604
  this._skybox.apply();
512
605
  }
513
606
 
514
- /** Used to determine if the background should be transparent when in pass through AR
515
- * @returns true when in XR on a pass through device where the background shouldbe invisible
516
- **/
607
+ /**
608
+ * Determines if the background should be transparent when in passthrough AR mode.
609
+ *
610
+ * @param context The current rendering context
611
+ * @returns {boolean} True when in XR on a pass through device where the background should be invisible
612
+ */
517
613
  static backgroundShouldBeTransparent(context: Context) {
518
614
  const session = context.renderer.xr?.getSession();
519
615
  if (!session) return false;
@@ -543,7 +639,10 @@ export class Camera extends Behaviour implements ICamera {
543
639
  }
544
640
  }
545
641
 
546
-
642
+ /**
643
+ * Helper class for managing skybox textures for cameras.
644
+ * Handles retrieving and applying skybox textures to the scene.
645
+ */
547
646
  class CameraSkybox {
548
647
 
549
648
  private _camera: Camera;
@@ -555,6 +654,10 @@ class CameraSkybox {
555
654
  this._camera = camera;
556
655
  }
557
656
 
657
+ /**
658
+ * Applies the skybox texture to the scene background.
659
+ * Retrieves the texture based on the camera's source ID.
660
+ */
558
661
  apply() {
559
662
  this._skybox = this.context.lightmaps.tryGetSkybox(this._camera.sourceId) as Texture;
560
663
  if (!this._skybox) {
@@ -572,13 +675,16 @@ class CameraSkybox {
572
675
  }
573
676
  }
574
677
 
575
-
678
+ /**
679
+ * Adds orbit controls to the camera if the freecam URL parameter is enabled.
680
+ *
681
+ * @param cam The camera to potentially add orbit controls to
682
+ */
576
683
  function handleFreeCam(cam: Camera) {
577
684
  const isFreecam = getParam("freecam");
578
685
  if (isFreecam) {
579
686
  if (cam.context.mainCameraComponent === cam) {
580
687
  GameObject.getOrAddComponent(cam.gameObject, OrbitControls);
581
688
  }
582
-
583
689
  }
584
690
  }
@@ -13,6 +13,13 @@ import { OrbitControls } from "./OrbitControls.js";
13
13
 
14
14
  const debug = getParam("debugmissingcamera");
15
15
 
16
+ /**
17
+ * Handler for missing camera events. Creates a default fallback camera when no camera is found in the scene.
18
+ * Sets up camera properties based on the context and HTML element attributes.
19
+ *
20
+ * @param evt The context event containing scene and configuration information
21
+ * @returns The created camera component
22
+ */
16
23
  ContextRegistry.registerCallback(ContextEvent.MissingCamera, (evt) => {
17
24
  if (debug) console.warn("Creating missing camera")
18
25
  const scene = evt.context.scene;
@@ -57,6 +64,12 @@ ContextRegistry.registerCallback(ContextEvent.MissingCamera, (evt) => {
57
64
  return cam;
58
65
  });
59
66
 
67
+ /**
68
+ * Handler for context creation events. Checks if camera controls should be added
69
+ * to the main camera when the context is created.
70
+ *
71
+ * @param evt The context creation event containing the context information
72
+ */
60
73
  ContextRegistry.registerCallback(ContextEvent.ContextCreated, (evt) => {
61
74
  if (!evt.context.mainCamera) {
62
75
  if (debug) console.log("Will not auto-fit because a default camera exists");
@@ -77,6 +90,13 @@ ContextRegistry.registerCallback(ContextEvent.ContextCreated, (evt) => {
77
90
  }
78
91
  })
79
92
 
93
+ /**
94
+ * Creates default orbit camera controls for the specified camera.
95
+ * Configures auto-rotation and auto-fit settings based on HTML attributes.
96
+ *
97
+ * @param context The rendering context
98
+ * @param cam Optional camera component to attach controls to (uses main camera if not specified)
99
+ */
80
100
  function createDefaultCameraControls(context: IContext, cam?: ICamera) {
81
101
 
82
102
  cam = cam ?? context.mainCameraComponent;