@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
|
@@ -3,78 +3,203 @@ import { Context } from "../engine/engine_setup.js";
|
|
|
3
3
|
import type { AnimatorControllerModel, State } from "../engine/extensions/NEEDLE_animator_controller_model.js";
|
|
4
4
|
import { AnimatorStateInfo } from "../engine/extensions/NEEDLE_animator_controller_model.js";
|
|
5
5
|
import { Animator } from "./Animator.js";
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for creating an AnimatorController
|
|
8
|
+
*/
|
|
6
9
|
declare type CreateAnimatorControllerOptions = {
|
|
7
|
-
/** Should each
|
|
10
|
+
/** Should each animation state loop */
|
|
8
11
|
looping?: boolean;
|
|
9
|
-
/** Set to false to disable generating transitions between
|
|
12
|
+
/** Set to false to disable generating transitions between animation clips */
|
|
10
13
|
autoTransition?: boolean;
|
|
11
|
-
/**
|
|
14
|
+
/** Duration in seconds for transitions between states */
|
|
12
15
|
transitionDuration?: number;
|
|
13
16
|
};
|
|
14
17
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
|
|
18
|
+
* Controls the playback of animations using a state machine architecture.
|
|
19
|
+
*
|
|
20
|
+
* The AnimatorController manages animation states, transitions between states,
|
|
21
|
+
* and parameters that affect those transitions. It is used by the {@link Animator}
|
|
22
|
+
* component to control animation behavior on 3D models.
|
|
23
|
+
*
|
|
24
|
+
* Use the static method {@link AnimatorController.createFromClips} to create
|
|
25
|
+
* an animator controller from a set of animation clips.
|
|
26
|
+
*/
|
|
19
27
|
export declare class AnimatorController {
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Creates an AnimatorController from a set of animation clips.
|
|
30
|
+
* Each clip becomes a state in the controller's state machine.
|
|
31
|
+
*
|
|
32
|
+
* @param clips - The animation clips to use for creating states
|
|
33
|
+
* @param options - Configuration options for the controller including looping behavior and transitions
|
|
34
|
+
* @returns A new AnimatorController instance
|
|
35
|
+
*/
|
|
25
36
|
static createFromClips(clips: AnimationClip[], options?: CreateAnimatorControllerOptions): AnimatorController;
|
|
37
|
+
/**
|
|
38
|
+
* Plays an animation state by name or hash.
|
|
39
|
+
*
|
|
40
|
+
* @param name - The name or hash identifier of the state to play
|
|
41
|
+
* @param layerIndex - The layer index (defaults to 0)
|
|
42
|
+
* @param normalizedTime - The normalized time to start the animation from (0-1)
|
|
43
|
+
* @param durationInSec - Transition duration in seconds
|
|
44
|
+
*/
|
|
26
45
|
play(name: string | number, layerIndex?: number, normalizedTime?: number, durationInSec?: number): void;
|
|
46
|
+
/**
|
|
47
|
+
* Resets the controller to its initial state.
|
|
48
|
+
*/
|
|
27
49
|
reset(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Sets a boolean parameter value by name or hash.
|
|
52
|
+
*
|
|
53
|
+
* @param name - The name or hash identifier of the parameter
|
|
54
|
+
* @param value - The boolean value to set
|
|
55
|
+
*/
|
|
28
56
|
setBool(name: string | number, value: boolean): void;
|
|
57
|
+
/**
|
|
58
|
+
* Gets a boolean parameter value by name or hash.
|
|
59
|
+
*
|
|
60
|
+
* @param name - The name or hash identifier of the parameter
|
|
61
|
+
* @returns The boolean value of the parameter, or false if not found
|
|
62
|
+
*/
|
|
29
63
|
getBool(name: string | number): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Sets a float parameter value by name or hash.
|
|
66
|
+
*
|
|
67
|
+
* @param name - The name or hash identifier of the parameter
|
|
68
|
+
* @param val - The float value to set
|
|
69
|
+
* @returns True if the parameter was found and set, false otherwise
|
|
70
|
+
*/
|
|
30
71
|
setFloat(name: string | number, val: number): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Gets a float parameter value by name or hash.
|
|
74
|
+
*
|
|
75
|
+
* @param name - The name or hash identifier of the parameter
|
|
76
|
+
* @returns The float value of the parameter, or 0 if not found
|
|
77
|
+
*/
|
|
31
78
|
getFloat(name: string | number): number;
|
|
79
|
+
/**
|
|
80
|
+
* Sets an integer parameter value by name or hash.
|
|
81
|
+
*
|
|
82
|
+
* @param name - The name or hash identifier of the parameter
|
|
83
|
+
* @param val - The integer value to set
|
|
84
|
+
*/
|
|
32
85
|
setInteger(name: string | number, val: number): void;
|
|
86
|
+
/**
|
|
87
|
+
* Gets an integer parameter value by name or hash.
|
|
88
|
+
*
|
|
89
|
+
* @param name - The name or hash identifier of the parameter
|
|
90
|
+
* @returns The integer value of the parameter, or 0 if not found
|
|
91
|
+
*/
|
|
33
92
|
getInteger(name: string | number): number;
|
|
93
|
+
/**
|
|
94
|
+
* Sets a trigger parameter to active (true).
|
|
95
|
+
* Trigger parameters are automatically reset after they are consumed by a transition.
|
|
96
|
+
*
|
|
97
|
+
* @param name - The name or hash identifier of the trigger parameter
|
|
98
|
+
*/
|
|
34
99
|
setTrigger(name: string | number): void;
|
|
100
|
+
/**
|
|
101
|
+
* Resets a trigger parameter to inactive (false).
|
|
102
|
+
*
|
|
103
|
+
* @param name - The name or hash identifier of the trigger parameter
|
|
104
|
+
*/
|
|
35
105
|
resetTrigger(name: string | number): void;
|
|
106
|
+
/**
|
|
107
|
+
* Gets the current state of a trigger parameter.
|
|
108
|
+
*
|
|
109
|
+
* @param name - The name or hash identifier of the trigger parameter
|
|
110
|
+
* @returns The boolean state of the trigger, or false if not found
|
|
111
|
+
*/
|
|
36
112
|
getTrigger(name: string | number): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Checks if the controller is currently in a transition between states.
|
|
115
|
+
*
|
|
116
|
+
* @returns True if a transition is in progress, false otherwise
|
|
117
|
+
*/
|
|
37
118
|
isInTransition(): boolean;
|
|
38
119
|
/** Set the speed of the animator controller. Larger values will make the animation play faster. */
|
|
39
120
|
setSpeed(speed: number): void;
|
|
40
121
|
private _speed;
|
|
41
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Finds an animation state by name or hash.
|
|
124
|
+
* @deprecated Use findState instead
|
|
125
|
+
*
|
|
126
|
+
* @param name - The name or hash identifier of the state to find
|
|
127
|
+
* @returns The found state or null if not found
|
|
128
|
+
*/
|
|
42
129
|
FindState(name: string | number | undefined | null): State | null;
|
|
130
|
+
/**
|
|
131
|
+
* Finds an animation state by name or hash.
|
|
132
|
+
*
|
|
133
|
+
* @param name - The name or hash identifier of the state to find
|
|
134
|
+
* @returns The found state or null if not found
|
|
135
|
+
*/
|
|
43
136
|
findState(name: string | number | undefined | null): State | null;
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Gets information about the current playing animation state.
|
|
139
|
+
*
|
|
140
|
+
* @returns An AnimatorStateInfo object with data about the current state, or null if no state is active
|
|
141
|
+
*/
|
|
47
142
|
getCurrentStateInfo(): AnimatorStateInfo | null;
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Gets the animation action currently playing.
|
|
145
|
+
*
|
|
146
|
+
* @returns The current animation action, or null if no action is playing
|
|
147
|
+
*/
|
|
52
148
|
get currentAction(): AnimationAction | null;
|
|
53
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* The normalized time (0-1) to start playing the first state at.
|
|
151
|
+
* This affects the initial state when the animator is first enabled.
|
|
152
|
+
*/
|
|
54
153
|
normalizedStartOffset: number;
|
|
55
|
-
/**
|
|
154
|
+
/**
|
|
155
|
+
* The Animator component this controller is bound to.
|
|
156
|
+
*/
|
|
56
157
|
animator?: Animator;
|
|
57
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* The data model describing the animation states and transitions.
|
|
160
|
+
*/
|
|
58
161
|
model: AnimatorControllerModel;
|
|
59
|
-
/**
|
|
162
|
+
/**
|
|
163
|
+
* Gets the engine context from the bound animator.
|
|
164
|
+
*/
|
|
60
165
|
get context(): Context | undefined | null;
|
|
61
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* Gets the animation mixer used by this controller.
|
|
168
|
+
*/
|
|
62
169
|
get mixer(): AnimationMixer;
|
|
63
170
|
/**
|
|
64
|
-
*
|
|
171
|
+
* Cleans up resources used by this controller.
|
|
172
|
+
* Stops all animations and unregisters the mixer from the animation system.
|
|
65
173
|
*/
|
|
66
174
|
dispose(): void;
|
|
67
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* Binds this controller to an animator component.
|
|
177
|
+
* Creates a new animation mixer and sets up animation actions.
|
|
178
|
+
*
|
|
179
|
+
* @param animator - The animator to bind this controller to
|
|
180
|
+
*/
|
|
68
181
|
bind(animator: Animator): void;
|
|
69
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Creates a deep copy of this controller.
|
|
184
|
+
* Clones the model data but does not copy runtime state.
|
|
185
|
+
*
|
|
186
|
+
* @returns A new AnimatorController instance with the same configuration
|
|
187
|
+
*/
|
|
70
188
|
clone(): AnimatorController | null;
|
|
71
|
-
/**
|
|
189
|
+
/**
|
|
190
|
+
* Updates the controller's state machine and animations.
|
|
191
|
+
* Called each frame by the animator component.
|
|
192
|
+
*
|
|
193
|
+
* @param weight - The weight to apply to the animations (for blending)
|
|
194
|
+
*/
|
|
72
195
|
update(weight: number): void;
|
|
73
196
|
private _mixer;
|
|
74
197
|
private _activeState?;
|
|
75
|
-
/**
|
|
76
|
-
*
|
|
77
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Gets the currently active animation state.
|
|
200
|
+
*
|
|
201
|
+
* @returns The active state or undefined if no state is active
|
|
202
|
+
*/
|
|
78
203
|
get activeState(): State | undefined;
|
|
79
204
|
constructor(model: AnimatorControllerModel);
|
|
80
205
|
private _activeStates;
|
|
@@ -92,6 +217,10 @@ export declare class AnimatorController {
|
|
|
92
217
|
private createAction;
|
|
93
218
|
private evaluateCondition;
|
|
94
219
|
private createActions;
|
|
220
|
+
/**
|
|
221
|
+
* Yields all animation actions managed by this controller.
|
|
222
|
+
* Iterates through all states in all layers and returns their actions.
|
|
223
|
+
*/
|
|
95
224
|
enumerateActions(): Generator<AnimationAction, void, unknown>;
|
|
96
225
|
private rootMotionHandler?;
|
|
97
226
|
}
|
|
@@ -9,6 +9,11 @@ import { deepClone, getParam } from "../engine/engine_utils.js";
|
|
|
9
9
|
import { AnimatorConditionMode, AnimatorControllerParameterType, AnimatorStateInfo, createMotion } from "../engine/extensions/NEEDLE_animator_controller_model.js";
|
|
10
10
|
const debug = getParam("debuganimatorcontroller");
|
|
11
11
|
const debugRootMotion = getParam("debugrootmotion");
|
|
12
|
+
/**
|
|
13
|
+
* Generates a hash code for a string
|
|
14
|
+
* @param str - The string to hash
|
|
15
|
+
* @returns A numeric hash value
|
|
16
|
+
*/
|
|
12
17
|
function stringToHash(str) {
|
|
13
18
|
let hash = 0;
|
|
14
19
|
for (let i = 0; i < str.length; i++) {
|
|
@@ -19,16 +24,24 @@ function stringToHash(str) {
|
|
|
19
24
|
return hash;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
27
|
+
* Controls the playback of animations using a state machine architecture.
|
|
28
|
+
*
|
|
29
|
+
* The AnimatorController manages animation states, transitions between states,
|
|
30
|
+
* and parameters that affect those transitions. It is used by the {@link Animator}
|
|
31
|
+
* component to control animation behavior on 3D models.
|
|
32
|
+
*
|
|
33
|
+
* Use the static method {@link AnimatorController.createFromClips} to create
|
|
34
|
+
* an animator controller from a set of animation clips.
|
|
35
|
+
*/
|
|
26
36
|
export class AnimatorController {
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Creates an AnimatorController from a set of animation clips.
|
|
39
|
+
* Each clip becomes a state in the controller's state machine.
|
|
40
|
+
*
|
|
41
|
+
* @param clips - The animation clips to use for creating states
|
|
42
|
+
* @param options - Configuration options for the controller including looping behavior and transitions
|
|
43
|
+
* @returns A new AnimatorController instance
|
|
44
|
+
*/
|
|
32
45
|
static createFromClips(clips, options = { looping: false, autoTransition: true, transitionDuration: 0 }) {
|
|
33
46
|
const states = [];
|
|
34
47
|
for (let i = 0; i < clips.length; i++) {
|
|
@@ -79,6 +92,14 @@ export class AnimatorController {
|
|
|
79
92
|
const controller = new AnimatorController(model);
|
|
80
93
|
return controller;
|
|
81
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Plays an animation state by name or hash.
|
|
97
|
+
*
|
|
98
|
+
* @param name - The name or hash identifier of the state to play
|
|
99
|
+
* @param layerIndex - The layer index (defaults to 0)
|
|
100
|
+
* @param normalizedTime - The normalized time to start the animation from (0-1)
|
|
101
|
+
* @param durationInSec - Transition duration in seconds
|
|
102
|
+
*/
|
|
82
103
|
play(name, layerIndex = -1, normalizedTime = Number.NEGATIVE_INFINITY, durationInSec = 0) {
|
|
83
104
|
if (layerIndex < 0)
|
|
84
105
|
layerIndex = 0;
|
|
@@ -98,49 +119,111 @@ export class AnimatorController {
|
|
|
98
119
|
}
|
|
99
120
|
console.warn("Could not find " + name + " to play");
|
|
100
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Resets the controller to its initial state.
|
|
124
|
+
*/
|
|
101
125
|
reset() {
|
|
102
126
|
this.setStartTransition();
|
|
103
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Sets a boolean parameter value by name or hash.
|
|
130
|
+
*
|
|
131
|
+
* @param name - The name or hash identifier of the parameter
|
|
132
|
+
* @param value - The boolean value to set
|
|
133
|
+
*/
|
|
104
134
|
setBool(name, value) {
|
|
105
135
|
const key = typeof name === "string" ? "name" : "hash";
|
|
106
136
|
return this.model?.parameters?.filter(p => p[key] === name).forEach(p => p.value = value);
|
|
107
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Gets a boolean parameter value by name or hash.
|
|
140
|
+
*
|
|
141
|
+
* @param name - The name or hash identifier of the parameter
|
|
142
|
+
* @returns The boolean value of the parameter, or false if not found
|
|
143
|
+
*/
|
|
108
144
|
getBool(name) {
|
|
109
145
|
const key = typeof name === "string" ? "name" : "hash";
|
|
110
146
|
return this.model?.parameters?.find(p => p[key] === name)?.value ?? false;
|
|
111
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Sets a float parameter value by name or hash.
|
|
150
|
+
*
|
|
151
|
+
* @param name - The name or hash identifier of the parameter
|
|
152
|
+
* @param val - The float value to set
|
|
153
|
+
* @returns True if the parameter was found and set, false otherwise
|
|
154
|
+
*/
|
|
112
155
|
setFloat(name, val) {
|
|
113
156
|
const key = typeof name === "string" ? "name" : "hash";
|
|
114
157
|
const filtered = this.model?.parameters?.filter(p => p[key] === name);
|
|
115
158
|
filtered.forEach(p => p.value = val);
|
|
116
159
|
return filtered?.length > 0;
|
|
117
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Gets a float parameter value by name or hash.
|
|
163
|
+
*
|
|
164
|
+
* @param name - The name or hash identifier of the parameter
|
|
165
|
+
* @returns The float value of the parameter, or 0 if not found
|
|
166
|
+
*/
|
|
118
167
|
getFloat(name) {
|
|
119
168
|
const key = typeof name === "string" ? "name" : "hash";
|
|
120
169
|
return this.model?.parameters?.find(p => p[key] === name)?.value ?? 0;
|
|
121
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Sets an integer parameter value by name or hash.
|
|
173
|
+
*
|
|
174
|
+
* @param name - The name or hash identifier of the parameter
|
|
175
|
+
* @param val - The integer value to set
|
|
176
|
+
*/
|
|
122
177
|
setInteger(name, val) {
|
|
123
178
|
const key = typeof name === "string" ? "name" : "hash";
|
|
124
179
|
return this.model?.parameters?.filter(p => p[key] === name).forEach(p => p.value = val);
|
|
125
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Gets an integer parameter value by name or hash.
|
|
183
|
+
*
|
|
184
|
+
* @param name - The name or hash identifier of the parameter
|
|
185
|
+
* @returns The integer value of the parameter, or 0 if not found
|
|
186
|
+
*/
|
|
126
187
|
getInteger(name) {
|
|
127
188
|
const key = typeof name === "string" ? "name" : "hash";
|
|
128
189
|
return this.model?.parameters?.find(p => p[key] === name)?.value ?? 0;
|
|
129
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Sets a trigger parameter to active (true).
|
|
193
|
+
* Trigger parameters are automatically reset after they are consumed by a transition.
|
|
194
|
+
*
|
|
195
|
+
* @param name - The name or hash identifier of the trigger parameter
|
|
196
|
+
*/
|
|
130
197
|
setTrigger(name) {
|
|
131
198
|
if (debug)
|
|
132
199
|
console.log("SET TRIGGER", name);
|
|
133
200
|
const key = typeof name === "string" ? "name" : "hash";
|
|
134
201
|
return this.model?.parameters?.filter(p => p[key] === name).forEach(p => p.value = true);
|
|
135
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Resets a trigger parameter to inactive (false).
|
|
205
|
+
*
|
|
206
|
+
* @param name - The name or hash identifier of the trigger parameter
|
|
207
|
+
*/
|
|
136
208
|
resetTrigger(name) {
|
|
137
209
|
const key = typeof name === "string" ? "name" : "hash";
|
|
138
210
|
return this.model?.parameters?.filter(p => p[key] === name).forEach(p => p.value = false);
|
|
139
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Gets the current state of a trigger parameter.
|
|
214
|
+
*
|
|
215
|
+
* @param name - The name or hash identifier of the trigger parameter
|
|
216
|
+
* @returns The boolean state of the trigger, or false if not found
|
|
217
|
+
*/
|
|
140
218
|
getTrigger(name) {
|
|
141
219
|
const key = typeof name === "string" ? "name" : "hash";
|
|
142
220
|
return this.model?.parameters?.find(p => p[key] === name)?.value ?? false;
|
|
143
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Checks if the controller is currently in a transition between states.
|
|
224
|
+
*
|
|
225
|
+
* @returns True if a transition is in progress, false otherwise
|
|
226
|
+
*/
|
|
144
227
|
isInTransition() {
|
|
145
228
|
return this._activeStates.length > 1;
|
|
146
229
|
}
|
|
@@ -149,8 +232,20 @@ export class AnimatorController {
|
|
|
149
232
|
this._speed = speed;
|
|
150
233
|
}
|
|
151
234
|
_speed = 1;
|
|
152
|
-
|
|
235
|
+
/**
|
|
236
|
+
* Finds an animation state by name or hash.
|
|
237
|
+
* @deprecated Use findState instead
|
|
238
|
+
*
|
|
239
|
+
* @param name - The name or hash identifier of the state to find
|
|
240
|
+
* @returns The found state or null if not found
|
|
241
|
+
*/
|
|
153
242
|
FindState(name) { return this.findState(name); }
|
|
243
|
+
/**
|
|
244
|
+
* Finds an animation state by name or hash.
|
|
245
|
+
*
|
|
246
|
+
* @param name - The name or hash identifier of the state to find
|
|
247
|
+
* @returns The found state or null if not found
|
|
248
|
+
*/
|
|
154
249
|
findState(name) {
|
|
155
250
|
if (!name)
|
|
156
251
|
return null;
|
|
@@ -164,9 +259,11 @@ export class AnimatorController {
|
|
|
164
259
|
}
|
|
165
260
|
return null;
|
|
166
261
|
}
|
|
167
|
-
/**
|
|
168
|
-
*
|
|
169
|
-
|
|
262
|
+
/**
|
|
263
|
+
* Gets information about the current playing animation state.
|
|
264
|
+
*
|
|
265
|
+
* @returns An AnimatorStateInfo object with data about the current state, or null if no state is active
|
|
266
|
+
*/
|
|
170
267
|
getCurrentStateInfo() {
|
|
171
268
|
if (!this._activeState)
|
|
172
269
|
return null;
|
|
@@ -177,10 +274,11 @@ export class AnimatorController {
|
|
|
177
274
|
const normalizedTime = dur <= 0 ? 0 : Math.abs(action.time / dur);
|
|
178
275
|
return new AnimatorStateInfo(this._activeState, normalizedTime, dur, this._speed);
|
|
179
276
|
}
|
|
180
|
-
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Gets the animation action currently playing.
|
|
279
|
+
*
|
|
280
|
+
* @returns The current animation action, or null if no action is playing
|
|
281
|
+
*/
|
|
184
282
|
get currentAction() {
|
|
185
283
|
if (!this._activeState)
|
|
186
284
|
return null;
|
|
@@ -189,20 +287,32 @@ export class AnimatorController {
|
|
|
189
287
|
return null;
|
|
190
288
|
return action;
|
|
191
289
|
}
|
|
192
|
-
/**
|
|
290
|
+
/**
|
|
291
|
+
* The normalized time (0-1) to start playing the first state at.
|
|
292
|
+
* This affects the initial state when the animator is first enabled.
|
|
293
|
+
*/
|
|
193
294
|
normalizedStartOffset = 0;
|
|
194
|
-
/**
|
|
295
|
+
/**
|
|
296
|
+
* The Animator component this controller is bound to.
|
|
297
|
+
*/
|
|
195
298
|
animator;
|
|
196
|
-
/**
|
|
299
|
+
/**
|
|
300
|
+
* The data model describing the animation states and transitions.
|
|
301
|
+
*/
|
|
197
302
|
model;
|
|
198
|
-
/**
|
|
303
|
+
/**
|
|
304
|
+
* Gets the engine context from the bound animator.
|
|
305
|
+
*/
|
|
199
306
|
get context() { return this.animator?.context; }
|
|
200
|
-
/**
|
|
307
|
+
/**
|
|
308
|
+
* Gets the animation mixer used by this controller.
|
|
309
|
+
*/
|
|
201
310
|
get mixer() {
|
|
202
311
|
return this._mixer;
|
|
203
312
|
}
|
|
204
313
|
/**
|
|
205
|
-
*
|
|
314
|
+
* Cleans up resources used by this controller.
|
|
315
|
+
* Stops all animations and unregisters the mixer from the animation system.
|
|
206
316
|
*/
|
|
207
317
|
dispose() {
|
|
208
318
|
this._mixer.stopAllAction();
|
|
@@ -218,7 +328,12 @@ export class AnimatorController {
|
|
|
218
328
|
// applyRootMotion(obj: Object3D) {
|
|
219
329
|
// // this.internalApplyRootMotion(obj);
|
|
220
330
|
// }
|
|
221
|
-
/**
|
|
331
|
+
/**
|
|
332
|
+
* Binds this controller to an animator component.
|
|
333
|
+
* Creates a new animation mixer and sets up animation actions.
|
|
334
|
+
*
|
|
335
|
+
* @param animator - The animator to bind this controller to
|
|
336
|
+
*/
|
|
222
337
|
bind(animator) {
|
|
223
338
|
if (!animator)
|
|
224
339
|
console.error("AnimatorController.bind: animator is null");
|
|
@@ -233,7 +348,12 @@ export class AnimatorController {
|
|
|
233
348
|
this.createActions(this.animator);
|
|
234
349
|
}
|
|
235
350
|
}
|
|
236
|
-
/**
|
|
351
|
+
/**
|
|
352
|
+
* Creates a deep copy of this controller.
|
|
353
|
+
* Clones the model data but does not copy runtime state.
|
|
354
|
+
*
|
|
355
|
+
* @returns A new AnimatorController instance with the same configuration
|
|
356
|
+
*/
|
|
237
357
|
clone() {
|
|
238
358
|
if (typeof this.model === "string") {
|
|
239
359
|
console.warn("AnimatorController has not been resolved, can not create model from string", this.model);
|
|
@@ -265,7 +385,12 @@ export class AnimatorController {
|
|
|
265
385
|
const controller = new AnimatorController(clonedModel);
|
|
266
386
|
return controller;
|
|
267
387
|
}
|
|
268
|
-
/**
|
|
388
|
+
/**
|
|
389
|
+
* Updates the controller's state machine and animations.
|
|
390
|
+
* Called each frame by the animator component.
|
|
391
|
+
*
|
|
392
|
+
* @param weight - The weight to apply to the animations (for blending)
|
|
393
|
+
*/
|
|
269
394
|
update(weight) {
|
|
270
395
|
if (!this.animator)
|
|
271
396
|
return;
|
|
@@ -284,9 +409,11 @@ export class AnimatorController {
|
|
|
284
409
|
}
|
|
285
410
|
_mixer;
|
|
286
411
|
_activeState;
|
|
287
|
-
/**
|
|
288
|
-
*
|
|
289
|
-
|
|
412
|
+
/**
|
|
413
|
+
* Gets the currently active animation state.
|
|
414
|
+
*
|
|
415
|
+
* @returns The active state or undefined if no state is active
|
|
416
|
+
*/
|
|
290
417
|
get activeState() { return this._activeState; }
|
|
291
418
|
constructor(model) {
|
|
292
419
|
this.model = model;
|
|
@@ -706,6 +833,10 @@ export class AnimatorController {
|
|
|
706
833
|
}
|
|
707
834
|
}
|
|
708
835
|
}
|
|
836
|
+
/**
|
|
837
|
+
* Yields all animation actions managed by this controller.
|
|
838
|
+
* Iterates through all states in all layers and returns their actions.
|
|
839
|
+
*/
|
|
709
840
|
*enumerateActions() {
|
|
710
841
|
if (!this.model.layers)
|
|
711
842
|
return;
|
|
@@ -725,6 +856,10 @@ export class AnimatorController {
|
|
|
725
856
|
// https://docs.unity3d.com/Manual/RootMotion.html
|
|
726
857
|
rootMotionHandler;
|
|
727
858
|
}
|
|
859
|
+
/**
|
|
860
|
+
* Wraps a KeyframeTrack to allow custom evaluation of animation values.
|
|
861
|
+
* Used internally to modify animation behavior without changing the original data.
|
|
862
|
+
*/
|
|
728
863
|
class TrackEvaluationWrapper {
|
|
729
864
|
track;
|
|
730
865
|
createdInterpolant;
|
|
@@ -759,6 +894,10 @@ class TrackEvaluationWrapper {
|
|
|
759
894
|
this.customEvaluate = undefined;
|
|
760
895
|
}
|
|
761
896
|
}
|
|
897
|
+
/**
|
|
898
|
+
* Handles root motion extraction from animation tracks.
|
|
899
|
+
* Captures movement from animations and applies it to the root object.
|
|
900
|
+
*/
|
|
762
901
|
class RootMotionAction {
|
|
763
902
|
static lastObjPosition = {};
|
|
764
903
|
static lastObjRotation = {};
|
|
@@ -922,6 +1061,10 @@ class RootMotionAction {
|
|
|
922
1061
|
return true;
|
|
923
1062
|
}
|
|
924
1063
|
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Manages root motion for a character.
|
|
1066
|
+
* Extracts motion from animation tracks and applies it to the character's transform.
|
|
1067
|
+
*/
|
|
925
1068
|
class RootMotionHandler {
|
|
926
1069
|
controller;
|
|
927
1070
|
handler = [];
|
|
@@ -993,6 +1136,10 @@ class RootMotionHandler {
|
|
|
993
1136
|
return null;
|
|
994
1137
|
}
|
|
995
1138
|
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Serialization handler for AnimatorController instances.
|
|
1141
|
+
* Handles conversion between serialized data and runtime objects.
|
|
1142
|
+
*/
|
|
996
1143
|
class AnimatorControllerSerializator extends TypeSerializer {
|
|
997
1144
|
onSerialize(_, _context) {
|
|
998
1145
|
}
|