1 | import { Matrix4, Matrix4Tuple } from "../math/Matrix4.js";
|
2 | import { DataTexture } from "../textures/DataTexture.js";
|
3 | import { Bone } from "./Bone.js";
|
4 |
|
5 | export interface SkeletonJSON {
|
6 | metadata: { version: number; type: string; generator: string };
|
7 | bones: string[];
|
8 | boneInverses: Matrix4Tuple[];
|
9 | uuid: string;
|
10 | }
|
11 |
|
12 | /**
|
13 | * Use an array of {@link Bone | bones} to create a {@link Skeleton} that can be used by a {@link THREE.SkinnedMesh | SkinnedMesh}.
|
14 | * @example
|
15 | * ```typescript
|
16 | * // Create a simple "arm"
|
17 | * const bones = [];
|
18 | * const shoulder = new THREE.Bone();
|
19 | * const elbow = new THREE.Bone();
|
20 | * const hand = new THREE.Bone();
|
21 | * shoulder.add(elbow);
|
22 | * elbow.add(hand);
|
23 | * bones.push(shoulder);
|
24 | * bones.push(elbow);
|
25 | * bones.push(hand);
|
26 | * shoulder.position.y = -5;
|
27 | * elbow.position.y = 0;
|
28 | * hand.position.y = 5;
|
29 | * const armSkeleton = new THREE.Skeleton(bones);
|
30 | * See the[page: SkinnedMesh] page
|
31 | * for an example of usage with standard[page: BufferGeometry].
|
32 | * ```
|
33 | * @see {@link https://threejs.org/docs/index.html#api/en/objects/Skeleton | Official Documentation}
|
34 | * @see {@link https://github.com/mrdoob/three.js/blob/master/src/objects/Skeleton.js | Source}
|
35 | */
|
36 | export class Skeleton {
|
37 | /**
|
38 | * Creates a new Skeleton.
|
39 | * @param bones The array of {@link THREE.Bone | bones}. Default `[]`.
|
40 | * @param boneInverses An array of {@link THREE.Matrix4 | Matrix4s}. Default `[]`.
|
41 | */
|
42 | constructor(bones?: Bone[], boneInverses?: Matrix4[]);
|
43 |
|
44 | /**
|
45 | * {//en.wikipedia.org/wiki/Universally_unique_identifier | UUID} of this object instance.
http: |
46 | * @remarks This gets automatically assigned and shouldn't be edited.
|
47 | */
|
48 | uuid: string;
|
49 |
|
50 | /**
|
51 | * The array of {@link THREE.Bone | Bones}.
|
52 | * @remarks Note this is a copy of the original array, not a reference, so you can modify the original array without effecting this one.
|
53 | */
|
54 | bones: Bone[];
|
55 |
|
56 | /**
|
57 | * An array of {@link Matrix4 | Matrix4s} that represent the inverse of the {@link THREE.Matrix4 | matrixWorld} of the individual bones.
|
58 | */
|
59 | boneInverses: Matrix4[];
|
60 |
|
61 | /**
|
62 | * The array buffer holding the bone data when using a vertex texture.
|
63 | */
|
64 | boneMatrices: Float32Array;
|
65 |
|
66 | /**
|
67 | * The {@link THREE.DataTexture | DataTexture} holding the bone data when using a vertex texture.
|
68 | */
|
69 | boneTexture: null | DataTexture;
|
70 |
|
71 | frame: number;
|
72 |
|
73 | init(): void;
|
74 |
|
75 | /**
|
76 | * Generates the {@link boneInverses} array if not provided in the constructor.
|
77 | */
|
78 | calculateInverses(): void;
|
79 |
|
80 | /**
|
81 | * Computes an instance of {@link THREE.DataTexture | DataTexture} in order to pass the bone data more efficiently to the shader
|
82 | * @remarks
|
83 | * The texture is assigned to {@link boneTexture}.
|
84 | */
|
85 | computeBoneTexture(): this;
|
86 |
|
87 | /**
|
88 | * Returns the skeleton to the base pose.
|
89 | */
|
90 | pose(): void;
|
91 |
|
92 | /**
|
93 | * Updates the {@link boneMatrices} and {@link boneTexture} after changing the bones
|
94 | * @remarks
|
95 | * This is called automatically by the {@link THREE.WebGLRenderer | WebGLRenderer} if the {@link Skeleton} is used with a {@link THREE.SkinnedMesh | SkinnedMesh}.
|
96 | */
|
97 | update(): void;
|
98 |
|
99 | /**
|
100 | * Returns a clone of this {@link Skeleton} object.
|
101 | */
|
102 | clone(): Skeleton;
|
103 |
|
104 | /**
|
105 | * Searches through the skeleton's bone array and returns the first with a matching name.
|
106 | * @param name String to match to the Bone's {@link THREE.Bone.name | .name} property.
|
107 | */
|
108 | getBoneByName(name: string): undefined | Bone;
|
109 |
|
110 | /**
|
111 | * Frees the GPU-related resources allocated by this instance
|
112 | * @remarks
|
113 | * Call this method whenever this instance is no longer used in your app.
|
114 | */
|
115 | dispose(): void;
|
116 |
|
117 | toJSON(): SkeletonJSON;
|
118 |
|
119 | fromJSON(json: SkeletonJSON, bones: Record<string, Bone>): void;
|
120 | }
|