@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.
- package/CHANGELOG.md +9 -0
- package/components.needle.json +1 -1
- package/dist/needle-engine.bundle.js +4245 -2977
- package/dist/needle-engine.bundle.light.js +4236 -2968
- package/dist/needle-engine.bundle.light.min.js +73 -73
- package/dist/needle-engine.bundle.light.umd.cjs +61 -61
- package/dist/needle-engine.bundle.min.js +62 -62
- package/dist/needle-engine.bundle.umd.cjs +61 -61
- package/dist/needle-engine.light.d.ts +9 -9
- package/dist/three-examples.js +825 -794
- package/dist/three-examples.light.js +825 -794
- package/dist/three-examples.light.min.js +12 -12
- package/dist/three-examples.light.umd.cjs +10 -10
- package/dist/three-examples.min.js +12 -12
- package/dist/three-examples.umd.cjs +10 -10
- package/lib/engine/engine_addressables.d.ts +3 -0
- package/lib/engine/engine_addressables.js +18 -0
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_input.d.ts +20 -1
- package/lib/engine/engine_input.js.map +1 -1
- 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.d.ts +8 -0
- package/lib/engine-components/SceneSwitcher.js +72 -8
- 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/ui/EventSystem.d.ts +1 -0
- package/lib/engine-components/ui/EventSystem.js +8 -5
- package/lib/engine-components/ui/EventSystem.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/plugins/vite/alias.js +6 -3
- package/src/engine/engine_addressables.ts +21 -0
- package/src/engine/engine_input.ts +20 -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 +78 -9
- 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/ui/EventSystem.ts +9 -7
- package/src/engine-components/webxr/WebXR.ts +144 -27
- package/src/engine-components-experimental/networking/PlayerSync.ts +85 -13
|
@@ -15,6 +15,11 @@ import { Animator } from "./Animator.js";
|
|
|
15
15
|
const debug = getParam("debuganimatorcontroller");
|
|
16
16
|
const debugRootMotion = getParam("debugrootmotion");
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Generates a hash code for a string
|
|
20
|
+
* @param str - The string to hash
|
|
21
|
+
* @returns A numeric hash value
|
|
22
|
+
*/
|
|
18
23
|
function stringToHash(str): number {
|
|
19
24
|
let hash = 0;
|
|
20
25
|
for (let i = 0; i < str.length; i++) {
|
|
@@ -25,27 +30,38 @@ function stringToHash(str): number {
|
|
|
25
30
|
return hash;
|
|
26
31
|
}
|
|
27
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Configuration options for creating an AnimatorController
|
|
35
|
+
*/
|
|
28
36
|
declare type CreateAnimatorControllerOptions = {
|
|
29
|
-
/** Should each
|
|
37
|
+
/** Should each animation state loop */
|
|
30
38
|
looping?: boolean,
|
|
31
|
-
/** Set to false to disable generating transitions between
|
|
39
|
+
/** Set to false to disable generating transitions between animation clips */
|
|
32
40
|
autoTransition?: boolean,
|
|
33
|
-
/**
|
|
41
|
+
/** Duration in seconds for transitions between states */
|
|
34
42
|
transitionDuration?: number,
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
|
|
46
|
+
* Controls the playback of animations using a state machine architecture.
|
|
47
|
+
*
|
|
48
|
+
* The AnimatorController manages animation states, transitions between states,
|
|
49
|
+
* and parameters that affect those transitions. It is used by the {@link Animator}
|
|
50
|
+
* component to control animation behavior on 3D models.
|
|
51
|
+
*
|
|
52
|
+
* Use the static method {@link AnimatorController.createFromClips} to create
|
|
53
|
+
* an animator controller from a set of animation clips.
|
|
54
|
+
*/
|
|
42
55
|
export class AnimatorController {
|
|
43
56
|
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Creates an AnimatorController from a set of animation clips.
|
|
59
|
+
* Each clip becomes a state in the controller's state machine.
|
|
60
|
+
*
|
|
61
|
+
* @param clips - The animation clips to use for creating states
|
|
62
|
+
* @param options - Configuration options for the controller including looping behavior and transitions
|
|
63
|
+
* @returns A new AnimatorController instance
|
|
64
|
+
*/
|
|
49
65
|
static createFromClips(clips: AnimationClip[], options: CreateAnimatorControllerOptions = { looping: false, autoTransition: true, transitionDuration: 0 }): AnimatorController {
|
|
50
66
|
const states: State[] = [];
|
|
51
67
|
for (let i = 0; i < clips.length; i++) {
|
|
@@ -99,6 +115,14 @@ export class AnimatorController {
|
|
|
99
115
|
return controller;
|
|
100
116
|
}
|
|
101
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Plays an animation state by name or hash.
|
|
120
|
+
*
|
|
121
|
+
* @param name - The name or hash identifier of the state to play
|
|
122
|
+
* @param layerIndex - The layer index (defaults to 0)
|
|
123
|
+
* @param normalizedTime - The normalized time to start the animation from (0-1)
|
|
124
|
+
* @param durationInSec - Transition duration in seconds
|
|
125
|
+
*/
|
|
102
126
|
play(name: string | number, layerIndex: number = -1, normalizedTime: number = Number.NEGATIVE_INFINITY, durationInSec: number = 0) {
|
|
103
127
|
if (layerIndex < 0) layerIndex = 0;
|
|
104
128
|
else if (layerIndex >= this.model.layers.length) {
|
|
@@ -118,20 +142,42 @@ export class AnimatorController {
|
|
|
118
142
|
console.warn("Could not find " + name + " to play");
|
|
119
143
|
}
|
|
120
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Resets the controller to its initial state.
|
|
147
|
+
*/
|
|
121
148
|
reset() {
|
|
122
149
|
this.setStartTransition();
|
|
123
150
|
}
|
|
124
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Sets a boolean parameter value by name or hash.
|
|
154
|
+
*
|
|
155
|
+
* @param name - The name or hash identifier of the parameter
|
|
156
|
+
* @param value - The boolean value to set
|
|
157
|
+
*/
|
|
125
158
|
setBool(name: string | number, value: boolean) {
|
|
126
159
|
const key = typeof name === "string" ? "name" : "hash";
|
|
127
160
|
return this.model?.parameters?.filter(p => p[key] === name).forEach(p => p.value = value);
|
|
128
161
|
}
|
|
129
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Gets a boolean parameter value by name or hash.
|
|
165
|
+
*
|
|
166
|
+
* @param name - The name or hash identifier of the parameter
|
|
167
|
+
* @returns The boolean value of the parameter, or false if not found
|
|
168
|
+
*/
|
|
130
169
|
getBool(name: string | number): boolean {
|
|
131
170
|
const key = typeof name === "string" ? "name" : "hash";
|
|
132
171
|
return this.model?.parameters?.find(p => p[key] === name)?.value as boolean ?? false;
|
|
133
172
|
}
|
|
134
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Sets a float parameter value by name or hash.
|
|
176
|
+
*
|
|
177
|
+
* @param name - The name or hash identifier of the parameter
|
|
178
|
+
* @param val - The float value to set
|
|
179
|
+
* @returns True if the parameter was found and set, false otherwise
|
|
180
|
+
*/
|
|
135
181
|
setFloat(name: string | number, val: number) {
|
|
136
182
|
const key = typeof name === "string" ? "name" : "hash";
|
|
137
183
|
const filtered = this.model?.parameters?.filter(p => p[key] === name);
|
|
@@ -139,21 +185,45 @@ export class AnimatorController {
|
|
|
139
185
|
return filtered?.length > 0;
|
|
140
186
|
}
|
|
141
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Gets a float parameter value by name or hash.
|
|
190
|
+
*
|
|
191
|
+
* @param name - The name or hash identifier of the parameter
|
|
192
|
+
* @returns The float value of the parameter, or 0 if not found
|
|
193
|
+
*/
|
|
142
194
|
getFloat(name: string | number): number {
|
|
143
195
|
const key = typeof name === "string" ? "name" : "hash";
|
|
144
196
|
return this.model?.parameters?.find(p => p[key] === name)?.value as number ?? 0;
|
|
145
197
|
}
|
|
146
198
|
|
|
199
|
+
/**
|
|
200
|
+
* Sets an integer parameter value by name or hash.
|
|
201
|
+
*
|
|
202
|
+
* @param name - The name or hash identifier of the parameter
|
|
203
|
+
* @param val - The integer value to set
|
|
204
|
+
*/
|
|
147
205
|
setInteger(name: string | number, val: number) {
|
|
148
206
|
const key = typeof name === "string" ? "name" : "hash";
|
|
149
207
|
return this.model?.parameters?.filter(p => p[key] === name).forEach(p => p.value = val);
|
|
150
208
|
}
|
|
151
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Gets an integer parameter value by name or hash.
|
|
212
|
+
*
|
|
213
|
+
* @param name - The name or hash identifier of the parameter
|
|
214
|
+
* @returns The integer value of the parameter, or 0 if not found
|
|
215
|
+
*/
|
|
152
216
|
getInteger(name: string | number): number {
|
|
153
217
|
const key = typeof name === "string" ? "name" : "hash";
|
|
154
218
|
return this.model?.parameters?.find(p => p[key] === name)?.value as number ?? 0;
|
|
155
219
|
}
|
|
156
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Sets a trigger parameter to active (true).
|
|
223
|
+
* Trigger parameters are automatically reset after they are consumed by a transition.
|
|
224
|
+
*
|
|
225
|
+
* @param name - The name or hash identifier of the trigger parameter
|
|
226
|
+
*/
|
|
157
227
|
setTrigger(name: string | number) {
|
|
158
228
|
if (debug)
|
|
159
229
|
console.log("SET TRIGGER", name);
|
|
@@ -161,16 +231,32 @@ export class AnimatorController {
|
|
|
161
231
|
return this.model?.parameters?.filter(p => p[key] === name).forEach(p => p.value = true);
|
|
162
232
|
}
|
|
163
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Resets a trigger parameter to inactive (false).
|
|
236
|
+
*
|
|
237
|
+
* @param name - The name or hash identifier of the trigger parameter
|
|
238
|
+
*/
|
|
164
239
|
resetTrigger(name: string | number) {
|
|
165
240
|
const key = typeof name === "string" ? "name" : "hash";
|
|
166
241
|
return this.model?.parameters?.filter(p => p[key] === name).forEach(p => p.value = false);
|
|
167
242
|
}
|
|
168
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Gets the current state of a trigger parameter.
|
|
246
|
+
*
|
|
247
|
+
* @param name - The name or hash identifier of the trigger parameter
|
|
248
|
+
* @returns The boolean state of the trigger, or false if not found
|
|
249
|
+
*/
|
|
169
250
|
getTrigger(name: string | number): boolean {
|
|
170
251
|
const key = typeof name === "string" ? "name" : "hash";
|
|
171
252
|
return this.model?.parameters?.find(p => p[key] === name)?.value as boolean ?? false;
|
|
172
253
|
}
|
|
173
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Checks if the controller is currently in a transition between states.
|
|
257
|
+
*
|
|
258
|
+
* @returns True if a transition is in progress, false otherwise
|
|
259
|
+
*/
|
|
174
260
|
isInTransition(): boolean {
|
|
175
261
|
return this._activeStates.length > 1;
|
|
176
262
|
}
|
|
@@ -182,8 +268,21 @@ export class AnimatorController {
|
|
|
182
268
|
private _speed: number = 1;
|
|
183
269
|
|
|
184
270
|
|
|
185
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Finds an animation state by name or hash.
|
|
273
|
+
* @deprecated Use findState instead
|
|
274
|
+
*
|
|
275
|
+
* @param name - The name or hash identifier of the state to find
|
|
276
|
+
* @returns The found state or null if not found
|
|
277
|
+
*/
|
|
186
278
|
FindState(name: string | number | undefined | null): State | null { return this.findState(name); }
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Finds an animation state by name or hash.
|
|
282
|
+
*
|
|
283
|
+
* @param name - The name or hash identifier of the state to find
|
|
284
|
+
* @returns The found state or null if not found
|
|
285
|
+
*/
|
|
187
286
|
findState(name: string | number | undefined | null): State | null {
|
|
188
287
|
if (!name) return null;
|
|
189
288
|
if (Array.isArray(this.model.layers)) {
|
|
@@ -196,9 +295,11 @@ export class AnimatorController {
|
|
|
196
295
|
return null;
|
|
197
296
|
}
|
|
198
297
|
|
|
199
|
-
/**
|
|
200
|
-
*
|
|
201
|
-
|
|
298
|
+
/**
|
|
299
|
+
* Gets information about the current playing animation state.
|
|
300
|
+
*
|
|
301
|
+
* @returns An AnimatorStateInfo object with data about the current state, or null if no state is active
|
|
302
|
+
*/
|
|
202
303
|
getCurrentStateInfo() {
|
|
203
304
|
if (!this._activeState) return null;
|
|
204
305
|
const action = this._activeState.motion.action;
|
|
@@ -208,10 +309,11 @@ export class AnimatorController {
|
|
|
208
309
|
return new AnimatorStateInfo(this._activeState, normalizedTime, dur, this._speed);
|
|
209
310
|
}
|
|
210
311
|
|
|
211
|
-
/**
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
|
|
312
|
+
/**
|
|
313
|
+
* Gets the animation action currently playing.
|
|
314
|
+
*
|
|
315
|
+
* @returns The current animation action, or null if no action is playing
|
|
316
|
+
*/
|
|
215
317
|
get currentAction(): AnimationAction | null {
|
|
216
318
|
if (!this._activeState) return null;
|
|
217
319
|
const action = this._activeState.motion.action;
|
|
@@ -219,24 +321,37 @@ export class AnimatorController {
|
|
|
219
321
|
return action;
|
|
220
322
|
}
|
|
221
323
|
|
|
222
|
-
/**
|
|
324
|
+
/**
|
|
325
|
+
* The normalized time (0-1) to start playing the first state at.
|
|
326
|
+
* This affects the initial state when the animator is first enabled.
|
|
327
|
+
*/
|
|
223
328
|
normalizedStartOffset: number = 0;
|
|
224
329
|
|
|
225
|
-
/**
|
|
330
|
+
/**
|
|
331
|
+
* The Animator component this controller is bound to.
|
|
332
|
+
*/
|
|
226
333
|
animator?: Animator;
|
|
227
|
-
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* The data model describing the animation states and transitions.
|
|
337
|
+
*/
|
|
228
338
|
model: AnimatorControllerModel;
|
|
229
339
|
|
|
230
|
-
/**
|
|
340
|
+
/**
|
|
341
|
+
* Gets the engine context from the bound animator.
|
|
342
|
+
*/
|
|
231
343
|
get context(): Context | undefined | null { return this.animator?.context; }
|
|
232
344
|
|
|
233
|
-
/**
|
|
345
|
+
/**
|
|
346
|
+
* Gets the animation mixer used by this controller.
|
|
347
|
+
*/
|
|
234
348
|
get mixer() {
|
|
235
349
|
return this._mixer;
|
|
236
350
|
}
|
|
237
351
|
|
|
238
352
|
/**
|
|
239
|
-
*
|
|
353
|
+
* Cleans up resources used by this controller.
|
|
354
|
+
* Stops all animations and unregisters the mixer from the animation system.
|
|
240
355
|
*/
|
|
241
356
|
dispose() {
|
|
242
357
|
this._mixer.stopAllAction();
|
|
@@ -254,7 +369,12 @@ export class AnimatorController {
|
|
|
254
369
|
// // this.internalApplyRootMotion(obj);
|
|
255
370
|
// }
|
|
256
371
|
|
|
257
|
-
/**
|
|
372
|
+
/**
|
|
373
|
+
* Binds this controller to an animator component.
|
|
374
|
+
* Creates a new animation mixer and sets up animation actions.
|
|
375
|
+
*
|
|
376
|
+
* @param animator - The animator to bind this controller to
|
|
377
|
+
*/
|
|
258
378
|
bind(animator: Animator) {
|
|
259
379
|
if (!animator) console.error("AnimatorController.bind: animator is null");
|
|
260
380
|
else if (this.animator !== animator) {
|
|
@@ -269,7 +389,12 @@ export class AnimatorController {
|
|
|
269
389
|
}
|
|
270
390
|
}
|
|
271
391
|
|
|
272
|
-
/**
|
|
392
|
+
/**
|
|
393
|
+
* Creates a deep copy of this controller.
|
|
394
|
+
* Clones the model data but does not copy runtime state.
|
|
395
|
+
*
|
|
396
|
+
* @returns A new AnimatorController instance with the same configuration
|
|
397
|
+
*/
|
|
273
398
|
clone() {
|
|
274
399
|
if (typeof this.model === "string") {
|
|
275
400
|
console.warn("AnimatorController has not been resolved, can not create model from string", this.model);
|
|
@@ -297,7 +422,12 @@ export class AnimatorController {
|
|
|
297
422
|
return controller;
|
|
298
423
|
}
|
|
299
424
|
|
|
300
|
-
/**
|
|
425
|
+
/**
|
|
426
|
+
* Updates the controller's state machine and animations.
|
|
427
|
+
* Called each frame by the animator component.
|
|
428
|
+
*
|
|
429
|
+
* @param weight - The weight to apply to the animations (for blending)
|
|
430
|
+
*/
|
|
301
431
|
update(weight: number) {
|
|
302
432
|
if (!this.animator) return;
|
|
303
433
|
this.evaluateTransitions();
|
|
@@ -318,9 +448,11 @@ export class AnimatorController {
|
|
|
318
448
|
private _mixer!: AnimationMixer;
|
|
319
449
|
private _activeState?: State;
|
|
320
450
|
|
|
321
|
-
/**
|
|
322
|
-
*
|
|
323
|
-
|
|
451
|
+
/**
|
|
452
|
+
* Gets the currently active animation state.
|
|
453
|
+
*
|
|
454
|
+
* @returns The active state or undefined if no state is active
|
|
455
|
+
*/
|
|
324
456
|
get activeState(): State | undefined { return this._activeState; }
|
|
325
457
|
|
|
326
458
|
constructor(model: AnimatorControllerModel) {
|
|
@@ -770,6 +902,10 @@ export class AnimatorController {
|
|
|
770
902
|
}
|
|
771
903
|
}
|
|
772
904
|
|
|
905
|
+
/**
|
|
906
|
+
* Yields all animation actions managed by this controller.
|
|
907
|
+
* Iterates through all states in all layers and returns their actions.
|
|
908
|
+
*/
|
|
773
909
|
*enumerateActions() {
|
|
774
910
|
if (!this.model.layers) return;
|
|
775
911
|
for (const layer of this.model.layers) {
|
|
@@ -807,6 +943,10 @@ export class AnimatorController {
|
|
|
807
943
|
// }
|
|
808
944
|
}
|
|
809
945
|
|
|
946
|
+
/**
|
|
947
|
+
* Wraps a KeyframeTrack to allow custom evaluation of animation values.
|
|
948
|
+
* Used internally to modify animation behavior without changing the original data.
|
|
949
|
+
*/
|
|
810
950
|
class TrackEvaluationWrapper {
|
|
811
951
|
|
|
812
952
|
track?: KeyframeTrack;
|
|
@@ -844,6 +984,10 @@ class TrackEvaluationWrapper {
|
|
|
844
984
|
}
|
|
845
985
|
}
|
|
846
986
|
|
|
987
|
+
/**
|
|
988
|
+
* Handles root motion extraction from animation tracks.
|
|
989
|
+
* Captures movement from animations and applies it to the root object.
|
|
990
|
+
*/
|
|
847
991
|
class RootMotionAction {
|
|
848
992
|
|
|
849
993
|
private static lastObjPosition: { [key: string]: Vector3 } = {};
|
|
@@ -1043,6 +1187,10 @@ class RootMotionAction {
|
|
|
1043
1187
|
}
|
|
1044
1188
|
}
|
|
1045
1189
|
|
|
1190
|
+
/**
|
|
1191
|
+
* Manages root motion for a character.
|
|
1192
|
+
* Extracts motion from animation tracks and applies it to the character's transform.
|
|
1193
|
+
*/
|
|
1046
1194
|
class RootMotionHandler {
|
|
1047
1195
|
|
|
1048
1196
|
private controller: AnimatorController;
|
|
@@ -1129,8 +1277,10 @@ class RootMotionHandler {
|
|
|
1129
1277
|
}
|
|
1130
1278
|
}
|
|
1131
1279
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1280
|
+
/**
|
|
1281
|
+
* Serialization handler for AnimatorController instances.
|
|
1282
|
+
* Handles conversion between serialized data and runtime objects.
|
|
1283
|
+
*/
|
|
1134
1284
|
class AnimatorControllerSerializator extends TypeSerializer {
|
|
1135
1285
|
onSerialize(_: any, _context: SerializationContext) {
|
|
1136
1286
|
|
|
@@ -5,15 +5,18 @@ import { Camera } from "./Camera.js";
|
|
|
5
5
|
import { Behaviour, GameObject } from "./Component.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* AudioListener represents a listener that can
|
|
8
|
+
* AudioListener represents a listener that can hear audio sources in the scene.
|
|
9
|
+
* This component creates and manages a Three.js {@link three#AudioListener}, automatically connecting it
|
|
10
|
+
* to the main camera or a Camera in the parent hierarchy.
|
|
9
11
|
* @category Multimedia
|
|
10
12
|
* @group Components
|
|
11
13
|
*/
|
|
12
14
|
export class AudioListener extends Behaviour {
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
|
-
* Gets the existing or creates a new
|
|
16
|
-
*
|
|
17
|
+
* Gets the existing Three.js {@link three#AudioListener} instance or creates a new one if it doesn't exist.
|
|
18
|
+
* This listener is responsible for capturing audio in the 3D scene.
|
|
19
|
+
* @returns The {@link three#AudioListener} instance
|
|
17
20
|
*/
|
|
18
21
|
get listener(): ThreeAudioListener {
|
|
19
22
|
if (this._listener == null)
|
|
@@ -23,13 +26,21 @@ export class AudioListener extends Behaviour {
|
|
|
23
26
|
|
|
24
27
|
private _listener: ThreeAudioListener | null = null;
|
|
25
28
|
|
|
26
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Registers for interaction events and initializes the audio listener
|
|
31
|
+
* when this component is enabled.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
27
34
|
onEnable(): void {
|
|
28
35
|
Application.registerWaitForInteraction(this.onInteraction);
|
|
29
36
|
this.addListenerIfItExists();
|
|
30
37
|
}
|
|
31
38
|
|
|
32
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Cleans up event registrations and removes the audio listener
|
|
41
|
+
* when this component is disabled.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
33
44
|
onDisable(): void {
|
|
34
45
|
Application.unregisterWaitForInteraction(this.onInteraction);
|
|
35
46
|
this.removeListenerIfItExists();
|