@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { QueryFilterFlags } from "@dimforge/rapier3d-compat";
|
|
1
|
+
import type { QueryFilterFlags, World } from "@dimforge/rapier3d-compat";
|
|
2
2
|
import { AnimationClip, Color, Material, Mesh, Object3D, Quaternion } from "three";
|
|
3
3
|
import { Vector3 } from "three";
|
|
4
4
|
import { type GLTF as THREE_GLTF } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
@@ -442,80 +442,241 @@ export class SphereOverlapResult {
|
|
|
442
442
|
|
|
443
443
|
|
|
444
444
|
export interface IPhysicsEngine {
|
|
445
|
+
/** Initializes the physics engine */
|
|
445
446
|
initialize(): Promise<boolean>;
|
|
447
|
+
/** Indicates whether the physics engine has been initialized */
|
|
446
448
|
get isInitialized(): boolean;
|
|
449
|
+
/** Advances physics simulation by the given time step */
|
|
447
450
|
step(dt: number): void;
|
|
448
451
|
postStep();
|
|
452
|
+
/** Indicates whether the physics engine is currently updating */
|
|
449
453
|
get isUpdating(): boolean;
|
|
450
|
-
/**
|
|
454
|
+
/** Clears all cached data (e.g., mesh data when creating scaled mesh colliders) */
|
|
451
455
|
clearCaches();
|
|
452
456
|
|
|
457
|
+
/** Enables or disables the physics engine */
|
|
453
458
|
enabled: boolean;
|
|
454
|
-
|
|
459
|
+
/** Returns the underlying physics world object */
|
|
460
|
+
get world(): World | undefined;
|
|
455
461
|
|
|
462
|
+
/** Sets the gravity vector for the physics simulation */
|
|
456
463
|
set gravity(vec3: Vec3);
|
|
464
|
+
/** Gets the current gravity vector */
|
|
457
465
|
get gravity(): Vec3;
|
|
458
466
|
|
|
459
|
-
/**
|
|
467
|
+
/**
|
|
468
|
+
* Gets the rapier physics body for a Needle component
|
|
469
|
+
* @param obj The collider or rigidbody component
|
|
470
|
+
* @returns The underlying physics body or null if not found
|
|
471
|
+
*/
|
|
460
472
|
getBody(obj: ICollider | IRigidbody): null | any;
|
|
461
|
-
/**
|
|
473
|
+
/**
|
|
474
|
+
* Gets the Needle Engine component for a rapier physics object
|
|
475
|
+
* @param rapierObject The rapier physics object
|
|
476
|
+
* @returns The associated component or null if not found
|
|
477
|
+
*/
|
|
462
478
|
getComponent(rapierObject: object): IComponent | null;
|
|
463
479
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
* @param origin
|
|
467
|
-
* @param direction
|
|
468
|
-
* @param options
|
|
480
|
+
/**
|
|
481
|
+
* Performs a fast raycast against physics colliders
|
|
482
|
+
* @param origin Ray origin in screen or worldspace
|
|
483
|
+
* @param direction Ray direction in worldspace
|
|
484
|
+
* @param options Additional raycast configuration options
|
|
485
|
+
* @returns Raycast result containing hit point and collider, or null if no hit
|
|
469
486
|
*/
|
|
470
487
|
raycast(origin?: Vec2 | Vec3, direction?: Vec3, options?: {
|
|
471
488
|
maxDistance?: number,
|
|
472
489
|
/** True if you want to also hit objects when the raycast starts from inside a collider */
|
|
473
490
|
solid?: boolean,
|
|
474
491
|
queryFilterFlags?: QueryFilterFlags,
|
|
475
|
-
/**
|
|
476
|
-
*
|
|
492
|
+
/**
|
|
493
|
+
* Raycast filter groups. Groups are used to apply the collision group rules for the scene query.
|
|
494
|
+
* The scene query will only consider hits with colliders with collision groups compatible with
|
|
495
|
+
* this collision group (using the bitwise test described in the collision groups section).
|
|
496
|
+
* For example membership 0x0001 and filter 0x0002 should be 0x00010002
|
|
497
|
+
* @see https://rapier.rs/docs/user_guides/javascript/colliders#collision-groups-and-solver-groups
|
|
498
|
+
*/
|
|
477
499
|
filterGroups?: number,
|
|
478
|
-
/**
|
|
500
|
+
/**
|
|
501
|
+
* Predicate to filter colliders in raycast results
|
|
502
|
+
* @param collider The collider being tested
|
|
503
|
+
* @returns False to ignore this collider, true to include it
|
|
504
|
+
*/
|
|
479
505
|
filterPredicate?: (collider: ICollider) => boolean
|
|
480
506
|
}): RaycastResult;
|
|
481
|
-
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Performs a raycast that also returns the normal vector at the hit point
|
|
510
|
+
* @param origin Ray origin in screen or worldspace
|
|
511
|
+
* @param direction Ray direction in worldspace
|
|
512
|
+
* @param options Additional raycast configuration options
|
|
513
|
+
* @returns Raycast result containing hit point, normal, and collider, or null if no hit
|
|
514
|
+
*/
|
|
482
515
|
raycastAndGetNormal(origin?: Vec2 | Vec3, direction?: Vec3, options?: {
|
|
483
516
|
maxDistance?: number,
|
|
484
517
|
/** True if you want to also hit objects when the raycast starts from inside a collider */
|
|
485
518
|
solid?: boolean,
|
|
486
519
|
queryFilterFlags?: QueryFilterFlags,
|
|
487
|
-
/**
|
|
488
|
-
*
|
|
520
|
+
/**
|
|
521
|
+
* Raycast filter groups. Groups are used to apply the collision group rules for the scene query.
|
|
522
|
+
* The scene query will only consider hits with colliders with collision groups compatible with
|
|
523
|
+
* this collision group (using the bitwise test described in the collision groups section).
|
|
524
|
+
* For example membership 0x0001 and filter 0x0002 should be 0x00010002
|
|
525
|
+
* @see https://rapier.rs/docs/user_guides/javascript/colliders#collision-groups-and-solver-groups
|
|
526
|
+
*/
|
|
489
527
|
filterGroups?: number,
|
|
490
|
-
/**
|
|
528
|
+
/**
|
|
529
|
+
* Predicate to filter colliders in raycast results
|
|
530
|
+
* @param collider The collider being tested
|
|
531
|
+
* @returns False to ignore this collider, true to include it
|
|
532
|
+
*/
|
|
491
533
|
filterPredicate?: (collider: ICollider) => boolean
|
|
492
534
|
}): RaycastResult;
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Finds all colliders within a sphere
|
|
538
|
+
* @param point The center point of the sphere
|
|
539
|
+
* @param radius The radius of the sphere
|
|
540
|
+
* @returns Array of objects that overlap with the sphere
|
|
541
|
+
*/
|
|
493
542
|
sphereOverlap(point: Vector3, radius: number): Array<SphereOverlapResult>;
|
|
494
543
|
|
|
495
544
|
// Collider methods
|
|
545
|
+
/**
|
|
546
|
+
* Adds a sphere collider to the physics world
|
|
547
|
+
* @param collider The collider component to add
|
|
548
|
+
*/
|
|
496
549
|
addSphereCollider(collider: ICollider);
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Adds a box collider to the physics world
|
|
553
|
+
* @param collider The collider component to add
|
|
554
|
+
* @param size The size of the box
|
|
555
|
+
*/
|
|
497
556
|
addBoxCollider(collider: ICollider, size: Vector3);
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Adds a capsule collider to the physics world
|
|
560
|
+
* @param collider The collider component to add
|
|
561
|
+
* @param radius The radius of the capsule
|
|
562
|
+
* @param height The height of the capsule
|
|
563
|
+
*/
|
|
498
564
|
addCapsuleCollider(collider: ICollider, radius: number, height: number);
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Adds a mesh collider to the physics world
|
|
568
|
+
* @param collider The collider component to add
|
|
569
|
+
* @param mesh The mesh to use for collision
|
|
570
|
+
* @param convex Whether the collision mesh should be treated as convex
|
|
571
|
+
* @param scale Optional scale to apply to the mesh
|
|
572
|
+
*/
|
|
499
573
|
addMeshCollider(collider: ICollider, mesh: Mesh, convex: boolean, scale?: Vector3 | undefined);
|
|
500
574
|
|
|
575
|
+
/**
|
|
576
|
+
* Updates the physics material properties of a collider
|
|
577
|
+
* @param collider The collider to update
|
|
578
|
+
*/
|
|
501
579
|
updatePhysicsMaterial(collider: ICollider);
|
|
502
580
|
|
|
503
581
|
// Rigidbody methods
|
|
582
|
+
/**
|
|
583
|
+
* Wakes up a sleeping rigidbody
|
|
584
|
+
* @param rb The rigidbody to wake up
|
|
585
|
+
*/
|
|
504
586
|
wakeup(rb: IRigidbody);
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Checks if a rigidbody is currently sleeping
|
|
590
|
+
* @param rb The rigidbody to check
|
|
591
|
+
* @returns Whether the rigidbody is sleeping or undefined if cannot be determined
|
|
592
|
+
*/
|
|
505
593
|
isSleeping(rb: IRigidbody): boolean | undefined;
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Updates the physical properties of a rigidbody or collider
|
|
597
|
+
* @param rb The rigidbody or collider to update
|
|
598
|
+
*/
|
|
506
599
|
updateProperties(rb: IRigidbody | ICollider);
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Resets all forces acting on a rigidbody
|
|
603
|
+
* @param rb The rigidbody to reset forces on
|
|
604
|
+
* @param wakeup Whether to wake up the rigidbody
|
|
605
|
+
*/
|
|
507
606
|
resetForces(rb: IRigidbody, wakeup: boolean);
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Resets all torques acting on a rigidbody
|
|
610
|
+
* @param rb The rigidbody to reset torques on
|
|
611
|
+
* @param wakeup Whether to wake up the rigidbody
|
|
612
|
+
*/
|
|
508
613
|
resetTorques(rb: IRigidbody, wakeup: boolean);
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Adds a continuous force to a rigidbody
|
|
617
|
+
* @param rb The rigidbody to add force to
|
|
618
|
+
* @param vec The force vector to add
|
|
619
|
+
* @param wakeup Whether to wake up the rigidbody
|
|
620
|
+
*/
|
|
509
621
|
addForce(rb: IRigidbody, vec: Vec3, wakeup: boolean);
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Applies an instantaneous impulse to a rigidbody
|
|
625
|
+
* @param rb The rigidbody to apply impulse to
|
|
626
|
+
* @param vec The impulse vector to apply
|
|
627
|
+
* @param wakeup Whether to wake up the rigidbody
|
|
628
|
+
*/
|
|
510
629
|
applyImpulse(rb: IRigidbody, vec: Vec3, wakeup: boolean);
|
|
511
|
-
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Gets the linear velocity of a rigidbody or the rigidbody attached to a collider
|
|
633
|
+
* @param rb The rigidbody or collider to get velocity from
|
|
634
|
+
* @returns The linear velocity vector or null if not available
|
|
635
|
+
*/
|
|
512
636
|
getLinearVelocity(rb: IRigidbody | ICollider): Vec3 | null;
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Gets the angular velocity of a rigidbody
|
|
640
|
+
* @param rb The rigidbody to get angular velocity from
|
|
641
|
+
* @returns The angular velocity vector or null if not available
|
|
642
|
+
*/
|
|
513
643
|
getAngularVelocity(rb: IRigidbody): Vec3 | null;
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Sets the angular velocity of a rigidbody
|
|
647
|
+
* @param rb The rigidbody to set angular velocity for
|
|
648
|
+
* @param vec The angular velocity vector to set
|
|
649
|
+
* @param wakeup Whether to wake up the rigidbody
|
|
650
|
+
*/
|
|
514
651
|
setAngularVelocity(rb: IRigidbody, vec: Vec3, wakeup: boolean);
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Sets the linear velocity of a rigidbody
|
|
655
|
+
* @param rb The rigidbody to set linear velocity for
|
|
656
|
+
* @param vec The linear velocity vector to set
|
|
657
|
+
* @param wakeup Whether to wake up the rigidbody
|
|
658
|
+
*/
|
|
515
659
|
setLinearVelocity(rb: IRigidbody, vec: Vec3, wakeup: boolean);
|
|
516
660
|
|
|
661
|
+
/**
|
|
662
|
+
* Updates the position and/or rotation of a physics body
|
|
663
|
+
* @param comp The collider or rigidbody component to update
|
|
664
|
+
* @param translation Whether to update the position
|
|
665
|
+
* @param rotation Whether to update the rotation
|
|
666
|
+
*/
|
|
517
667
|
updateBody(comp: ICollider | IRigidbody, translation: boolean, rotation: boolean);
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Removes a physics body from the simulation
|
|
671
|
+
* @param body The component whose physics body should be removed
|
|
672
|
+
*/
|
|
518
673
|
removeBody(body: IComponent);
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Gets the physics body for a component
|
|
677
|
+
* @param obj The collider or rigidbody component
|
|
678
|
+
* @returns The underlying physics body or null if not found
|
|
679
|
+
*/
|
|
519
680
|
getBody(obj: ICollider | IRigidbody): null | any;
|
|
520
681
|
|
|
521
682
|
// Joints
|
|
@@ -11,38 +11,73 @@ import { Behaviour } from "./Component.js";
|
|
|
11
11
|
|
|
12
12
|
const debug = getParam("debuganimator");
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Represents an event emitted by an animation mixer
|
|
16
|
+
* @category Animation and Sequencing
|
|
17
|
+
*/
|
|
15
18
|
export declare class MixerEvent {
|
|
19
|
+
/** The type of event that occurred */
|
|
16
20
|
type: string;
|
|
21
|
+
/** The animation action that triggered this event */
|
|
17
22
|
action: AnimationAction;
|
|
23
|
+
/** Number of loops completed in this cycle */
|
|
18
24
|
loopDelta: number;
|
|
25
|
+
/** The animation mixer that emitted this event */
|
|
19
26
|
target: AnimationMixer;
|
|
20
27
|
}
|
|
21
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Configuration options for playing animations
|
|
31
|
+
* @category Animation and Sequencing
|
|
32
|
+
*/
|
|
22
33
|
export declare class PlayOptions {
|
|
34
|
+
/** Whether the animation should loop, and if so, which loop style to use */
|
|
23
35
|
loop?: boolean | AnimationActionLoopStyles;
|
|
36
|
+
/** Whether the final animation state should be maintained after playback completes */
|
|
24
37
|
clampWhenFinished?: boolean;
|
|
25
38
|
}
|
|
26
39
|
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
40
|
+
/**
|
|
41
|
+
* The Animator component plays and manages animations on a GameObject.
|
|
42
|
+
* It works with an AnimatorController to handle state transitions and animation blending.
|
|
43
|
+
* A new AnimatorController can be created from code via `AnimatorController.createFromClips`.
|
|
29
44
|
* @category Animation and Sequencing
|
|
30
45
|
* @group Components
|
|
31
46
|
*/
|
|
32
47
|
export class Animator extends Behaviour implements IAnimationComponent {
|
|
33
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Identifies this component as an animation component in the engine
|
|
51
|
+
*/
|
|
34
52
|
get isAnimationComponent() {
|
|
35
53
|
return true;
|
|
36
54
|
}
|
|
37
55
|
|
|
56
|
+
/**
|
|
57
|
+
* When enabled, animation will affect the root transform position and rotation
|
|
58
|
+
*/
|
|
38
59
|
@serializable()
|
|
39
60
|
applyRootMotion: boolean = false;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Indicates whether this animator contains root motion data
|
|
64
|
+
*/
|
|
40
65
|
@serializable()
|
|
41
66
|
hasRootMotion: boolean = false;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* When enabled, the animator will maintain its state when the component is disabled
|
|
70
|
+
*/
|
|
42
71
|
@serializable()
|
|
43
72
|
keepAnimatorControllerStateOnDisable: boolean = false;
|
|
44
73
|
|
|
45
74
|
// set from needle animator extension
|
|
75
|
+
/**
|
|
76
|
+
* Sets or replaces the animator controller for this component.
|
|
77
|
+
* Handles binding the controller to this animator instance and ensures
|
|
78
|
+
* proper initialization when the controller changes.
|
|
79
|
+
* @param val The animator controller model or instance to use
|
|
80
|
+
*/
|
|
46
81
|
@serializable()
|
|
47
82
|
set runtimeAnimatorController(val: AnimatorControllerModel | AnimatorController | undefined | null) {
|
|
48
83
|
if (this._animatorController && this._animatorController.model === val) {
|
|
@@ -69,41 +104,53 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
69
104
|
}
|
|
70
105
|
else this._animatorController = null;
|
|
71
106
|
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Gets the current animator controller instance
|
|
110
|
+
* @returns The current animator controller or null if none is assigned
|
|
111
|
+
*/
|
|
72
112
|
get runtimeAnimatorController(): AnimatorController | undefined | null {
|
|
73
113
|
return this._animatorController;
|
|
74
114
|
}
|
|
75
115
|
|
|
76
|
-
/**
|
|
77
|
-
*
|
|
78
|
-
* @returns
|
|
79
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves information about the current animation state
|
|
118
|
+
* @returns The current state information, or undefined if no state is playing
|
|
119
|
+
*/
|
|
80
120
|
getCurrentStateInfo() {
|
|
81
121
|
return this.runtimeAnimatorController?.getCurrentStateInfo();
|
|
82
122
|
}
|
|
83
|
-
/**
|
|
84
|
-
*
|
|
85
|
-
|
|
123
|
+
/**
|
|
124
|
+
* The currently playing animation action that can be used to modify animation properties
|
|
125
|
+
* @returns The current animation action, or null if no animation is playing
|
|
126
|
+
*/
|
|
86
127
|
get currentAction() {
|
|
87
128
|
return this.runtimeAnimatorController?.currentAction || null;
|
|
88
129
|
}
|
|
89
130
|
|
|
90
|
-
/**
|
|
131
|
+
/**
|
|
132
|
+
* Indicates whether animation parameters have been modified since the last update
|
|
133
|
+
* @returns True if parameters have been changed
|
|
134
|
+
*/
|
|
91
135
|
get parametersAreDirty() { return this._parametersAreDirty; }
|
|
92
136
|
private _parametersAreDirty: boolean = false;
|
|
93
137
|
|
|
94
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* Indicates whether the animator state has changed since the last update
|
|
140
|
+
* @returns True if the animator has been changed
|
|
141
|
+
*/
|
|
95
142
|
get isDirty() { return this._isDirty; }
|
|
96
143
|
private _isDirty: boolean = false;
|
|
97
144
|
|
|
98
145
|
/**@deprecated use play() */
|
|
99
146
|
Play(name: string | number, layer: number = -1, normalizedTime: number = Number.NEGATIVE_INFINITY, transitionDurationInSec: number = 0) { this.play(name, layer, normalizedTime, transitionDurationInSec); }
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* @param
|
|
103
|
-
* @param
|
|
104
|
-
* @param
|
|
105
|
-
* @
|
|
106
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Plays an animation on the animator
|
|
149
|
+
* @param name The name or hash of the animation to play
|
|
150
|
+
* @param layer The layer to play the animation on (-1 for default layer)
|
|
151
|
+
* @param normalizedTime The time position to start playing (0-1 range, NEGATIVE_INFINITY for current position)
|
|
152
|
+
* @param transitionDurationInSec The duration of the blend transition in seconds
|
|
153
|
+
*/
|
|
107
154
|
play(name: string | number, layer: number = -1, normalizedTime: number = Number.NEGATIVE_INFINITY, transitionDurationInSec: number = 0) {
|
|
108
155
|
this.runtimeAnimatorController?.play(name, layer, normalizedTime, transitionDurationInSec);
|
|
109
156
|
this._isDirty = true;
|
|
@@ -111,7 +158,9 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
111
158
|
|
|
112
159
|
/**@deprecated use reset */
|
|
113
160
|
Reset() { this.reset(); }
|
|
114
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* Resets the animator controller to its initial state
|
|
163
|
+
*/
|
|
115
164
|
reset() {
|
|
116
165
|
this._animatorController?.reset();
|
|
117
166
|
this._isDirty = true;
|
|
@@ -119,6 +168,12 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
119
168
|
|
|
120
169
|
/**@deprecated use setBool */
|
|
121
170
|
SetBool(name: string | number, val: boolean) { this.setBool(name, val); }
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Sets a boolean parameter in the animator
|
|
174
|
+
* @param name The name or hash of the parameter
|
|
175
|
+
* @param value The boolean value to set
|
|
176
|
+
*/
|
|
122
177
|
setBool(name: string | number, value: boolean) {
|
|
123
178
|
if (debug) console.log("setBool", name, value);
|
|
124
179
|
if (this.runtimeAnimatorController?.getBool(name) !== value)
|
|
@@ -128,18 +183,34 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
128
183
|
|
|
129
184
|
/**@deprecated use getBool */
|
|
130
185
|
GetBool(name: string | number) { return this.getBool(name); }
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Gets a boolean parameter from the animator
|
|
189
|
+
* @param name The name or hash of the parameter
|
|
190
|
+
* @returns The value of the boolean parameter, or false if not found
|
|
191
|
+
*/
|
|
131
192
|
getBool(name: string | number): boolean {
|
|
132
193
|
const res = this.runtimeAnimatorController?.getBool(name) ?? false;
|
|
133
194
|
if (debug) console.log("getBool", name, res);
|
|
134
195
|
return res;
|
|
135
196
|
}
|
|
136
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Toggles a boolean parameter between true and false
|
|
200
|
+
* @param name The name or hash of the parameter
|
|
201
|
+
*/
|
|
137
202
|
toggleBool(name: string | number) {
|
|
138
203
|
this.setBool(name, !this.getBool(name));
|
|
139
204
|
}
|
|
140
205
|
|
|
141
206
|
/**@deprecated use setFloat */
|
|
142
207
|
SetFloat(name: string | number, val: number) { this.setFloat(name, val); }
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Sets a float parameter in the animator
|
|
211
|
+
* @param name The name or hash of the parameter
|
|
212
|
+
* @param val The float value to set
|
|
213
|
+
*/
|
|
143
214
|
setFloat(name: string | number, val: number) {
|
|
144
215
|
if (this.runtimeAnimatorController?.getFloat(name) !== val)
|
|
145
216
|
this._parametersAreDirty = true;
|
|
@@ -149,6 +220,12 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
149
220
|
|
|
150
221
|
/**@deprecated use getFloat */
|
|
151
222
|
GetFloat(name: string | number) { return this.getFloat(name); }
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Gets a float parameter from the animator
|
|
226
|
+
* @param name The name or hash of the parameter
|
|
227
|
+
* @returns The value of the float parameter, or -1 if not found
|
|
228
|
+
*/
|
|
152
229
|
getFloat(name: string | number): number {
|
|
153
230
|
const res = this.runtimeAnimatorController?.getFloat(name) ?? -1;
|
|
154
231
|
if (debug) console.log("getFloat", name, res);
|
|
@@ -157,6 +234,12 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
157
234
|
|
|
158
235
|
/**@deprecated use setInteger */
|
|
159
236
|
SetInteger(name: string | number, val: number) { this.setInteger(name, val); }
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Sets an integer parameter in the animator
|
|
240
|
+
* @param name The name or hash of the parameter
|
|
241
|
+
* @param val The integer value to set
|
|
242
|
+
*/
|
|
160
243
|
setInteger(name: string | number, val: number) {
|
|
161
244
|
if (this.runtimeAnimatorController?.getInteger(name) !== val)
|
|
162
245
|
this._parametersAreDirty = true;
|
|
@@ -166,6 +249,12 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
166
249
|
|
|
167
250
|
/**@deprecated use getInteger */
|
|
168
251
|
GetInteger(name: string | number) { return this.getInteger(name); }
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Gets an integer parameter from the animator
|
|
255
|
+
* @param name The name or hash of the parameter
|
|
256
|
+
* @returns The value of the integer parameter, or -1 if not found
|
|
257
|
+
*/
|
|
169
258
|
getInteger(name: string | number): number {
|
|
170
259
|
const res = this.runtimeAnimatorController?.getInteger(name) ?? -1;
|
|
171
260
|
if (debug) console.log("getInteger", name, res);
|
|
@@ -174,6 +263,11 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
174
263
|
|
|
175
264
|
/**@deprecated use setTrigger */
|
|
176
265
|
SetTrigger(name: string | number) { this.setTrigger(name); }
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Activates a trigger parameter in the animator
|
|
269
|
+
* @param name The name or hash of the trigger parameter
|
|
270
|
+
*/
|
|
177
271
|
setTrigger(name: string | number) {
|
|
178
272
|
this._parametersAreDirty = true;
|
|
179
273
|
if (debug) console.log("setTrigger", name);
|
|
@@ -182,6 +276,11 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
182
276
|
|
|
183
277
|
/**@deprecated use resetTrigger */
|
|
184
278
|
ResetTrigger(name: string | number) { this.resetTrigger(name); }
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Resets a trigger parameter in the animator
|
|
282
|
+
* @param name The name or hash of the trigger parameter
|
|
283
|
+
*/
|
|
185
284
|
resetTrigger(name: string | number) {
|
|
186
285
|
this._parametersAreDirty = true;
|
|
187
286
|
if (debug) console.log("resetTrigger", name);
|
|
@@ -190,6 +289,12 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
190
289
|
|
|
191
290
|
/**@deprecated use getTrigger */
|
|
192
291
|
GetTrigger(name: string | number) { this.getTrigger(name); }
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Gets the state of a trigger parameter from the animator
|
|
295
|
+
* @param name The name or hash of the trigger parameter
|
|
296
|
+
* @returns The state of the trigger parameter
|
|
297
|
+
*/
|
|
193
298
|
getTrigger(name: string | number) {
|
|
194
299
|
const res = this.runtimeAnimatorController?.getTrigger(name);
|
|
195
300
|
if (debug) console.log("getTrigger", name, res);
|
|
@@ -198,13 +303,21 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
198
303
|
|
|
199
304
|
/**@deprecated use isInTransition */
|
|
200
305
|
IsInTransition() { return this.isInTransition(); }
|
|
201
|
-
/**
|
|
306
|
+
/**
|
|
307
|
+
* Checks if the animator is currently in a transition between states
|
|
308
|
+
* @returns True if the animator is currently blending between animations
|
|
309
|
+
*/
|
|
202
310
|
isInTransition(): boolean {
|
|
203
311
|
return this.runtimeAnimatorController?.isInTransition() ?? false;
|
|
204
312
|
}
|
|
205
313
|
|
|
206
314
|
/**@deprecated use setSpeed */
|
|
207
315
|
SetSpeed(speed: number) { return this.setSpeed(speed); }
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Sets the playback speed of the animator
|
|
319
|
+
* @param speed The new playback speed multiplier
|
|
320
|
+
*/
|
|
208
321
|
setSpeed(speed: number) {
|
|
209
322
|
if (speed === this._speed) return;
|
|
210
323
|
if (debug) console.log("setSpeed", speed);
|
|
@@ -213,13 +326,20 @@ export class Animator extends Behaviour implements IAnimationComponent {
|
|
|
213
326
|
this._animatorController.setSpeed(speed);
|
|
214
327
|
}
|
|
215
328
|
|
|
216
|
-
/**
|
|
329
|
+
/**
|
|
330
|
+
* Sets a random playback speed between the min and max values
|
|
331
|
+
* @param minMax Object with x (minimum) and y (maximum) speed values
|
|
332
|
+
*/
|
|
217
333
|
set minMaxSpeed(minMax: { x: number, y: number }) {
|
|
218
334
|
this._speed = Mathf.lerp(minMax.x, minMax.y, Math.random());
|
|
219
335
|
if (this._animatorController?.animator == this)
|
|
220
336
|
this._animatorController.setSpeed(this._speed);
|
|
221
337
|
}
|
|
222
338
|
|
|
339
|
+
/**
|
|
340
|
+
* Sets a random normalized time offset for animations between min (x) and max (y) values
|
|
341
|
+
* @param minMax Object with x (min) and y (max) values for the offset range
|
|
342
|
+
*/
|
|
223
343
|
set minMaxOffsetNormalized(minMax: { x: number, y: number }) {
|
|
224
344
|
this._normalizedStartOffset = Mathf.lerp(minMax.x, minMax.y, Math.random());
|
|
225
345
|
if (this.runtimeAnimatorController?.animator == this)
|