@needle-tools/engine 4.3.0-alpha → 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 (101) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/needle-engine.bundle.js +1467 -222
  3. package/dist/needle-engine.bundle.light.js +1467 -222
  4. package/dist/needle-engine.bundle.light.min.js +32 -32
  5. package/dist/needle-engine.bundle.light.umd.cjs +3 -3
  6. package/dist/needle-engine.bundle.min.js +3 -3
  7. package/dist/needle-engine.bundle.umd.cjs +3 -3
  8. package/dist/needle-engine.light.d.ts +9 -9
  9. package/lib/engine/engine_types.d.ts +162 -17
  10. package/lib/engine-components/Animator.d.ts +129 -21
  11. package/lib/engine-components/Animator.js +115 -21
  12. package/lib/engine-components/Animator.js.map +1 -1
  13. package/lib/engine-components/AnimatorController.d.ts +161 -32
  14. package/lib/engine-components/AnimatorController.js +176 -29
  15. package/lib/engine-components/AnimatorController.js.map +1 -1
  16. package/lib/engine-components/AudioListener.d.ts +16 -5
  17. package/lib/engine-components/AudioListener.js +16 -5
  18. package/lib/engine-components/AudioListener.js.map +1 -1
  19. package/lib/engine-components/AudioSource.d.ts +120 -28
  20. package/lib/engine-components/AudioSource.js +120 -37
  21. package/lib/engine-components/AudioSource.js.map +1 -1
  22. package/lib/engine-components/AvatarLoader.d.ts +61 -0
  23. package/lib/engine-components/AvatarLoader.js +61 -1
  24. package/lib/engine-components/AvatarLoader.js.map +1 -1
  25. package/lib/engine-components/AxesHelper.d.ts +19 -1
  26. package/lib/engine-components/AxesHelper.js +19 -1
  27. package/lib/engine-components/AxesHelper.js.map +1 -1
  28. package/lib/engine-components/BoxHelperComponent.d.ts +26 -0
  29. package/lib/engine-components/BoxHelperComponent.js +26 -0
  30. package/lib/engine-components/BoxHelperComponent.js.map +1 -1
  31. package/lib/engine-components/Camera.d.ts +126 -37
  32. package/lib/engine-components/Camera.js +139 -37
  33. package/lib/engine-components/Camera.js.map +1 -1
  34. package/lib/engine-components/CameraUtils.js +20 -0
  35. package/lib/engine-components/CameraUtils.js.map +1 -1
  36. package/lib/engine-components/Collider.d.ts +95 -21
  37. package/lib/engine-components/Collider.js +100 -23
  38. package/lib/engine-components/Collider.js.map +1 -1
  39. package/lib/engine-components/Component.d.ts +554 -106
  40. package/lib/engine-components/Component.js +352 -81
  41. package/lib/engine-components/Component.js.map +1 -1
  42. package/lib/engine-components/DragControls.d.ts +95 -21
  43. package/lib/engine-components/DragControls.js +126 -32
  44. package/lib/engine-components/DragControls.js.map +1 -1
  45. package/lib/engine-components/DropListener.d.ts +99 -16
  46. package/lib/engine-components/DropListener.js +119 -14
  47. package/lib/engine-components/DropListener.js.map +1 -1
  48. package/lib/engine-components/Light.d.ts +102 -5
  49. package/lib/engine-components/Light.js +102 -44
  50. package/lib/engine-components/Light.js.map +1 -1
  51. package/lib/engine-components/NeedleMenu.d.ts +28 -11
  52. package/lib/engine-components/NeedleMenu.js +28 -11
  53. package/lib/engine-components/NeedleMenu.js.map +1 -1
  54. package/lib/engine-components/Networking.d.ts +37 -5
  55. package/lib/engine-components/Networking.js +37 -5
  56. package/lib/engine-components/Networking.js.map +1 -1
  57. package/lib/engine-components/SceneSwitcher.js +44 -0
  58. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  59. package/lib/engine-components/SpatialTrigger.d.ts +66 -1
  60. package/lib/engine-components/SpatialTrigger.js +74 -2
  61. package/lib/engine-components/SpatialTrigger.js.map +1 -1
  62. package/lib/engine-components/SpectatorCamera.d.ts +66 -4
  63. package/lib/engine-components/SpectatorCamera.js +132 -6
  64. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  65. package/lib/engine-components/SyncedTransform.d.ts +45 -6
  66. package/lib/engine-components/SyncedTransform.js +45 -6
  67. package/lib/engine-components/SyncedTransform.js.map +1 -1
  68. package/lib/engine-components/TransformGizmo.d.ts +49 -3
  69. package/lib/engine-components/TransformGizmo.js +49 -3
  70. package/lib/engine-components/TransformGizmo.js.map +1 -1
  71. package/lib/engine-components/webxr/WebXR.d.ts +131 -22
  72. package/lib/engine-components/webxr/WebXR.js +132 -23
  73. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  74. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +82 -9
  75. package/lib/engine-components-experimental/networking/PlayerSync.js +76 -11
  76. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  77. package/package.json +1 -1
  78. package/src/engine/engine_types.ts +179 -18
  79. package/src/engine-components/Animator.ts +142 -22
  80. package/src/engine-components/AnimatorController.ts +184 -34
  81. package/src/engine-components/AudioListener.ts +16 -5
  82. package/src/engine-components/AudioSource.ts +126 -37
  83. package/src/engine-components/AvatarLoader.ts +61 -2
  84. package/src/engine-components/AxesHelper.ts +21 -1
  85. package/src/engine-components/BoxHelperComponent.ts +26 -0
  86. package/src/engine-components/Camera.ts +147 -41
  87. package/src/engine-components/CameraUtils.ts +20 -0
  88. package/src/engine-components/Collider.ts +102 -27
  89. package/src/engine-components/Component.ts +605 -129
  90. package/src/engine-components/DragControls.ts +134 -38
  91. package/src/engine-components/DropListener.ts +143 -23
  92. package/src/engine-components/Light.ts +105 -44
  93. package/src/engine-components/NeedleMenu.ts +29 -11
  94. package/src/engine-components/Networking.ts +37 -6
  95. package/src/engine-components/SceneSwitcher.ts +48 -1
  96. package/src/engine-components/SpatialTrigger.ts +80 -3
  97. package/src/engine-components/SpectatorCamera.ts +136 -18
  98. package/src/engine-components/SyncedTransform.ts +50 -7
  99. package/src/engine-components/TransformGizmo.ts +49 -4
  100. package/src/engine-components/webxr/WebXR.ts +144 -27
  101. package/src/engine-components-experimental/networking/PlayerSync.ts +85 -13
