@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.
- package/CHANGELOG.md +7 -0
- package/dist/needle-engine.bundle.js +6683 -5393
- package/dist/needle-engine.bundle.light.js +6687 -5397
- package/dist/needle-engine.bundle.light.min.js +121 -118
- package/dist/needle-engine.bundle.light.umd.cjs +128 -125
- package/dist/needle-engine.bundle.min.js +119 -116
- package/dist/needle-engine.bundle.umd.cjs +124 -121
- package/dist/needle-engine.d.ts +9 -9
- package/dist/needle-engine.light.d.ts +9 -9
- package/lib/engine/engine_context.js +1 -1
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.js +2 -4
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/engine_serialization_core.js +1 -1
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_types.d.ts +162 -17
- package/lib/engine/xr/NeedleXRSession.d.ts +6 -1
- package/lib/engine/xr/NeedleXRSession.js +6 -1
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- 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 +121 -40
- 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/particlesystem/ParticleSystem.js +1 -1
- package/lib/engine-components/particlesystem/ParticleSystem.js.map +1 -1
- package/lib/engine-components/webxr/WebARSessionRoot.d.ts +8 -3
- package/lib/engine-components/webxr/WebARSessionRoot.js +30 -9
- package/lib/engine-components/webxr/WebARSessionRoot.js.map +1 -1
- package/lib/engine-components/webxr/WebXR.d.ts +156 -25
- package/lib/engine-components/webxr/WebXR.js +160 -26
- 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_context.ts +1 -1
- package/src/engine/engine_mainloop_utils.ts +2 -4
- package/src/engine/engine_serialization_core.ts +1 -1
- package/src/engine/engine_types.ts +179 -18
- package/src/engine/xr/NeedleXRSession.ts +7 -1
- 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 +127 -39
- 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/particlesystem/ParticleSystem.ts +2 -2
- package/src/engine-components/webxr/WebARSessionRoot.ts +31 -8
- package/src/engine-components/webxr/WebXR.ts +173 -29
- package/src/engine-components-experimental/networking/PlayerSync.ts +85 -13
|
@@ -12,6 +12,7 @@ import { EventList } from "../../engine-components/EventList.js";
|
|
|
12
12
|
|
|
13
13
|
const debug = getParam("debugplayersync");
|
|
14
14
|
|
|
15
|
+
/** Type definition for a PlayerSync instance with a guaranteed asset property */
|
|
15
16
|
declare type PlayerSyncWithAsset = PlayerSync & Required<Pick<PlayerSync, "asset">>;
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -23,7 +24,10 @@ export class PlayerSync extends Behaviour {
|
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* This API is experimental and may change or be removed in the future.
|
|
26
|
-
*
|
|
27
|
+
* Creates a PlayerSync instance at runtime from a given URL and sets it up for networking
|
|
28
|
+
* @param url Path to the asset that should be instantiated for each player
|
|
29
|
+
* @param init Optional initialization parameters for the PlayerSync component
|
|
30
|
+
* @returns Promise resolving to a PlayerSync instance with a guaranteed asset property
|
|
27
31
|
* @example
|
|
28
32
|
* ```typescript
|
|
29
33
|
* const res = await PlayerSync.setupFrom("/assets/demo.glb");
|
|
@@ -47,15 +51,22 @@ export class PlayerSync extends Behaviour {
|
|
|
47
51
|
return ps as PlayerSyncWithAsset;
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* When enabled, PlayerSync will automatically load and instantiate the assigned asset when joining a networked room
|
|
56
|
+
*/
|
|
51
57
|
@serializable()
|
|
52
58
|
autoSync: boolean = true;
|
|
53
59
|
|
|
54
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* The asset that will be loaded and instantiated when PlayerSync becomes active and joins a networked room
|
|
62
|
+
*/
|
|
55
63
|
@serializable(AssetReference)
|
|
56
64
|
asset?: AssetReference;
|
|
57
65
|
|
|
58
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Event invoked when a player instance is spawned with the spawned {@link Object3D} as parameter
|
|
68
|
+
* @serializable
|
|
69
|
+
*/
|
|
59
70
|
@serializable(EventList)
|
|
60
71
|
onPlayerSpawned?: EventList<Object3D>;
|
|
61
72
|
|
|
@@ -86,6 +97,10 @@ export class PlayerSync extends Behaviour {
|
|
|
86
97
|
if (this.autoSync) this.getInstance();
|
|
87
98
|
}
|
|
88
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Gets or creates an instance of the assigned asset for the local player
|
|
102
|
+
* @returns Promise resolving to the instantiated player object or null if creation failed
|
|
103
|
+
*/
|
|
89
104
|
async getInstance() {
|
|
90
105
|
if (this._localInstance) return this._localInstance;
|
|
91
106
|
|
|
@@ -123,6 +138,9 @@ export class PlayerSync extends Behaviour {
|
|
|
123
138
|
return this._localInstance;
|
|
124
139
|
}
|
|
125
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Destroys the current player instance and cleans up networking state
|
|
143
|
+
*/
|
|
126
144
|
destroyInstance = () => {
|
|
127
145
|
this._localInstance?.then(go => {
|
|
128
146
|
if (debug) console.log("PlayerSync.destroyInstance", go);
|
|
@@ -131,8 +149,9 @@ export class PlayerSync extends Behaviour {
|
|
|
131
149
|
this._localInstance = undefined;
|
|
132
150
|
}
|
|
133
151
|
|
|
134
|
-
|
|
135
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Sets up visibility change listeners to handle player cleanup when browser tab visibility changes
|
|
154
|
+
*/
|
|
136
155
|
private watchTabVisible() {
|
|
137
156
|
window.addEventListener("visibilitychange", _ => {
|
|
138
157
|
if (document.visibilityState === "visible") {
|
|
@@ -147,32 +166,50 @@ export class PlayerSync extends Behaviour {
|
|
|
147
166
|
}
|
|
148
167
|
}
|
|
149
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Enum defining events that can be triggered by PlayerState
|
|
171
|
+
*/
|
|
150
172
|
export enum PlayerStateEvent {
|
|
173
|
+
/** Triggered when a PlayerState's owner property changes */
|
|
151
174
|
OwnerChanged = "ownerChanged",
|
|
152
175
|
}
|
|
153
176
|
|
|
177
|
+
/** Arguments passed when a PlayerState's owner changes */
|
|
154
178
|
export declare interface PlayerStateOwnerChangedArgs {
|
|
179
|
+
/** The PlayerState instance that changed */
|
|
155
180
|
playerState: PlayerState;
|
|
181
|
+
/** Previous owner's connection ID */
|
|
156
182
|
oldValue: string;
|
|
183
|
+
/** New owner's connection ID */
|
|
157
184
|
newValue: string;
|
|
158
185
|
}
|
|
159
186
|
|
|
187
|
+
/** Callback type for PlayerState events */
|
|
160
188
|
export declare type PlayerStateEventCallback = (args: CustomEvent<PlayerStateOwnerChangedArgs>) => void;
|
|
161
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Represents a player instance in the networked environment.
|
|
192
|
+
* Handles ownership, synchronization, and lifecycle management of player objects.
|
|
193
|
+
*/
|
|
162
194
|
export class PlayerState extends Behaviour {
|
|
163
195
|
|
|
164
196
|
private static _all: PlayerState[] = [];
|
|
165
|
-
/**
|
|
197
|
+
/** All PlayerState instances for all players in the scene */
|
|
166
198
|
static get all(): PlayerState[] {
|
|
167
199
|
return PlayerState._all;
|
|
168
200
|
};
|
|
169
201
|
|
|
170
202
|
private static _local: PlayerState[] = [];
|
|
171
|
-
/**
|
|
203
|
+
/** All PlayerState instances that belong to the local player */
|
|
172
204
|
static get local(): PlayerState[] {
|
|
173
205
|
return PlayerState._local;
|
|
174
206
|
}
|
|
175
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Gets the PlayerState component for a given object or component
|
|
210
|
+
* @param obj Object3D or Component to find the PlayerState for
|
|
211
|
+
* @returns The PlayerState component if found, undefined otherwise
|
|
212
|
+
*/
|
|
176
213
|
static getFor(obj: Object3D | Component) {
|
|
177
214
|
if (obj instanceof Object3D) {
|
|
178
215
|
return GameObject.getComponentInParent(obj, PlayerState);
|
|
@@ -183,22 +220,34 @@ export class PlayerState extends Behaviour {
|
|
|
183
220
|
return undefined;
|
|
184
221
|
}
|
|
185
222
|
|
|
186
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Checks if a given object or component belongs to the local player
|
|
225
|
+
* @param obj Object3D or Component to check
|
|
226
|
+
* @returns True if the object belongs to the local player, false otherwise
|
|
227
|
+
*/
|
|
187
228
|
static isLocalPlayer(obj: Object3D | Component): boolean {
|
|
188
229
|
const state = PlayerState.getFor(obj);
|
|
189
230
|
return state?.isLocalPlayer ?? false;
|
|
190
231
|
}
|
|
191
232
|
|
|
192
|
-
// static Callback
|
|
193
233
|
private static _callbacks: { [key: string]: PlayerStateEventCallback[] } = {};
|
|
194
234
|
/**
|
|
195
|
-
*
|
|
235
|
+
* Registers a callback for a specific PlayerState event
|
|
236
|
+
* @param event The event to listen for
|
|
237
|
+
* @param cb Callback function that will be invoked when the event occurs
|
|
238
|
+
* @returns The provided callback function for chaining
|
|
196
239
|
*/
|
|
197
240
|
static addEventListener(event: PlayerStateEvent, cb: PlayerStateEventCallback) {
|
|
198
241
|
if (!this._callbacks[event]) this._callbacks[event] = [];
|
|
199
242
|
this._callbacks[event].push(cb);
|
|
200
243
|
return cb;
|
|
201
244
|
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Removes a previously registered event callback
|
|
248
|
+
* @param event The event type to remove the callback from
|
|
249
|
+
* @param cb The callback function to remove
|
|
250
|
+
*/
|
|
202
251
|
static removeEventListener(event: PlayerStateEvent, cb: PlayerStateEventCallback) {
|
|
203
252
|
if (!this._callbacks[event]) return;
|
|
204
253
|
const index = this._callbacks[event].indexOf(cb);
|
|
@@ -212,20 +261,39 @@ export class PlayerState extends Behaviour {
|
|
|
212
261
|
}
|
|
213
262
|
|
|
214
263
|
|
|
264
|
+
/** Event triggered when the owner of this PlayerState changes */
|
|
215
265
|
public onOwnerChangeEvent = new EventList();
|
|
266
|
+
|
|
267
|
+
/** Event triggered the first time an owner is assigned to this PlayerState */
|
|
216
268
|
public onFirstOwnerChangeEvent = new EventList();
|
|
269
|
+
|
|
270
|
+
/** Indicates if this PlayerState has an owner assigned */
|
|
217
271
|
public hasOwner = false;
|
|
218
272
|
|
|
273
|
+
/**
|
|
274
|
+
* The connection ID of the player who owns this PlayerState instance
|
|
275
|
+
* @syncField Synchronized across the network
|
|
276
|
+
*/
|
|
219
277
|
@syncField(PlayerState.prototype.onOwnerChange)
|
|
220
278
|
owner?: string;
|
|
221
279
|
|
|
222
|
-
/**
|
|
280
|
+
/**
|
|
281
|
+
* When enabled, PlayerState will not destroy itself when the owner is not connected anymore
|
|
282
|
+
*/
|
|
223
283
|
dontDestroy: boolean = false;
|
|
224
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Indicates if this PlayerState belongs to the local player
|
|
287
|
+
*/
|
|
225
288
|
get isLocalPlayer(): boolean {
|
|
226
289
|
return this.owner === this.context.connection.connectionId;
|
|
227
290
|
}
|
|
228
291
|
|
|
292
|
+
/**
|
|
293
|
+
* Handles owner change events and updates relevant state
|
|
294
|
+
* @param newOwner The new owner's connection ID
|
|
295
|
+
* @param oldOwner The previous owner's connection ID
|
|
296
|
+
*/
|
|
229
297
|
private onOwnerChange(newOwner: string, oldOwner: string) {
|
|
230
298
|
if (debug) console.log(`PlayerSync.onOwnerChange: ${oldOwner} → ${newOwner} (me: ${this.context.connection.connectionId})`);
|
|
231
299
|
|
|
@@ -300,7 +368,7 @@ export class PlayerState extends Behaviour {
|
|
|
300
368
|
}
|
|
301
369
|
}
|
|
302
370
|
|
|
303
|
-
/**
|
|
371
|
+
/** Tells the server that this client has been destroyed, and the networking message for the instantiate will be removed */
|
|
304
372
|
doDestroy() {
|
|
305
373
|
if (debug) console.log("PlayerSync.doDestroy → syncDestroy", this.name);
|
|
306
374
|
syncDestroy(this.gameObject, this.context.connection, true, { saveInRoom: false });
|
|
@@ -319,6 +387,10 @@ export class PlayerState extends Behaviour {
|
|
|
319
387
|
}
|
|
320
388
|
}
|
|
321
389
|
|
|
390
|
+
/**
|
|
391
|
+
* Handler for when a user leaves the networked room
|
|
392
|
+
* @param model Object containing the ID of the user who left
|
|
393
|
+
*/
|
|
322
394
|
private onUserLeftRoom = (model: { userId: string }) => {
|
|
323
395
|
if (model.userId === this.owner) {
|
|
324
396
|
if (debug)
|