boneLookController.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import { Vector3 } from "../Maths/math.vector";
  2. import type { TransformNode } from "../Meshes/transformNode";
  3. import type { Bone } from "./bone";
  4. import { Space } from "../Maths/math.axis";
  5. /**
  6. * Class used to make a bone look toward a point in space
  7. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons#bonelookcontroller
  8. */
  9. export declare class BoneLookController {
  10. private static _TmpVecs;
  11. private static _TmpQuat;
  12. private static _TmpMats;
  13. /**
  14. * The target Vector3 that the bone will look at
  15. */
  16. target: Vector3;
  17. /**
  18. * The TransformNode that the bone is attached to
  19. * Name kept as mesh for back compatibility
  20. */
  21. mesh: TransformNode;
  22. /**
  23. * The bone that will be looking to the target
  24. */
  25. bone: Bone;
  26. /**
  27. * The up axis of the coordinate system that is used when the bone is rotated
  28. */
  29. upAxis: Vector3;
  30. /**
  31. * The space that the up axis is in - Space.BONE, Space.LOCAL (default), or Space.WORLD
  32. */
  33. upAxisSpace: Space;
  34. /**
  35. * Used to make an adjustment to the yaw of the bone
  36. */
  37. adjustYaw: number;
  38. /**
  39. * Used to make an adjustment to the pitch of the bone
  40. */
  41. adjustPitch: number;
  42. /**
  43. * Used to make an adjustment to the roll of the bone
  44. */
  45. adjustRoll: number;
  46. /**
  47. * The amount to slerp (spherical linear interpolation) to the target. Set this to a value between 0 and 1 (a value of 1 disables slerp)
  48. */
  49. slerpAmount: number;
  50. private _minYaw;
  51. private _maxYaw;
  52. private _minPitch;
  53. private _maxPitch;
  54. private _minYawSin;
  55. private _minYawCos;
  56. private _maxYawSin;
  57. private _maxYawCos;
  58. private _midYawConstraint;
  59. private _minPitchTan;
  60. private _maxPitchTan;
  61. private _boneQuat;
  62. private _slerping;
  63. private _transformYawPitch;
  64. private _transformYawPitchInv;
  65. private _firstFrameSkipped;
  66. private _yawRange;
  67. private _fowardAxis;
  68. /**
  69. * Gets or sets the minimum yaw angle that the bone can look to
  70. */
  71. get minYaw(): number;
  72. set minYaw(value: number);
  73. /**
  74. * Gets or sets the maximum yaw angle that the bone can look to
  75. */
  76. get maxYaw(): number;
  77. set maxYaw(value: number);
  78. /**
  79. * Use the absolute value for yaw when checking the min/max constraints
  80. */
  81. useAbsoluteValueForYaw: boolean;
  82. /**
  83. * Gets or sets the minimum pitch angle that the bone can look to
  84. */
  85. get minPitch(): number;
  86. set minPitch(value: number);
  87. /**
  88. * Gets or sets the maximum pitch angle that the bone can look to
  89. */
  90. get maxPitch(): number;
  91. set maxPitch(value: number);
  92. /**
  93. * Create a BoneLookController
  94. * @param mesh the TransformNode that the bone belongs to
  95. * @param bone the bone that will be looking to the target
  96. * @param target the target Vector3 to look at
  97. * @param options optional settings:
  98. * * maxYaw: the maximum angle the bone will yaw to
  99. * * minYaw: the minimum angle the bone will yaw to
  100. * * maxPitch: the maximum angle the bone will pitch to
  101. * * minPitch: the minimum angle the bone will yaw to
  102. * * slerpAmount: set the between 0 and 1 to make the bone slerp to the target.
  103. * * upAxis: the up axis of the coordinate system
  104. * * upAxisSpace: the space that the up axis is in - Space.BONE, Space.LOCAL (default), or Space.WORLD.
  105. * * yawAxis: set yawAxis if the bone does not yaw on the y axis
  106. * * pitchAxis: set pitchAxis if the bone does not pitch on the x axis
  107. * * adjustYaw: used to make an adjustment to the yaw of the bone
  108. * * adjustPitch: used to make an adjustment to the pitch of the bone
  109. * * adjustRoll: used to make an adjustment to the roll of the bone
  110. * @param options.maxYaw
  111. * @param options.minYaw
  112. * @param options.maxPitch
  113. * @param options.minPitch
  114. * @param options.slerpAmount
  115. * @param options.upAxis
  116. * @param options.upAxisSpace
  117. * @param options.yawAxis
  118. * @param options.pitchAxis
  119. * @param options.adjustYaw
  120. * @param options.adjustPitch
  121. * @param options.adjustRoll
  122. **/
  123. constructor(mesh: TransformNode, bone: Bone, target: Vector3, options?: {
  124. maxYaw?: number;
  125. minYaw?: number;
  126. maxPitch?: number;
  127. minPitch?: number;
  128. slerpAmount?: number;
  129. upAxis?: Vector3;
  130. upAxisSpace?: Space;
  131. yawAxis?: Vector3;
  132. pitchAxis?: Vector3;
  133. adjustYaw?: number;
  134. adjustPitch?: number;
  135. adjustRoll?: number;
  136. useAbsoluteValueForYaw?: boolean;
  137. });
  138. /**
  139. * Update the bone to look at the target. This should be called before the scene is rendered (use scene.registerBeforeRender())
  140. */
  141. update(): void;
  142. private _getAngleDiff;
  143. private _getAngleBetween;
  144. private _isAngleBetween;
  145. private _updateLinkedTransformRotation;
  146. }