skeletonViewer.d.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { Color3 } from "../Maths/math.color";
  2. import type { Scene } from "../scene";
  3. import type { Nullable } from "../types";
  4. import type { Skeleton } from "../Bones/skeleton";
  5. import type { AbstractMesh } from "../Meshes/abstractMesh";
  6. import type { LinesMesh } from "../Meshes/linesMesh";
  7. import { UtilityLayerRenderer } from "../Rendering/utilityLayerRenderer";
  8. import { ShaderMaterial } from "../Materials/shaderMaterial";
  9. import type { ISkeletonViewerOptions, IBoneWeightShaderOptions, ISkeletonMapShaderOptions } from "./ISkeletonViewer";
  10. /**
  11. * Class used to render a debug view of a given skeleton
  12. * @see http://www.babylonjs-playground.com/#1BZJVJ#8
  13. */
  14. export declare class SkeletonViewer {
  15. /** defines the skeleton to render */
  16. skeleton: Skeleton;
  17. /** defines the mesh attached to the skeleton */
  18. mesh: Nullable<AbstractMesh>;
  19. /** defines a boolean indicating if bones matrices must be forced to update before rendering (true by default) */
  20. autoUpdateBonesMatrices: boolean;
  21. /** defines the rendering group id to use with the viewer */
  22. renderingGroupId: number;
  23. /** is the options for the viewer */
  24. options: Partial<ISkeletonViewerOptions>;
  25. /** public Display constants BABYLON.SkeletonViewer.DISPLAY_LINES */
  26. static readonly DISPLAY_LINES = 0;
  27. /** public Display constants BABYLON.SkeletonViewer.DISPLAY_SPHERES */
  28. static readonly DISPLAY_SPHERES = 1;
  29. /** public Display constants BABYLON.SkeletonViewer.DISPLAY_SPHERE_AND_SPURS */
  30. static readonly DISPLAY_SPHERE_AND_SPURS = 2;
  31. /** public static method to create a BoneWeight Shader
  32. * @param options The constructor options
  33. * @param scene The scene that the shader is scoped to
  34. * @returns The created ShaderMaterial
  35. * @see http://www.babylonjs-playground.com/#1BZJVJ#395
  36. */
  37. static CreateBoneWeightShader(options: IBoneWeightShaderOptions, scene: Scene): ShaderMaterial;
  38. /** public static method to create a BoneWeight Shader
  39. * @param options The constructor options
  40. * @param scene The scene that the shader is scoped to
  41. * @returns The created ShaderMaterial
  42. */
  43. static CreateSkeletonMapShader(options: ISkeletonMapShaderOptions, scene: Scene): ShaderMaterial;
  44. /** private static method to create a BoneWeight Shader
  45. * @param size The size of the buffer to create (usually the bone count)
  46. * @param colorMap The gradient data to generate
  47. * @param scene The scene that the shader is scoped to
  48. * @returns an Array of floats from the color gradient values
  49. */
  50. private static _CreateBoneMapColorBuffer;
  51. /** If SkeletonViewer scene scope. */
  52. private _scene;
  53. /** Gets or sets the color used to render the skeleton */
  54. color: Color3;
  55. /** Array of the points of the skeleton fo the line view. */
  56. private _debugLines;
  57. /** The SkeletonViewers Mesh. */
  58. private _debugMesh;
  59. /** The local axes Meshes. */
  60. private _localAxes;
  61. /** If SkeletonViewer is enabled. */
  62. private _isEnabled;
  63. /** If SkeletonViewer is ready. */
  64. private _ready;
  65. /** SkeletonViewer render observable. */
  66. private _obs;
  67. /** The Utility Layer to render the gizmos in. */
  68. private _utilityLayer;
  69. private _boneIndices;
  70. /** Gets the Scene. */
  71. get scene(): Scene;
  72. /** Gets the utilityLayer. */
  73. get utilityLayer(): Nullable<UtilityLayerRenderer>;
  74. /** Checks Ready Status. */
  75. get isReady(): Boolean;
  76. /** Sets Ready Status. */
  77. set ready(value: boolean);
  78. /** Gets the debugMesh */
  79. get debugMesh(): Nullable<AbstractMesh> | Nullable<LinesMesh>;
  80. /** Sets the debugMesh */
  81. set debugMesh(value: Nullable<AbstractMesh> | Nullable<LinesMesh>);
  82. /** Gets the displayMode */
  83. get displayMode(): number;
  84. /** Sets the displayMode */
  85. set displayMode(value: number);
  86. /**
  87. * Creates a new SkeletonViewer
  88. * @param skeleton defines the skeleton to render
  89. * @param mesh defines the mesh attached to the skeleton
  90. * @param scene defines the hosting scene
  91. * @param autoUpdateBonesMatrices defines a boolean indicating if bones matrices must be forced to update before rendering (true by default)
  92. * @param renderingGroupId defines the rendering group id to use with the viewer
  93. * @param options All of the extra constructor options for the SkeletonViewer
  94. */
  95. constructor(
  96. /** defines the skeleton to render */
  97. skeleton: Skeleton,
  98. /** defines the mesh attached to the skeleton */
  99. mesh: Nullable<AbstractMesh>,
  100. /** The Scene scope*/
  101. scene: Scene,
  102. /** defines a boolean indicating if bones matrices must be forced to update before rendering (true by default) */
  103. autoUpdateBonesMatrices?: boolean,
  104. /** defines the rendering group id to use with the viewer */
  105. renderingGroupId?: number,
  106. /** is the options for the viewer */
  107. options?: Partial<ISkeletonViewerOptions>);
  108. /** The Dynamic bindings for the update functions */
  109. private _bindObs;
  110. /** Update the viewer to sync with current skeleton state, only used to manually update. */
  111. update(): void;
  112. /** Gets or sets a boolean indicating if the viewer is enabled */
  113. set isEnabled(value: boolean);
  114. get isEnabled(): boolean;
  115. private _getBonePosition;
  116. private _getLinesForBonesWithLength;
  117. private _getLinesForBonesNoLength;
  118. /**
  119. * function to revert the mesh and scene back to the initial state.
  120. * @param animationState
  121. */
  122. private _revert;
  123. /**
  124. * function to get the absolute bind pose of a bone by accumulating transformations up the bone hierarchy.
  125. * @param bone
  126. * @param matrix
  127. */
  128. private _getAbsoluteBindPoseToRef;
  129. private _createSpur;
  130. private _getBoundingSphereForBone;
  131. /**
  132. * function to build and bind sphere joint points and spur bone representations.
  133. * @param spheresOnly
  134. */
  135. private _buildSpheresAndSpurs;
  136. private _buildLocalAxes;
  137. /** Update the viewer to sync with current skeleton state, only used for the line display. */
  138. private _displayLinesUpdate;
  139. /** Changes the displayMode of the skeleton viewer
  140. * @param mode The displayMode numerical value
  141. */
  142. changeDisplayMode(mode: number): void;
  143. /** Sets a display option of the skeleton viewer
  144. *
  145. * | Option | Type | Default | Description |
  146. * | ---------------- | ------- | ------- | ----------- |
  147. * | midStep | float | 0.235 | A percentage between a bone and its child that determines the widest part of a spur. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
  148. * | midStepFactor | float | 0.15 | Mid step width expressed as a factor of the length. A value of 0.5 makes the spur width half of the spur length. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
  149. * | sphereBaseSize | float | 2 | Sphere base size. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
  150. * | sphereScaleUnit | float | 0.865 | Sphere scale factor used to scale spheres in relation to the longest bone. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
  151. * | spurFollowsChild | boolean | false | Whether a spur should attach its far end to the child bone. |
  152. * | showLocalAxes | boolean | false | Displays local axes on all bones. |
  153. * | localAxesSize | float | 0.075 | Determines the length of each local axis. |
  154. *
  155. * @param option String of the option name
  156. * @param value The numerical option value
  157. */
  158. changeDisplayOptions(option: string, value: number): void;
  159. /** Release associated resources */
  160. dispose(): void;
  161. }