@needle-tools/engine 4.3.0-alpha → 4.3.0-alpha.3

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 (122) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/needle-engine.bundle.js +6683 -5393
  3. package/dist/needle-engine.bundle.light.js +6687 -5397
  4. package/dist/needle-engine.bundle.light.min.js +121 -118
  5. package/dist/needle-engine.bundle.light.umd.cjs +128 -125
  6. package/dist/needle-engine.bundle.min.js +119 -116
  7. package/dist/needle-engine.bundle.umd.cjs +124 -121
  8. package/dist/needle-engine.d.ts +9 -9
  9. package/dist/needle-engine.light.d.ts +9 -9
  10. package/lib/engine/engine_context.js +1 -1
  11. package/lib/engine/engine_context.js.map +1 -1
  12. package/lib/engine/engine_mainloop_utils.js +2 -4
  13. package/lib/engine/engine_mainloop_utils.js.map +1 -1
  14. package/lib/engine/engine_serialization_core.js +1 -1
  15. package/lib/engine/engine_serialization_core.js.map +1 -1
  16. package/lib/engine/engine_types.d.ts +162 -17
  17. package/lib/engine/xr/NeedleXRSession.d.ts +6 -1
  18. package/lib/engine/xr/NeedleXRSession.js +6 -1
  19. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  20. package/lib/engine-components/Animator.d.ts +129 -21
  21. package/lib/engine-components/Animator.js +115 -21
  22. package/lib/engine-components/Animator.js.map +1 -1
  23. package/lib/engine-components/AnimatorController.d.ts +161 -32
  24. package/lib/engine-components/AnimatorController.js +176 -29
  25. package/lib/engine-components/AnimatorController.js.map +1 -1
  26. package/lib/engine-components/AudioListener.d.ts +16 -5
  27. package/lib/engine-components/AudioListener.js +16 -5
  28. package/lib/engine-components/AudioListener.js.map +1 -1
  29. package/lib/engine-components/AudioSource.d.ts +120 -28
  30. package/lib/engine-components/AudioSource.js +121 -40
  31. package/lib/engine-components/AudioSource.js.map +1 -1
  32. package/lib/engine-components/AvatarLoader.d.ts +61 -0
  33. package/lib/engine-components/AvatarLoader.js +61 -1
  34. package/lib/engine-components/AvatarLoader.js.map +1 -1
  35. package/lib/engine-components/AxesHelper.d.ts +19 -1
  36. package/lib/engine-components/AxesHelper.js +19 -1
  37. package/lib/engine-components/AxesHelper.js.map +1 -1
  38. package/lib/engine-components/BoxHelperComponent.d.ts +26 -0
  39. package/lib/engine-components/BoxHelperComponent.js +26 -0
  40. package/lib/engine-components/BoxHelperComponent.js.map +1 -1
  41. package/lib/engine-components/Camera.d.ts +126 -37
  42. package/lib/engine-components/Camera.js +139 -37
  43. package/lib/engine-components/Camera.js.map +1 -1
  44. package/lib/engine-components/CameraUtils.js +20 -0
  45. package/lib/engine-components/CameraUtils.js.map +1 -1
  46. package/lib/engine-components/Collider.d.ts +95 -21
  47. package/lib/engine-components/Collider.js +100 -23
  48. package/lib/engine-components/Collider.js.map +1 -1
  49. package/lib/engine-components/Component.d.ts +554 -106
  50. package/lib/engine-components/Component.js +352 -81
  51. package/lib/engine-components/Component.js.map +1 -1
  52. package/lib/engine-components/DragControls.d.ts +95 -21
  53. package/lib/engine-components/DragControls.js +126 -32
  54. package/lib/engine-components/DragControls.js.map +1 -1
  55. package/lib/engine-components/DropListener.d.ts +99 -16
  56. package/lib/engine-components/DropListener.js +119 -14
  57. package/lib/engine-components/DropListener.js.map +1 -1
  58. package/lib/engine-components/Light.d.ts +102 -5
  59. package/lib/engine-components/Light.js +102 -44
  60. package/lib/engine-components/Light.js.map +1 -1
  61. package/lib/engine-components/NeedleMenu.d.ts +28 -11
  62. package/lib/engine-components/NeedleMenu.js +28 -11
  63. package/lib/engine-components/NeedleMenu.js.map +1 -1
  64. package/lib/engine-components/Networking.d.ts +37 -5
  65. package/lib/engine-components/Networking.js +37 -5
  66. package/lib/engine-components/Networking.js.map +1 -1
  67. package/lib/engine-components/SceneSwitcher.js +44 -0
  68. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  69. package/lib/engine-components/SpatialTrigger.d.ts +66 -1
  70. package/lib/engine-components/SpatialTrigger.js +74 -2
  71. package/lib/engine-components/SpatialTrigger.js.map +1 -1
  72. package/lib/engine-components/SpectatorCamera.d.ts +66 -4
  73. package/lib/engine-components/SpectatorCamera.js +132 -6
  74. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  75. package/lib/engine-components/SyncedTransform.d.ts +45 -6
  76. package/lib/engine-components/SyncedTransform.js +45 -6
  77. package/lib/engine-components/SyncedTransform.js.map +1 -1
  78. package/lib/engine-components/TransformGizmo.d.ts +49 -3
  79. package/lib/engine-components/TransformGizmo.js +49 -3
  80. package/lib/engine-components/TransformGizmo.js.map +1 -1
  81. package/lib/engine-components/particlesystem/ParticleSystem.js +1 -1
  82. package/lib/engine-components/particlesystem/ParticleSystem.js.map +1 -1
  83. package/lib/engine-components/webxr/WebARSessionRoot.d.ts +8 -3
  84. package/lib/engine-components/webxr/WebARSessionRoot.js +30 -9
  85. package/lib/engine-components/webxr/WebARSessionRoot.js.map +1 -1
  86. package/lib/engine-components/webxr/WebXR.d.ts +156 -25
  87. package/lib/engine-components/webxr/WebXR.js +160 -26
  88. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  89. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +82 -9
  90. package/lib/engine-components-experimental/networking/PlayerSync.js +76 -11
  91. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  92. package/package.json +1 -1
  93. package/src/engine/engine_context.ts +1 -1
  94. package/src/engine/engine_mainloop_utils.ts +2 -4
  95. package/src/engine/engine_serialization_core.ts +1 -1
  96. package/src/engine/engine_types.ts +179 -18
  97. package/src/engine/xr/NeedleXRSession.ts +7 -1
  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 +127 -39
  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 +48 -1
  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/particlesystem/ParticleSystem.ts +2 -2
  120. package/src/engine-components/webxr/WebARSessionRoot.ts +31 -8
  121. package/src/engine-components/webxr/WebXR.ts +173 -29
  122. package/src/engine-components-experimental/networking/PlayerSync.ts +85 -13