@@ -18,8 +18,10 @@ import { SyncedTransform } from "./SyncedTransform.js";
18
18
  import type { IPointerEventHandler, PointerEventData } from "./ui/PointerEvents.js";
19
19
  import { ObjectRaycaster } from "./ui/Raycaster.js";
20
20
 
21
+ /** Enable debug visualization and logging for DragControls by using the URL parameter `?debugdrag`. */
21
22
  const debug = getParam("debugdrag");
22
23
 
24
+ /** Buffer to store currently active DragControls components */
23
25
  const dragControlsBuffer: DragControls[] = [];
24
26
 
25
27
  /**
@@ -34,7 +36,7 @@ export enum DragMode {
34
36
  HitNormal = 2,
35
37
  /** Combination of XZ and Screen based on the viewing angle. Low angles result in Screen dragging and higher angles in XZ dragging. */
36
38
  DynamicViewAngle = 3,
37
- /** The drag plane is adjusted dynamically while dragging. */
39
+ /** The drag plane is snapped to surfaces in the scene while dragging. */
38
40
  SnapToSurfaces = 4,
39
41
  /** Don't allow dragging the object */
40
42
  None = 5,
@@ -42,18 +44,24 @@ export enum DragMode {
42
44
 
43
45
  /**
44
46
  * DragControls allows you to drag objects around in the scene. It can be used to move objects in 2D (screen space) or 3D (world space).
47
+ * Debug mode can be enabled with the URL parameter `?debugdrag`, which shows visual helpers and logs drag operations.
48
+ *
45
49
  * @category Interactivity
46
50
  * @group Components
47
51
  */
48
52
  export class DragControls extends Behaviour implements IPointerEventHandler {
49
53
 
50
54
  /**
55
+ * Checks if any DragControls component is currently active with selected objects
51
56
  * @returns True if any DragControls component is currently active
52
57
  */
53
58
  public static get HasAnySelected(): boolean { return this._active > 0; }
54
59
  private static _active: number = 0;
55
60
 
56
- /** @returns a list of DragControl components that are currently active */
61
+ /**
62
+ * Retrieves a list of all DragControl components that are currently dragging objects.
63
+ * @returns Array of currently active DragControls components
64
+ */
57
65
  public static get CurrentlySelected() {
58
66
  dragControlsBuffer.length = 0;
59
67
  for (const dc of this._instances) {
@@ -63,51 +71,71 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
63
71
  }
64
72
  return dragControlsBuffer;
65
73
  }
66
- /** Currently active and enabled DragControls components */
74
+ /** Registry of currently active and enabled DragControls components */
67
75
  private static _instances: DragControls[] = [];
68
76
 
69
-
70
-
71
- // dragPlane (floor, object, view)
72
- // snap to surface (snap orientation?)
73
- // two-handed drag (scale, rotate, move)
74
- // keep upright (no tilt)
75
-
76
- /** How and where the object is dragged along. */
77
+ /**
78
+ * Determines how and where the object is dragged along. Different modes include
79
+ * dragging along a plane, attached to the pointer, or following surface normals.
80
+ */
77
81
  @serializable()
78
82
  public dragMode: DragMode = DragMode.DynamicViewAngle;
79
83
 
80
- /** Snap dragged objects to a XYZ grid – 0 means: no snapping. */
84
+ /**
85
+ * Snaps dragged objects to a 3D grid with the specified resolution.
86
+ * Set to 0 to disable snapping.
87
+ */
81
88
  @serializable()
82
89
  public snapGridResolution: number = 0.0;
83
90
 
84
- /** Keep the original rotation of the dragged object. */
91
+ /**
92
+ * When true, maintains the original rotation of the dragged object while moving it.
93
+ * When false, allows the object to rotate freely during dragging.
94
+ */
85
95
  @serializable()
86
96
  public keepRotation: boolean = true;
87
97
 
88
- /** How and where the object is dragged along while dragging in XR. */
98
+ /**
99
+ * Determines how and where the object is dragged along while dragging in XR.
100
+ * Uses a separate setting from regular drag mode for better XR interaction.
101
+ */
89
102
  @serializable()
90
103
  public xrDragMode: DragMode = DragMode.Attached;
91
104
 
92
- /** Keep the original rotation of the dragged object while dragging in XR. */
105
+ /**
106
+ * When true, maintains the original rotation of the dragged object during XR dragging.
107
+ * When false, allows the object to rotate freely during XR dragging.
108
+ */
93
109
  @serializable()
94
110
  public xrKeepRotation: boolean = false;
95
111
 
96
- /** Accelerate dragging objects closer / further away when in XR */
112
+ /**
113
+ * Multiplier that affects how quickly objects move closer or further away when dragging in XR.
114
+ * Higher values make distance changes more pronounced.
115
+ * This is similar to mouse acceleration on a screen.
116
+ */
97
117
  @serializable()
98
118
  public xrDistanceDragFactor: number = 1;
99
119
 
100
- /** When enabled, draws a line from the dragged object downwards to the next raycast hit. */
120
+ /**
121
+ * When enabled, draws a visual line from the dragged object downwards to the next raycast hit,
122
+ * providing visual feedback about the object's position relative to surfaces below it.
123
+ */
101
124
  @serializable()
102
125
  public showGizmo: boolean = false;
103
126
 
104
- /** The currently dragged object (if any) */
127
+ /**
128
+ * Returns the object currently being dragged by this DragControls component, if any.
129
+ * @returns The object being dragged or null if no object is currently dragged
130
+ */
105
131
  get draggedObject() {
106
132
  return this._targetObject;
107
133
  }
108
134
 
109
135
  /**
110
- * Use to update the object that is being dragged by the DragControls
136
+ * Updates the object that is being dragged by the DragControls.
137
+ * This can be used to change the target during a drag operation.
138
+ * @param obj The new object to drag, or null to stop dragging
111
139
  */
112
140
  setTargetObject(obj: Object3D | null) {
113
141
  this._targetObject = obj;
@@ -133,8 +161,8 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
133
161
  this._rigidbody[wasKinematicKey] = false;
134
162
  }
135
163
  }
136
-
137
164
  }
