skeleton.d.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import { Bone } from "./bone";
  2. import { Observable } from "../Misc/observable";
  3. import { Vector3, Matrix } from "../Maths/math.vector";
  4. import type { Scene } from "../scene";
  5. import type { Nullable } from "../types";
  6. import type { AbstractMesh } from "../Meshes/abstractMesh";
  7. import { RawTexture } from "../Materials/Textures/rawTexture";
  8. import type { Animatable } from "../Animations/animatable";
  9. import type { AnimationPropertiesOverride } from "../Animations/animationPropertiesOverride";
  10. import { Animation } from "../Animations/animation";
  11. import { AnimationRange } from "../Animations/animationRange";
  12. import type { IInspectable } from "../Misc/iInspectable";
  13. import type { IAnimatable } from "../Animations/animatable.interface";
  14. import type { AbstractScene } from "../abstractScene";
  15. /**
  16. * Class used to handle skinning animations
  17. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons
  18. */
  19. export declare class Skeleton implements IAnimatable {
  20. /** defines the skeleton name */
  21. name: string;
  22. /** defines the skeleton Id */
  23. id: string;
  24. /**
  25. * Defines the list of child bones
  26. */
  27. bones: Bone[];
  28. /**
  29. * Defines an estimate of the dimension of the skeleton at rest
  30. */
  31. dimensionsAtRest: Vector3;
  32. /**
  33. * Defines a boolean indicating if the root matrix is provided by meshes or by the current skeleton (this is the default value)
  34. */
  35. needInitialSkinMatrix: boolean;
  36. /**
  37. * Gets the list of animations attached to this skeleton
  38. */
  39. animations: Array<Animation>;
  40. private _scene;
  41. private _isDirty;
  42. private _transformMatrices;
  43. private _transformMatrixTexture;
  44. private _meshesWithPoseMatrix;
  45. private _animatables;
  46. private _identity;
  47. private _synchronizedWithMesh;
  48. private _currentRenderId;
  49. private _ranges;
  50. private _absoluteTransformIsDirty;
  51. private _canUseTextureForBones;
  52. private _uniqueId;
  53. /** @internal */
  54. _numBonesWithLinkedTransformNode: number;
  55. /** @internal */
  56. _hasWaitingData: Nullable<boolean>;
  57. /** @internal */
  58. _parentContainer: Nullable<AbstractScene>;
  59. /**
  60. * Specifies if the skeleton should be serialized
  61. */
  62. doNotSerialize: boolean;
  63. private _useTextureToStoreBoneMatrices;
  64. /**
  65. * Gets or sets a boolean indicating that bone matrices should be stored as a texture instead of using shader uniforms (default is true).
  66. * Please note that this option is not available if the hardware does not support it
  67. */
  68. get useTextureToStoreBoneMatrices(): boolean;
  69. set useTextureToStoreBoneMatrices(value: boolean);
  70. private _animationPropertiesOverride;
  71. /**
  72. * Gets or sets the animation properties override
  73. */
  74. get animationPropertiesOverride(): Nullable<AnimationPropertiesOverride>;
  75. set animationPropertiesOverride(value: Nullable<AnimationPropertiesOverride>);
  76. /**
  77. * List of inspectable custom properties (used by the Inspector)
  78. * @see https://doc.babylonjs.com/toolsAndResources/inspector#extensibility
  79. */
  80. inspectableCustomProperties: IInspectable[];
  81. /**
  82. * An observable triggered before computing the skeleton's matrices
  83. */
  84. onBeforeComputeObservable: Observable<Skeleton>;
  85. /**
  86. * Gets a boolean indicating that the skeleton effectively stores matrices into a texture
  87. */
  88. get isUsingTextureForMatrices(): boolean;
  89. /**
  90. * Gets the unique ID of this skeleton
  91. */
  92. get uniqueId(): number;
  93. /**
  94. * Creates a new skeleton
  95. * @param name defines the skeleton name
  96. * @param id defines the skeleton Id
  97. * @param scene defines the hosting scene
  98. */
  99. constructor(
  100. /** defines the skeleton name */
  101. name: string,
  102. /** defines the skeleton Id */
  103. id: string, scene: Scene);
  104. /**
  105. * Gets the current object class name.
  106. * @returns the class name
  107. */
  108. getClassName(): string;
  109. /**
  110. * Returns an array containing the root bones
  111. * @returns an array containing the root bones
  112. */
  113. getChildren(): Array<Bone>;
  114. /**
  115. * Gets the list of transform matrices to send to shaders (one matrix per bone)
  116. * @param mesh defines the mesh to use to get the root matrix (if needInitialSkinMatrix === true)
  117. * @returns a Float32Array containing matrices data
  118. */
  119. getTransformMatrices(mesh: Nullable<AbstractMesh>): Float32Array;
  120. /**
  121. * Gets the list of transform matrices to send to shaders inside a texture (one matrix per bone)
  122. * @param mesh defines the mesh to use to get the root matrix (if needInitialSkinMatrix === true)
  123. * @returns a raw texture containing the data
  124. */
  125. getTransformMatrixTexture(mesh: AbstractMesh): Nullable<RawTexture>;
  126. /**
  127. * Gets the current hosting scene
  128. * @returns a scene object
  129. */
  130. getScene(): Scene;
  131. /**
  132. * Gets a string representing the current skeleton data
  133. * @param fullDetails defines a boolean indicating if we want a verbose version
  134. * @returns a string representing the current skeleton data
  135. */
  136. toString(fullDetails?: boolean): string;
  137. /**
  138. * Get bone's index searching by name
  139. * @param name defines bone's name to search for
  140. * @returns the indice of the bone. Returns -1 if not found
  141. */
  142. getBoneIndexByName(name: string): number;
  143. /**
  144. * Create a new animation range
  145. * @param name defines the name of the range
  146. * @param from defines the start key
  147. * @param to defines the end key
  148. */
  149. createAnimationRange(name: string, from: number, to: number): void;
  150. /**
  151. * Delete a specific animation range
  152. * @param name defines the name of the range
  153. * @param deleteFrames defines if frames must be removed as well
  154. */
  155. deleteAnimationRange(name: string, deleteFrames?: boolean): void;
  156. /**
  157. * Gets a specific animation range
  158. * @param name defines the name of the range to look for
  159. * @returns the requested animation range or null if not found
  160. */
  161. getAnimationRange(name: string): Nullable<AnimationRange>;
  162. /**
  163. * Gets the list of all animation ranges defined on this skeleton
  164. * @returns an array
  165. */
  166. getAnimationRanges(): Nullable<AnimationRange>[];
  167. /**
  168. * Copy animation range from a source skeleton.
  169. * This is not for a complete retargeting, only between very similar skeleton's with only possible bone length differences
  170. * @param source defines the source skeleton
  171. * @param name defines the name of the range to copy
  172. * @param rescaleAsRequired defines if rescaling must be applied if required
  173. * @returns true if operation was successful
  174. */
  175. copyAnimationRange(source: Skeleton, name: string, rescaleAsRequired?: boolean): boolean;
  176. /**
  177. * Forces the skeleton to go to rest pose
  178. */
  179. returnToRest(): void;
  180. private _getHighestAnimationFrame;
  181. /**
  182. * Begin a specific animation range
  183. * @param name defines the name of the range to start
  184. * @param loop defines if looping must be turned on (false by default)
  185. * @param speedRatio defines the speed ratio to apply (1 by default)
  186. * @param onAnimationEnd defines a callback which will be called when animation will end
  187. * @returns a new animatable
  188. */
  189. beginAnimation(name: string, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void): Nullable<Animatable>;
  190. /**
  191. * Convert the keyframes for a range of animation on a skeleton to be relative to a given reference frame.
  192. * @param skeleton defines the Skeleton containing the animation range to convert
  193. * @param referenceFrame defines the frame that keyframes in the range will be relative to
  194. * @param range defines the name of the AnimationRange belonging to the Skeleton to convert
  195. * @returns the original skeleton
  196. */
  197. static MakeAnimationAdditive(skeleton: Skeleton, referenceFrame: number | undefined, range: string): Nullable<Skeleton>;
  198. /** @internal */
  199. _markAsDirty(): void;
  200. /**
  201. * @internal
  202. */
  203. _registerMeshWithPoseMatrix(mesh: AbstractMesh): void;
  204. /**
  205. * @internal
  206. */
  207. _unregisterMeshWithPoseMatrix(mesh: AbstractMesh): void;
  208. private _computeTransformMatrices;
  209. /**
  210. * Build all resources required to render a skeleton
  211. * @param dontCheckFrameId defines a boolean indicating if prepare should be run without checking first the current frame id (default: false)
  212. */
  213. prepare(dontCheckFrameId?: boolean): void;
  214. /**
  215. * Gets the list of animatables currently running for this skeleton
  216. * @returns an array of animatables
  217. */
  218. getAnimatables(): IAnimatable[];
  219. /**
  220. * Clone the current skeleton
  221. * @param name defines the name of the new skeleton
  222. * @param id defines the id of the new skeleton
  223. * @returns the new skeleton
  224. */
  225. clone(name: string, id?: string): Skeleton;
  226. /**
  227. * Enable animation blending for this skeleton
  228. * @param blendingSpeed defines the blending speed to apply
  229. * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#animation-blending
  230. */
  231. enableBlending(blendingSpeed?: number): void;
  232. /**
  233. * Releases all resources associated with the current skeleton
  234. */
  235. dispose(): void;
  236. /**
  237. * Serialize the skeleton in a JSON object
  238. * @returns a JSON object
  239. */
  240. serialize(): any;
  241. /**
  242. * Creates a new skeleton from serialized data
  243. * @param parsedSkeleton defines the serialized data
  244. * @param scene defines the hosting scene
  245. * @returns a new skeleton
  246. */
  247. static Parse(parsedSkeleton: any, scene: Scene): Skeleton;
  248. /**
  249. * Compute all node absolute matrices
  250. * @param forceUpdate defines if computation must be done even if cache is up to date
  251. */
  252. computeAbsoluteMatrices(forceUpdate?: boolean): void;
  253. /**
  254. * Compute all node absolute matrices
  255. * @param forceUpdate defines if computation must be done even if cache is up to date
  256. * @deprecated Please use computeAbsoluteMatrices instead
  257. */
  258. computeAbsoluteTransforms(forceUpdate?: boolean): void;
  259. /**
  260. * Gets the root pose matrix
  261. * @returns a matrix
  262. */
  263. getPoseMatrix(): Nullable<Matrix>;
  264. /**
  265. * Sorts bones per internal index
  266. */
  267. sortBones(): void;
  268. private _sortBones;
  269. /**
  270. * Set the current local matrix as the restPose for all bones in the skeleton.
  271. */
  272. setCurrentPoseAsRest(): void;
  273. }