@@ -1,59 +1,63 @@
1
1
  import { BufferGeometry, Group, Mesh, Object3D, Vector3 } from "three"
2
2
 
3
+ import { isDevEnvironment } from "../engine/debug/index.js";
3
4
  import { addComponent } from "../engine/engine_components.js";
4
5
  import { Gizmos } from "../engine/engine_gizmos.js";
5
6
  import type { PhysicsMaterial } from "../engine/engine_physics.types.js";
6
7
  import { serializable } from "../engine/engine_serialization_decorator.js";
7
- import { getBoundingBox, getWorldScale } from "../engine/engine_three_utils.js";
8
- // import { IColliderProvider, registerColliderProvider } from "../engine/engine_physics.js";
8
+ import { getBoundingBox } from "../engine/engine_three_utils.js";
9
9
  import type { IBoxCollider, ICollider, ISphereCollider } from "../engine/engine_types.js";
10
10
  import { validate } from "../engine/engine_util_decorator.js";
11
- import { unwatchWrite, watchWrite } from "../engine/engine_utils.js";
11
+ import { getParam, unwatchWrite, watchWrite } from "../engine/engine_utils.js";
12
12
  import { NEEDLE_progressive } from "../engine/extensions/NEEDLE_progressive.js";
13
13
  import { Behaviour } from "./Component.js";