165
+
138
166
  private _rigidbody: Rigidbody | null = null;
139
167
 
140
168
  // future:
@@ -182,11 +210,20 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
182
210
  DragControls._instances = DragControls._instances.filter(i => i !== this);
183
211
  }
184
212
 
213
+ /**
214
+ * Checks if editing is allowed for the current networking connection.
215
+ * @param _obj Optional object to check edit permissions for
216
+ * @returns True if editing is allowed
217
+ */
185
218
  private allowEdit(_obj: Object3D | null = null) {
186
219
  return this.context.connection.allowEditing;
187
220
  }
188
221
 
189
- /** @internal */
222
+ /**
223
+ * Handles pointer enter events. Sets the cursor style and tracks the hovered object.
224
+ * @param evt Pointer event data containing information about the interaction
225
+ * @internal
226
+ */
190
227
  onPointerEnter?(evt: PointerEventData) {
191
228
  if (!this.allowEdit(this.gameObject)) return;
192
229
  if (evt.mode !== "screen") return;
@@ -202,12 +239,20 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
202
239
  this.context.domElement.style.cursor = 'pointer';
203
240
  }
204
241
 
205
- /** @internal */
242
+ /**
243
+ * Handles pointer movement events. Marks the event as used if dragging is active.
244
+ * @param args Pointer event data containing information about the movement
245
+ * @internal
246
+ */
206
247
  onPointerMove?(args: PointerEventData) {
207
248
  if (this._isDragging || this._potentialDragStartEvt !== null) args.use();
208
249
  }
