babylon.boneAxesViewer.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. module BABYLON.Debug {
  2. /**
  3. * The BoneAxesViewer will attach 3 axes to a specific bone of a specific mesh
  4. * @see demo here: https://www.babylonjs-playground.com/#0DE8F4#8
  5. */
  6. export class BoneAxesViewer extends AxesViewer {
  7. /**
  8. * Gets or sets the target mesh where to display the axes viewer
  9. */
  10. public mesh: Nullable<Mesh>;
  11. /**
  12. * Gets or sets the target bone where to display the axes viewer
  13. */
  14. public bone: Nullable<Bone>;
  15. /** Gets current position */
  16. public pos = Vector3.Zero();
  17. /** Gets direction of X axis */
  18. public xaxis = Vector3.Zero();
  19. /** Gets direction of Y axis */
  20. public yaxis = Vector3.Zero();
  21. /** Gets direction of Z axis */
  22. public zaxis = Vector3.Zero();
  23. /**
  24. * Creates a new BoneAxesViewer
  25. * @param scene defines the hosting scene
  26. * @param bone defines the target bone
  27. * @param mesh defines the target mesh
  28. * @param scaleLines defines a scaling factor for line length (1 by default)
  29. */
  30. constructor(scene: Scene, bone: Bone, mesh: Mesh, scaleLines = 1) {
  31. super(scene, scaleLines);
  32. this.mesh = mesh;
  33. this.bone = bone;
  34. }
  35. /**
  36. * Force the viewer to update
  37. */
  38. public update(): void {
  39. if (!this.mesh || !this.bone) {
  40. return;
  41. }
  42. var bone = this.bone;
  43. bone.getAbsolutePositionToRef(this.mesh, this.pos);
  44. bone.getDirectionToRef(Axis.X, this.mesh, this.xaxis);
  45. bone.getDirectionToRef(Axis.Y, this.mesh, this.yaxis);
  46. bone.getDirectionToRef(Axis.Z, this.mesh, this.zaxis);
  47. super.update(this.pos, this.xaxis, this.yaxis, this.zaxis);
  48. }
  49. /** Releases resources */
  50. public dispose() {
  51. if (this.mesh) {
  52. this.mesh = null;
  53. this.bone = null;
  54. super.dispose();
  55. }
  56. }
  57. }
  58. }