14
14
  import { Rigidbody } from "./RigidBody.js";
15
15
 
16
16
  /**
17
17
  * Collider is the base class for all colliders. A collider is a physical shape that is used to detect collisions with other objects in the scene.
18
- * Colliders are used in combination with a Rigidbody to create physical interactions between objects.
18
+ * Colliders are used in combination with a {@link Rigidbody} to create physical interactions between objects.
19
19
  * Colliders are registered with the physics engine when they are enabled and removed when they are disabled.
20
20
  * @category Physics
21
21
  * @group Components
22
22
  */
23
23
  export class Collider extends Behaviour implements ICollider {
24
24
 
25
- /** @internal */
25
+ /**
26
+ * Identifies this component as a collider.
27
+ * @internal
28
+ */
26
29
  get isCollider(): any {
27
30
  return true;
28
31
  }
29
32
 
30
33
  /**
31
- * The Rigidbody that this collider is attached to.
34
+ * The {@link Rigidbody} that this collider is attached to. This handles the physics simulation for this collider.
32
35
  */
33
36
  @serializable(Rigidbody)
34
37
  attachedRigidbody: Rigidbody | null = null;
35
38
 
36
39
  /**
37
40
  * When `true` the collider will not be used for collision detection but will still trigger events.
41
+ * Trigger colliders can trigger events when other colliders enter their space, without creating a physical response/collision.
38
42
  */
39
43
  @serializable()
40
44
  isTrigger: boolean = false;
41
45
 
42
46
  /**
43
- * The physics material that is used for the collider. This material defines physical properties of the collider such as friction and bounciness.
47
+ * The physics material that defines physical properties of the collider such as friction and bounciness.
44
48
  */
45
49
  @serializable()
46
50
  sharedMaterial?: PhysicsMaterial;
47
51
 
48
52
  /**
49
- * The layers that the collider is assigned to.
53
+ * The layers that this collider belongs to. Used for filtering collision detection.
54
+ * @default [0]
50
55
  */
51
56
  @serializable()
52
57
  membership: number[] = [0];
53
58
 
54
59
  /**
55
- * The layers that the collider will interact with.
56
- * @inheritdoc
60
+ * The layers that this collider will interact with. Used for filtering collision detection.
57
61
  */
58
62
  @serializable()
59
63
  filter?: number[];
@@ -80,62 +84,91 @@ export class Collider extends Behaviour implements ICollider {
80
84
  this.context.physics.engine?.removeBody(this);
81
85
  }
82
86
 
83
- /** Returns the underlying physics body from the physics engine (if any) - the component must be enabled and active in the scene */
87
+ /**
88
+ * Returns the underlying physics body from the physics engine.
89
+ * Only available if the component is enabled and active in the scene.
90
+ */
84
91
  get body() {
85
92
  return this.context.physics.engine?.getBody(this);
86
93
  }
87
94
 
88
95
  /**
89
- * Apply the collider properties to the physics engine.
96
+ * Updates the collider's properties in the physics engine.
97
+ * Use this when you've changed collider properties and need to sync with the physics engine.
90
98
  */
91
99
  updateProperties = () => {
92
100
  this.context.physics.engine?.updateProperties(this);
93
101
  }
94
102
 
95
- /** Requests an update of the physics material in the physics engine */
103
+ /**
104
+ * Updates the physics material in the physics engine.
105
+ * Call this after changing the sharedMaterial property.
106
+ */
96
107
  updatePhysicsMaterial() {
97
108
  this.context.physics.engine?.updatePhysicsMaterial(this);
98
-
99
109
  }
100
110
  }
101
111
 
