@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.
- package/CHANGELOG.md +3 -0
- package/dist/needle-engine.bundle.js +1467 -222
- package/dist/needle-engine.bundle.light.js +1467 -222
- package/dist/needle-engine.bundle.light.min.js +32 -32
- package/dist/needle-engine.bundle.light.umd.cjs +3 -3
- package/dist/needle-engine.bundle.min.js +3 -3
- package/dist/needle-engine.bundle.umd.cjs +3 -3
- package/dist/needle-engine.light.d.ts +9 -9
- package/lib/engine/engine_types.d.ts +162 -17
- package/lib/engine-components/Animator.d.ts +129 -21
- package/lib/engine-components/Animator.js +115 -21
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AnimatorController.d.ts +161 -32
- package/lib/engine-components/AnimatorController.js +176 -29
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/AudioListener.d.ts +16 -5
- package/lib/engine-components/AudioListener.js +16 -5
- package/lib/engine-components/AudioListener.js.map +1 -1
- package/lib/engine-components/AudioSource.d.ts +120 -28
- package/lib/engine-components/AudioSource.js +120 -37
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/AvatarLoader.d.ts +61 -0
- package/lib/engine-components/AvatarLoader.js +61 -1
- package/lib/engine-components/AvatarLoader.js.map +1 -1
- package/lib/engine-components/AxesHelper.d.ts +19 -1
- package/lib/engine-components/AxesHelper.js +19 -1
- package/lib/engine-components/AxesHelper.js.map +1 -1
- package/lib/engine-components/BoxHelperComponent.d.ts +26 -0
- package/lib/engine-components/BoxHelperComponent.js +26 -0
- package/lib/engine-components/BoxHelperComponent.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +126 -37
- package/lib/engine-components/Camera.js +139 -37
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CameraUtils.js +20 -0
- package/lib/engine-components/CameraUtils.js.map +1 -1
- package/lib/engine-components/Collider.d.ts +95 -21
- package/lib/engine-components/Collider.js +100 -23
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +554 -106
- package/lib/engine-components/Component.js +352 -81
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/DragControls.d.ts +95 -21
- package/lib/engine-components/DragControls.js +126 -32
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/DropListener.d.ts +99 -16
- package/lib/engine-components/DropListener.js +119 -14
- package/lib/engine-components/DropListener.js.map +1 -1
- package/lib/engine-components/Light.d.ts +102 -5
- package/lib/engine-components/Light.js +102 -44
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/NeedleMenu.d.ts +28 -11
- package/lib/engine-components/NeedleMenu.js +28 -11
- package/lib/engine-components/NeedleMenu.js.map +1 -1
- package/lib/engine-components/Networking.d.ts +37 -5
- package/lib/engine-components/Networking.js +37 -5
- package/lib/engine-components/Networking.js.map +1 -1
- package/lib/engine-components/SceneSwitcher.js +44 -0
- package/lib/engine-components/SceneSwitcher.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.d.ts +66 -1
- package/lib/engine-components/SpatialTrigger.js +74 -2
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.d.ts +66 -4
- package/lib/engine-components/SpectatorCamera.js +132 -6
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SyncedTransform.d.ts +45 -6
- package/lib/engine-components/SyncedTransform.js +45 -6
- package/lib/engine-components/SyncedTransform.js.map +1 -1
- package/lib/engine-components/TransformGizmo.d.ts +49 -3
- package/lib/engine-components/TransformGizmo.js +49 -3
- package/lib/engine-components/TransformGizmo.js.map +1 -1
- package/lib/engine-components/webxr/WebXR.d.ts +131 -22
- package/lib/engine-components/webxr/WebXR.js +132 -23
- package/lib/engine-components/webxr/WebXR.js.map +1 -1
- package/lib/engine-components-experimental/networking/PlayerSync.d.ts +82 -9
- package/lib/engine-components-experimental/networking/PlayerSync.js +76 -11
- package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_types.ts +179 -18
- package/src/engine-components/Animator.ts +142 -22
- package/src/engine-components/AnimatorController.ts +184 -34
- package/src/engine-components/AudioListener.ts +16 -5
- package/src/engine-components/AudioSource.ts +126 -37
- package/src/engine-components/AvatarLoader.ts +61 -2
- package/src/engine-components/AxesHelper.ts +21 -1
- package/src/engine-components/BoxHelperComponent.ts +26 -0
- package/src/engine-components/Camera.ts +147 -41
- package/src/engine-components/CameraUtils.ts +20 -0
- package/src/engine-components/Collider.ts +102 -27
- package/src/engine-components/Component.ts +605 -129
- package/src/engine-components/DragControls.ts +134 -38
- package/src/engine-components/DropListener.ts +143 -23
- package/src/engine-components/Light.ts +105 -44
- package/src/engine-components/NeedleMenu.ts +29 -11
- package/src/engine-components/Networking.ts +37 -6
- package/src/engine-components/SceneSwitcher.ts +48 -1
- package/src/engine-components/SpatialTrigger.ts +80 -3
- package/src/engine-components/SpectatorCamera.ts +136 -18
- package/src/engine-components/SyncedTransform.ts +50 -7
- package/src/engine-components/TransformGizmo.ts +49 -4
- package/src/engine-components/webxr/WebXR.ts +144 -27
- 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
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
209
|
-
*
|
|
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
|
|
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
|
-
/**
|
|
222
|
-
*
|
|
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
|
-
|
|
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
|
|
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
|
}
|