209
250
 
210
- /** @internal */
251
+ /**
252
+ * Handles pointer exit events. Resets the cursor style when the pointer leaves a draggable object.
253
+ * @param evt Pointer event data containing information about the interaction
254
+ * @internal
255
+ */
211
256
  onPointerExit?(evt: PointerEventData) {
212
257
  if (!this.allowEdit(this.gameObject)) return;
213
258
  if (evt.mode !== "screen") return;
@@ -215,7 +260,11 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
215
260
  this.context.domElement.style.cursor = 'auto';
216
261
  }
217
262
 
218
- /** @internal */
263
+ /**
264
+ * Handles pointer down events. Initiates the potential drag operation if conditions are met.
265
+ * @param args Pointer event data containing information about the interaction
266
+ * @internal
267
+ */
219
268
  onPointerDown(args: PointerEventData) {
220
269
  if (!this.allowEdit(this.gameObject)) return;
221
270
  if (args.used) return;
@@ -262,7 +311,11 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
262
311
  }
263
312
  }
264
313
 
265
- /** @internal */
314
+ /**
315
+ * Handles pointer up events. Finalizes or cancels the drag operation.
316
+ * @param args Pointer event data containing information about the interaction
317
+ * @internal
318
+ */
266
319
  onPointerUp(args: PointerEventData) {
267
320
  if (debug) Gizmos.DrawLabel(args.point ?? this.gameObject.worldPosition, "POINTERUP:" + args.pointerId + ", " + args.button, .03, 3);
268
321
  if (!this.allowEdit(this.gameObject)) return;
@@ -293,9 +346,12 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
293
346
  }
294
347
  }
295
348
 