102
112
  /**
103
- * SphereCollider is a collider that represents a sphere shape.
113
+ * SphereCollider represents a sphere-shaped collision volume.
114
+ * Useful for objects that are roughly spherical in shape or need a simple collision boundary.
104
115
  * @category Physics
105
116
  * @group Components
106
117
  */
107
118
  export class SphereCollider extends Collider implements ISphereCollider {
108
119
 
120
+ /**
121
+ * The radius of the sphere collider.
122
+ */
109
123
  @validate()
110
124
  @serializable()
111
125
  radius: number = .5;
112
126
 
127
+ /**
128
+ * The center position of the sphere collider relative to the transform's position.
129
+ */
113
130
  @serializable(Vector3)
114
131
  center: Vector3 = new Vector3(0, 0, 0);
115
132
 
133
+ /**
134
+ * Registers the sphere collider with the physics engine and sets up scale change monitoring.
135
+ */
116
136
  onEnable() {
117
137
  super.onEnable();
118
138
  this.context.physics.engine?.addSphereCollider(this);
119
139
  watchWrite(this.gameObject.scale, this.updateProperties);
120
140
  }
121
141
 
142
+ /**
143
+ * Removes scale change monitoring when the collider is disabled.
144
+ */
122
145
  onDisable(): void {
123
146
  super.onDisable();
124
147
  unwatchWrite(this.gameObject.scale, this.updateProperties);
125
148
  }
126
149
 
150
+ /**
151
+ * Updates collider properties when validated in the editor or inspector.
152
+ */
127
153
  onValidate(): void {
128
154
  this.updateProperties();
129
155
  }
130
156
  }
131
157
 
132
158
  /**
133
- * BoxCollider is a collider that represents a box shape.
159
+ * BoxCollider represents a box-shaped collision volume.
160
+ * Ideal for rectangular objects or objects that need a simple cuboid collision boundary.
134
161
  * @category Physics
135
162
  * @group Components
136
163
  */
