boneAxesViewer.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { AxesViewer } from "../Debug/axesViewer.js";
  2. import { Vector3 } from "../Maths/math.vector.js";
  3. import { Axis } from "../Maths/math.axis.js";
  4. /**
  5. * The BoneAxesViewer will attach 3 axes to a specific bone of a specific mesh
  6. * @see demo here: https://www.babylonjs-playground.com/#0DE8F4#8
  7. */
  8. export class BoneAxesViewer extends AxesViewer {
  9. /**
  10. * Creates a new BoneAxesViewer
  11. * @param scene defines the hosting scene
  12. * @param bone defines the target bone
  13. * @param mesh defines the target mesh
  14. * @param scaleLines defines a scaling factor for line length (1 by default)
  15. */
  16. constructor(scene, bone, mesh, scaleLines = 1) {
  17. super(scene, scaleLines);
  18. /** Gets current position */
  19. this.pos = Vector3.Zero();
  20. /** Gets direction of X axis */
  21. this.xaxis = Vector3.Zero();
  22. /** Gets direction of Y axis */
  23. this.yaxis = Vector3.Zero();
  24. /** Gets direction of Z axis */
  25. this.zaxis = Vector3.Zero();
  26. this.mesh = mesh;
  27. this.bone = bone;
  28. }
  29. /**
  30. * Force the viewer to update
  31. */
  32. update() {
  33. if (!this.mesh || !this.bone) {
  34. return;
  35. }
  36. const bone = this.bone;
  37. bone.getAbsolutePositionToRef(this.mesh, this.pos);
  38. bone.getDirectionToRef(Axis.X, this.mesh, this.xaxis);
  39. bone.getDirectionToRef(Axis.Y, this.mesh, this.yaxis);
  40. bone.getDirectionToRef(Axis.Z, this.mesh, this.zaxis);
  41. super.update(this.pos, this.xaxis, this.yaxis, this.zaxis);
  42. }
  43. /** Releases resources */
  44. dispose() {
  45. if (this.mesh) {
  46. this.mesh = null;
  47. this.bone = null;
  48. super.dispose();
  49. }
  50. }
  51. }
  52. //# sourceMappingURL=boneAxesViewer.js.map