296
- /** @internal */
349
+ /**
350
+ * Updates the drag operation every frame. Processes pointer movement, accumulates drag distance
351
+ * and triggers drag start once there's enough movement.
352
+ * @internal
353
+ */
297
354
  update(): void {
298
-
299
355
  for (const handler of this._dragHandlers.values()) {
300
356
  if (handler.collectMovementInfo) handler.collectMovementInfo();
301
357
  // TODO this doesn't make sense, we should instead just use the max here
@@ -324,7 +380,12 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
324
380
  this.onAnyDragUpdate();
325
381
  }
326
382
 
327
- /** Called when the first pointer starts dragging on this object. Not called for subsequent pointers on the same object. */
383
+ /**
384
+ * Called when the first pointer starts dragging on this object.
385
+ * Sets up network synchronization and marks rigidbodies for dragging.
386
+ * Not called for subsequent pointers on the same object.
387
+ * @param evt Pointer event data that initiated the drag
388
+ */
328
389
  private onFirstDragStart(evt: PointerEventData) {
329
390
  if (!evt || !evt.object) return;
330
391
 
@@ -356,7 +417,10 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
356
417
  this._draggingRigidbodies.push(...rbs);
357
418
  }
358
419
 
359
- /** Called each frame as long as any pointer is dragging this object. */
420
+ /**
421
+ * Called each frame as long as any pointer is dragging this object.
422
+ * Updates visuals and keeps rigidbodies awake during the drag.
423
+ */
360
424
  private onAnyDragUpdate() {
361
425
  if (!this._dragHelper) return;
362
426
  this._dragHelper.showGizmo = this.showGizmo;
@@ -373,7 +437,11 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
373
437
  InstancingUtil.markDirty(object);
374
438
  }
375
439
 
376
- /** Called when the last pointer has been removed from this object. */
440
+ /**
441
+ * Called when the last pointer has been removed from this object.
442
+ * Cleans up drag state and applies final velocities to rigidbodies.
443
+ * @param evt Pointer event data for the last pointer that was lifted
444
+ */
377
445
  private onLastDragEnd(evt: PointerEventData | null) {
378
446
  if (!this || !this._isDragging) return;
379
447
  this._isDragging = false;
@@ -399,7 +467,10 @@ export class DragControls extends Behaviour implements IPointerEventHandler {
399
467
  }
400
468
  }
401
469
 
402
- /** Common interface for pointer handlers (single touch and multi touch) */
470
+ /**
471
+ * Common interface for pointer handlers (single touch and multi touch).
472
+ * Defines methods for tracking movement and managing target objects during drag operations.
473
+ */
403
474
  interface IDragHandler {
404
475
  /** Used to determine if a drag has happened for this handler */
405
476
  getTotalMovement?(): Vector3;
@@ -414,7 +485,10 @@ interface IDragHandler {
414
485
  onDragUpdate?(numberOfPointers: number): void;
415
486
  }
416
487
 
417
- /** Handles two touch points affecting one object. Allows movement, scale and rotation of objects. */
488
+ /**
489
+ * Handles two touch points affecting one object.
490
+ * Enables multi-touch interactions that allow movement, scaling, and rotation of objects.
491
+ */
418
492
  class MultiTouchDragHandler implements IDragHandler {
419
493
 
420
494
  handlerA: DragPointerHandler;
@@ -660,15 +734,27 @@ class MultiTouchDragHandler implements IDragHandler {
660
734
  }
661
735
 
662
736
 
663
- /** Handles a single pointer on an object. DragPointerHandlers are created on pointer enter,
664
- * help with determining if there's actually a drag, and then perform operations based on spatial pointer data.
737
+ /**
738
+ * Handles a single pointer on an object.
739
+ * DragPointerHandlers manage determining if a drag operation has started, tracking pointer movement,
740
+ * and controlling object translation based on the drag mode.
665
741
  */
666
742
  class DragPointerHandler implements IDragHandler {
667
743
 
668
- /** Absolute movement of the pointer. Used for determining if a motion/drag is happening.
669
- * This is in world units, so very small for screens (near-plane space change) */
744
+ /**
745
+ * Returns the accumulated movement of the pointer in world units.
746
+ * Used for determining if enough motion has occurred to start a drag.
747
+ */
670
748
  getTotalMovement(): Vector3 { return this._totalMovement; }
749
+
750
+ /**
751
+ * Returns the object that follows the pointer during dragging operations.
752
+ */
671
753
  get followObject(): GameObject { return this._followObject; }
754
+
755
+ /**
756
+ * Returns the point where the pointer initially hit the object in local space.
757
+ */
672
758
  get hitPointInLocalSpace(): Vector3 { return this._hitPointInLocalSpace; }
673
759
 
674
760
  private context: Context;
@@ -1249,18 +1335,28 @@ class DragPointerHandler implements IDragHandler {
1249
1335
  }
1250
1336
  }
1251
1337
 
1252
- /** Currently does _only_ provide visuals support for DragControls operations.
1253
- * Previously it also provided the actual drag functionality, but that has been moved to DragControls for now.
1338
+ /**
1339
+ * Provides visual helper elements for DragControls.
1340
+ * Shows where objects will be placed and their relation to surfaces below them.
1254
1341
  */
1255
1342
  class LegacyDragVisualsHelper {
1256
1343
 
1344
+ /** Controls whether visual helpers like lines and markers are displayed */
1257
1345
  showGizmo: boolean = true;
1346
+
1347
+ /** When true, drag plane alignment changes based on view angle */
1258
1348
  useViewAngle: boolean = true;
1259
1349
 
1350
+ /**
1351
+ * Checks if there is a currently selected object being visualized
1352
+ */
1260
1353
  public get hasSelected(): boolean {
1261
1354
  return this._selected !== null && this._selected !== undefined;
1262
1355
  }
1263
1356
 
1357
+ /**
1358
+ * Returns the currently selected object being visualized, if any
1359
+ */
1264
1360
  public get selected(): Object3D | null {
1265
1361
  return this._selected;
1266
1362
  }