137
164
  export class BoxCollider extends Collider implements IBoxCollider {
138
165
 
166
+ /**
167
+ * Creates and adds a BoxCollider to the given object.
168
+ * @param obj The object to add the collider to
169
+ * @param opts Configuration options for the collider and optional rigidbody
170
+ * @returns The newly created BoxCollider
171
+ */
139
172
  static add(obj: Mesh | Object3D, opts?: { rigidbody: boolean, debug?: boolean }) {
140
173
  const collider = addComponent(obj, BoxCollider);
141
174
  collider.autoFit();
@@ -146,31 +179,51 @@ export class BoxCollider extends Collider implements IBoxCollider {
146
179
  return collider;
147
180
  }
148
181
 
182
+ /**
183
+ * The size of the box collider along each axis.
184
+ */
149
185
  @validate()
150
186
  @serializable(Vector3)
151
187
  size: Vector3 = new Vector3(1, 1, 1);
152
188
 
189
+ /**
190
+ * The center position of the box collider relative to the transform's position.
191
+ */
153
192
  @serializable(Vector3)
154
193
  center: Vector3 = new Vector3(0, 0, 0);
155
194
 
156
- /** @internal */
195
+ /**
196
+ * Registers the box collider with the physics engine and sets up scale change monitoring.
197
+ * @internal
198
+ */
157
199
  onEnable() {
158
200
  super.onEnable();
159
201
  this.context.physics.engine?.addBoxCollider(this, this.size);
160
202
  watchWrite(this.gameObject.scale, this.updateProperties);
161
203
  }
162
204
 
163
- /** @internal */
205
+ /**
206
+ * Removes scale change monitoring when the collider is disabled.
207
+ * @internal
208
+ */
164
209
  onDisable(): void {
165
210
  super.onDisable();
166
211
  unwatchWrite(this.gameObject.scale, this.updateProperties);
167
212
  }
168
213
 
169
- /** @internal */
214
+ /**
215
+ * Updates collider properties when validated in the editor or inspector.
216
+ * @internal
217
+ */
170
218
  onValidate(): void {
171
219
  this.updateProperties();
172
220
  }
173
221
 
222
+ /**
223
+ * Automatically fits the collider to the geometry of the object.
224
+ * Sets the size and center based on the object's bounding box.
225
+ * @param opts Options object with a debug flag to visualize the bounding box
226
+ */
174
227
  autoFit(opts?: { debug?: boolean }) {
175
228
  const obj = this.gameObject;
176
229
 
@@ -205,24 +258,31 @@ export class BoxCollider extends Collider implements IBoxCollider {
205
258
  }
206
259
 
207
260
  /**
208
- * MeshCollider is a collider that represents a mesh shape.
209
- * The mesh collider can be used to create a collider from a mesh.
261
+ * MeshCollider creates a collision shape from a mesh geometry.
262
+ * Allows for complex collision shapes that match the exact geometry of an object.
210
263
  * @category Physics
211
264
  * @group Components
212
265
  */
213
266
  export class MeshCollider extends Collider {
214
267
 
215
268
  /**
216
- * The mesh that is used for the collider.
269
+ * The mesh that is used to create the collision shape.
270
+ * If not set, the collider will try to use the mesh of the object it's attached to.
217
271
  */
218
272
  @serializable(Mesh)
219
273
  sharedMesh?: Mesh;
220
274
 
221
- /** When `true` the collider won't have holes or entrances.
222
- * If you wan't this mesh collider to be able to *contain* other objects this should be set to `false` */
275
+ /**
276
+ * When `true` the collider is treated as a solid object without holes.
277
+ * Set to `false` if you want this mesh collider to be able to contain other objects.
278
+ */
223
279
  @serializable()
224
280
  convex: boolean = false;
225
281
 
282
+ /**
283
+ * Creates and registers the mesh collider with the physics engine.
284
+ * Handles both individual meshes and mesh groups.
285
+ */
226
286
  onEnable() {
227
287
  super.onEnable();
228
288
  if (!this.context.physics.engine) return;
@@ -272,29 +332,44 @@ export class MeshCollider extends Collider {
272
332
  });
273
333
  }
274
334
  else {
275
- console.warn("A MeshCollider mesh is assigned, but it's neither a Mesh nor a Group. Please report a bug!", this, this.sharedMesh);
335
+ if (isDevEnvironment() || getParam("showcolliders")) {
336
+ console.warn(`[MeshCollider] A MeshCollider mesh is assigned to an unknown object on \"${this.gameObject.name}\", but it's neither a Mesh nor a Group. Please double check that you attached the collider component to the right object and report a bug otherwise!`, this);
337
+ }
276
338
  }
277
339
  }
278
340
  }
279
341
  }
280
342
 
281
343
  /**
282
- * CapsuleCollider is a collider that represents a capsule shape.
344
+ * CapsuleCollider represents a capsule-shaped collision volume (cylinder with hemispherical ends).
345
+ * Ideal for character controllers and objects that need a rounded collision shape.
283
346
  * @category Physics
284
347
  * @group Components
285
348
  */
286
349
  export class CapsuleCollider extends Collider {
350
+ /**
351
+ * The center position of the capsule collider relative to the transform's position.
352
+ */
287
353
  @serializable(Vector3)
288
354
  center: Vector3 = new Vector3(0, 0, 0);
289
355
 
356
+ /**
357
+ * The radius of the capsule's cylindrical body and hemispherical ends.
358
+ */
290
359
  @serializable()
291
360
  radius: number = .5;
361
+
362
+ /**
363
+ * The total height of the capsule including both hemispherical ends.
364
+ */
292
365
  @serializable()
293
366
  height: number = 2;
294
367
 
368
+ /**
369
+ * Registers the capsule collider with the physics engine.
370
+ */
295
371
  onEnable() {
296
372
  super.onEnable();
297
373
  this.context.physics.engine?.addCapsuleCollider(this, this.height, this.radius);
298
374
  }
299
-
300
375
  }