bone.d.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. import type { Skeleton } from "./skeleton";
  2. import { Vector3, Quaternion, Matrix } from "../Maths/math.vector";
  3. import type { Nullable } from "../types";
  4. import type { TransformNode } from "../Meshes/transformNode";
  5. import { Node } from "../node";
  6. import { Space } from "../Maths/math.axis";
  7. import type { Animation } from "../Animations/animation";
  8. import type { AnimationPropertiesOverride } from "../Animations/animationPropertiesOverride";
  9. /**
  10. * Class used to store bone information
  11. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons
  12. */
  13. export declare class Bone extends Node {
  14. /**
  15. * defines the bone name
  16. */
  17. name: string;
  18. private static _TmpVecs;
  19. private static _TmpQuat;
  20. private static _TmpMats;
  21. /**
  22. * Gets the list of child bones
  23. */
  24. children: Bone[];
  25. /** Gets the animations associated with this bone */
  26. animations: Animation[];
  27. /**
  28. * Gets or sets bone length
  29. */
  30. length: number;
  31. /**
  32. * @internal Internal only
  33. * Set this value to map this bone to a different index in the transform matrices
  34. * Set this value to -1 to exclude the bone from the transform matrices
  35. */
  36. _index: Nullable<number>;
  37. private _skeleton;
  38. private _localMatrix;
  39. private _absoluteMatrix;
  40. private _bindMatrix;
  41. private _absoluteBindMatrix;
  42. private _absoluteInverseBindMatrix;
  43. private _finalMatrix;
  44. private _restMatrix;
  45. private _scalingDeterminant;
  46. private _localScaling;
  47. private _localRotation;
  48. private _localPosition;
  49. private _needToDecompose;
  50. private _needToCompose;
  51. /** @internal */
  52. _linkedTransformNode: Nullable<TransformNode>;
  53. /** @internal */
  54. _waitingTransformNodeId: Nullable<string>;
  55. /** @internal */
  56. get _matrix(): Matrix;
  57. /** @internal */
  58. set _matrix(value: Matrix);
  59. /**
  60. * Create a new bone
  61. * @param name defines the bone name
  62. * @param skeleton defines the parent skeleton
  63. * @param parentBone defines the parent (can be null if the bone is the root)
  64. * @param localMatrix defines the local matrix (default: identity)
  65. * @param restMatrix defines the rest matrix (default: localMatrix)
  66. * @param bindMatrix defines the bind matrix (default: localMatrix)
  67. * @param index defines index of the bone in the hierarchy (default: null)
  68. */
  69. constructor(
  70. /**
  71. * defines the bone name
  72. */
  73. name: string, skeleton: Skeleton, parentBone?: Nullable<Bone>, localMatrix?: Nullable<Matrix>, restMatrix?: Nullable<Matrix>, bindMatrix?: Nullable<Matrix>, index?: Nullable<number>);
  74. /**
  75. * Gets the current object class name.
  76. * @returns the class name
  77. */
  78. getClassName(): string;
  79. /**
  80. * Gets the parent skeleton
  81. * @returns a skeleton
  82. */
  83. getSkeleton(): Skeleton;
  84. get parent(): Bone;
  85. /**
  86. * Gets parent bone
  87. * @returns a bone or null if the bone is the root of the bone hierarchy
  88. */
  89. getParent(): Nullable<Bone>;
  90. /**
  91. * Returns an array containing the children of the bone
  92. * @returns an array containing the children of the bone (can be empty if the bone has no children)
  93. */
  94. getChildren(): Array<Bone>;
  95. /**
  96. * Gets the node index in matrix array generated for rendering
  97. * @returns the node index
  98. */
  99. getIndex(): number;
  100. set parent(newParent: Nullable<Bone>);
  101. /**
  102. * Sets the parent bone
  103. * @param parent defines the parent (can be null if the bone is the root)
  104. * @param updateAbsoluteBindMatrices defines if the absolute bind and absolute inverse bind matrices must be updated
  105. */
  106. setParent(parent: Nullable<Bone>, updateAbsoluteBindMatrices?: boolean): void;
  107. /**
  108. * Gets the local matrix
  109. * @returns the local matrix
  110. */
  111. getLocalMatrix(): Matrix;
  112. /**
  113. * Gets the bind matrix
  114. * @returns the bind matrix
  115. */
  116. getBindMatrix(): Matrix;
  117. /**
  118. * Gets the bind matrix.
  119. * @returns the bind matrix
  120. * @deprecated Please use getBindMatrix instead
  121. */
  122. getBaseMatrix(): Matrix;
  123. /**
  124. * Gets the rest matrix
  125. * @returns the rest matrix
  126. */
  127. getRestMatrix(): Matrix;
  128. /**
  129. * Gets the rest matrix
  130. * @returns the rest matrix
  131. * @deprecated Please use getRestMatrix instead
  132. */
  133. getRestPose(): Matrix;
  134. /**
  135. * Sets the rest matrix
  136. * @param matrix the local-space rest matrix to set for this bone
  137. */
  138. setRestMatrix(matrix: Matrix): void;
  139. /**
  140. * Sets the rest matrix
  141. * @param matrix the local-space rest to set for this bone
  142. * @deprecated Please use setRestMatrix instead
  143. */
  144. setRestPose(matrix: Matrix): void;
  145. /**
  146. * Gets the bind matrix
  147. * @returns the bind matrix
  148. * @deprecated Please use getBindMatrix instead
  149. */
  150. getBindPose(): Matrix;
  151. /**
  152. * Sets the bind matrix
  153. * This will trigger a recomputation of the absolute bind and absolute inverse bind matrices for this bone and its children
  154. * Note that the local matrix will also be set with the matrix passed in parameter!
  155. * @param matrix the local-space bind matrix to set for this bone
  156. */
  157. setBindMatrix(matrix: Matrix): void;
  158. /**
  159. * Sets the bind matrix
  160. * @param matrix the local-space bind to set for this bone
  161. * @deprecated Please use setBindMatrix instead
  162. */
  163. setBindPose(matrix: Matrix): void;
  164. /**
  165. * Gets the matrix used to store the final world transformation of the bone (ie. the matrix sent to shaders)
  166. * @returns the final world matrix
  167. */
  168. getFinalMatrix(): Matrix;
  169. /**
  170. * Gets the matrix used to store the final world transformation of the bone (ie. the matrix sent to shaders)
  171. * @deprecated Please use getFinalMatrix instead
  172. * @returns the final world matrix
  173. */
  174. getWorldMatrix(): Matrix;
  175. /**
  176. * Sets the local matrix to the rest matrix
  177. */
  178. returnToRest(): void;
  179. /**
  180. * Gets the inverse of the bind matrix, in world space (relative to the skeleton root)
  181. * @returns the inverse bind matrix, in world space
  182. */
  183. getAbsoluteInverseBindMatrix(): Matrix;
  184. /**
  185. * Gets the inverse of the bind matrix, in world space (relative to the skeleton root)
  186. * @returns the inverse bind matrix, in world space
  187. * @deprecated Please use getAbsoluteInverseBindMatrix instead
  188. */
  189. getInvertedAbsoluteTransform(): Matrix;
  190. /**
  191. * Gets the bone matrix, in world space (relative to the skeleton root)
  192. * @returns the bone matrix, in world space
  193. */
  194. getAbsoluteMatrix(): Matrix;
  195. /**
  196. * Gets the bone matrix, in world space (relative to the skeleton root)
  197. * @returns the bone matrix, in world space
  198. * @deprecated Please use getAbsoluteMatrix instead
  199. */
  200. getAbsoluteTransform(): Matrix;
  201. /**
  202. * Links with the given transform node.
  203. * The local matrix of this bone is overwritten by the transform of the node every frame.
  204. * @param transformNode defines the transform node to link to
  205. */
  206. linkTransformNode(transformNode: Nullable<TransformNode>): void;
  207. /**
  208. * Gets the node used to drive the bone's transformation
  209. * @returns a transform node or null
  210. */
  211. getTransformNode(): Nullable<TransformNode>;
  212. /** Gets or sets current position (in local space) */
  213. get position(): Vector3;
  214. set position(newPosition: Vector3);
  215. /** Gets or sets current rotation (in local space) */
  216. get rotation(): Vector3;
  217. set rotation(newRotation: Vector3);
  218. /** Gets or sets current rotation quaternion (in local space) */
  219. get rotationQuaternion(): Quaternion;
  220. set rotationQuaternion(newRotation: Quaternion);
  221. /** Gets or sets current scaling (in local space) */
  222. get scaling(): Vector3;
  223. set scaling(newScaling: Vector3);
  224. /**
  225. * Gets the animation properties override
  226. */
  227. get animationPropertiesOverride(): Nullable<AnimationPropertiesOverride>;
  228. private _decompose;
  229. private _compose;
  230. /**
  231. * Update the bind (and optionally the local) matrix
  232. * @param bindMatrix defines the new matrix to set to the bind/local matrix, in local space
  233. * @param updateAbsoluteBindMatrices defines if the absolute bind and absolute inverse bind matrices must be recomputed (default: true)
  234. * @param updateLocalMatrix defines if the local matrix should also be updated with the matrix passed in parameter (default: true)
  235. */
  236. updateMatrix(bindMatrix: Matrix, updateAbsoluteBindMatrices?: boolean, updateLocalMatrix?: boolean): void;
  237. /**
  238. * @internal
  239. */
  240. _updateAbsoluteBindMatrices(bindMatrix?: Matrix, updateChildren?: boolean): void;
  241. /**
  242. * Flag the bone as dirty (Forcing it to update everything)
  243. * @returns this bone
  244. */
  245. markAsDirty(): Bone;
  246. /** @internal */
  247. _markAsDirtyAndCompose(): void;
  248. private _markAsDirtyAndDecompose;
  249. private _updatePosition;
  250. /**
  251. * Translate the bone in local or world space
  252. * @param vec The amount to translate the bone
  253. * @param space The space that the translation is in (default: Space.LOCAL)
  254. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  255. */
  256. translate(vec: Vector3, space?: Space, tNode?: TransformNode): void;
  257. /**
  258. * Set the position of the bone in local or world space
  259. * @param position The position to set the bone
  260. * @param space The space that the position is in (default: Space.LOCAL)
  261. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  262. */
  263. setPosition(position: Vector3, space?: Space, tNode?: TransformNode): void;
  264. /**
  265. * Set the absolute position of the bone (world space)
  266. * @param position The position to set the bone
  267. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  268. */
  269. setAbsolutePosition(position: Vector3, tNode?: TransformNode): void;
  270. /**
  271. * Scale the bone on the x, y and z axes (in local space)
  272. * @param x The amount to scale the bone on the x axis
  273. * @param y The amount to scale the bone on the y axis
  274. * @param z The amount to scale the bone on the z axis
  275. * @param scaleChildren sets this to true if children of the bone should be scaled as well (false by default)
  276. */
  277. scale(x: number, y: number, z: number, scaleChildren?: boolean): void;
  278. /**
  279. * Set the bone scaling in local space
  280. * @param scale defines the scaling vector
  281. */
  282. setScale(scale: Vector3): void;
  283. /**
  284. * Gets the current scaling in local space
  285. * @returns the current scaling vector
  286. */
  287. getScale(): Vector3;
  288. /**
  289. * Gets the current scaling in local space and stores it in a target vector
  290. * @param result defines the target vector
  291. */
  292. getScaleToRef(result: Vector3): void;
  293. /**
  294. * Set the yaw, pitch, and roll of the bone in local or world space
  295. * @param yaw The rotation of the bone on the y axis
  296. * @param pitch The rotation of the bone on the x axis
  297. * @param roll The rotation of the bone on the z axis
  298. * @param space The space that the axes of rotation are in
  299. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  300. */
  301. setYawPitchRoll(yaw: number, pitch: number, roll: number, space?: Space, tNode?: TransformNode): void;
  302. /**
  303. * Add a rotation to the bone on an axis in local or world space
  304. * @param axis The axis to rotate the bone on
  305. * @param amount The amount to rotate the bone
  306. * @param space The space that the axis is in
  307. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  308. */
  309. rotate(axis: Vector3, amount: number, space?: Space, tNode?: TransformNode): void;
  310. /**
  311. * Set the rotation of the bone to a particular axis angle in local or world space
  312. * @param axis The axis to rotate the bone on
  313. * @param angle The angle that the bone should be rotated to
  314. * @param space The space that the axis is in
  315. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  316. */
  317. setAxisAngle(axis: Vector3, angle: number, space?: Space, tNode?: TransformNode): void;
  318. /**
  319. * Set the euler rotation of the bone in local or world space
  320. * @param rotation The euler rotation that the bone should be set to
  321. * @param space The space that the rotation is in
  322. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  323. */
  324. setRotation(rotation: Vector3, space?: Space, tNode?: TransformNode): void;
  325. /**
  326. * Set the quaternion rotation of the bone in local or world space
  327. * @param quat The quaternion rotation that the bone should be set to
  328. * @param space The space that the rotation is in
  329. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  330. */
  331. setRotationQuaternion(quat: Quaternion, space?: Space, tNode?: TransformNode): void;
  332. /**
  333. * Set the rotation matrix of the bone in local or world space
  334. * @param rotMat The rotation matrix that the bone should be set to
  335. * @param space The space that the rotation is in
  336. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  337. */
  338. setRotationMatrix(rotMat: Matrix, space?: Space, tNode?: TransformNode): void;
  339. private _rotateWithMatrix;
  340. private _getAbsoluteInverseMatrixUnscaledToRef;
  341. /**
  342. * Get the position of the bone in local or world space
  343. * @param space The space that the returned position is in
  344. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  345. * @returns The position of the bone
  346. */
  347. getPosition(space?: Space, tNode?: Nullable<TransformNode>): Vector3;
  348. /**
  349. * Copy the position of the bone to a vector3 in local or world space
  350. * @param space The space that the returned position is in
  351. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  352. * @param result The vector3 to copy the position to
  353. */
  354. getPositionToRef(space: Space | undefined, tNode: Nullable<TransformNode>, result: Vector3): void;
  355. /**
  356. * Get the absolute position of the bone (world space)
  357. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  358. * @returns The absolute position of the bone
  359. */
  360. getAbsolutePosition(tNode?: Nullable<TransformNode>): Vector3;
  361. /**
  362. * Copy the absolute position of the bone (world space) to the result param
  363. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  364. * @param result The vector3 to copy the absolute position to
  365. */
  366. getAbsolutePositionToRef(tNode: TransformNode, result: Vector3): void;
  367. /**
  368. * Compute the absolute matrices of this bone and its children
  369. */
  370. computeAbsoluteMatrices(): void;
  371. /**
  372. * Compute the absolute matrices of this bone and its children
  373. * @deprecated Please use computeAbsoluteMatrices instead
  374. */
  375. computeAbsoluteTransforms(): void;
  376. /**
  377. * Get the world direction from an axis that is in the local space of the bone
  378. * @param localAxis The local direction that is used to compute the world direction
  379. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  380. * @returns The world direction
  381. */
  382. getDirection(localAxis: Vector3, tNode?: Nullable<TransformNode>): Vector3;
  383. /**
  384. * Copy the world direction to a vector3 from an axis that is in the local space of the bone
  385. * @param localAxis The local direction that is used to compute the world direction
  386. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  387. * @param result The vector3 that the world direction will be copied to
  388. */
  389. getDirectionToRef(localAxis: Vector3, tNode: Nullable<TransformNode> | undefined, result: Vector3): void;
  390. /**
  391. * Get the euler rotation of the bone in local or world space
  392. * @param space The space that the rotation should be in
  393. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  394. * @returns The euler rotation
  395. */
  396. getRotation(space?: Space, tNode?: Nullable<TransformNode>): Vector3;
  397. /**
  398. * Copy the euler rotation of the bone to a vector3. The rotation can be in either local or world space
  399. * @param space The space that the rotation should be in
  400. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  401. * @param result The vector3 that the rotation should be copied to
  402. */
  403. getRotationToRef(space: Space | undefined, tNode: Nullable<TransformNode> | undefined, result: Vector3): void;
  404. /**
  405. * Get the quaternion rotation of the bone in either local or world space
  406. * @param space The space that the rotation should be in
  407. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  408. * @returns The quaternion rotation
  409. */
  410. getRotationQuaternion(space?: Space, tNode?: Nullable<TransformNode>): Quaternion;
  411. /**
  412. * Copy the quaternion rotation of the bone to a quaternion. The rotation can be in either local or world space
  413. * @param space The space that the rotation should be in
  414. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  415. * @param result The quaternion that the rotation should be copied to
  416. */
  417. getRotationQuaternionToRef(space: Space | undefined, tNode: Nullable<TransformNode> | undefined, result: Quaternion): void;
  418. /**
  419. * Get the rotation matrix of the bone in local or world space
  420. * @param space The space that the rotation should be in
  421. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  422. * @returns The rotation matrix
  423. */
  424. getRotationMatrix(space: Space | undefined, tNode: TransformNode): Matrix;
  425. /**
  426. * Copy the rotation matrix of the bone to a matrix. The rotation can be in either local or world space
  427. * @param space The space that the rotation should be in
  428. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  429. * @param result The quaternion that the rotation should be copied to
  430. */
  431. getRotationMatrixToRef(space: Space | undefined, tNode: TransformNode, result: Matrix): void;
  432. /**
  433. * Get the world position of a point that is in the local space of the bone
  434. * @param position The local position
  435. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  436. * @returns The world position
  437. */
  438. getAbsolutePositionFromLocal(position: Vector3, tNode?: Nullable<TransformNode>): Vector3;
  439. /**
  440. * Get the world position of a point that is in the local space of the bone and copy it to the result param
  441. * @param position The local position
  442. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  443. * @param result The vector3 that the world position should be copied to
  444. */
  445. getAbsolutePositionFromLocalToRef(position: Vector3, tNode: Nullable<TransformNode> | undefined, result: Vector3): void;
  446. /**
  447. * Get the local position of a point that is in world space
  448. * @param position The world position
  449. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  450. * @returns The local position
  451. */
  452. getLocalPositionFromAbsolute(position: Vector3, tNode?: Nullable<TransformNode>): Vector3;
  453. /**
  454. * Get the local position of a point that is in world space and copy it to the result param
  455. * @param position The world position
  456. * @param tNode A TransformNode whose world matrix is to be applied to the calculated absolute matrix. In most cases, you'll want to pass the mesh associated with the skeleton from which this bone comes. Used only when space=Space.WORLD
  457. * @param result The vector3 that the local position should be copied to
  458. */
  459. getLocalPositionFromAbsoluteToRef(position: Vector3, tNode: Nullable<TransformNode> | undefined, result: Vector3): void;
  460. /**
  461. * Set the current local matrix as the restMatrix for this bone.
  462. */
  463. setCurrentPoseAsRest(): void;
  464. }