babylon.axesViewer.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * Module Debug contains the (visual) components to debug a scene correctly
  3. */
  4. module BABYLON.Debug {
  5. /**
  6. * The Axes viewer will show 3 axes in a specific point in space
  7. */
  8. export class AxesViewer {
  9. private _xline = [Vector3.Zero(), Vector3.Zero()];
  10. private _yline = [Vector3.Zero(), Vector3.Zero()];
  11. private _zline = [Vector3.Zero(), Vector3.Zero()];
  12. private _xmesh: Nullable<LinesMesh>;
  13. private _ymesh: Nullable<LinesMesh>;
  14. private _zmesh: Nullable<LinesMesh>;
  15. /**
  16. * Gets the hosting scene
  17. */
  18. public scene: Nullable<Scene>;
  19. /**
  20. * Gets or sets a number used to scale line length
  21. */
  22. public scaleLines = 1;
  23. /**
  24. * Creates a new AxesViewer
  25. * @param scene defines the hosting scene
  26. * @param scaleLines defines a number used to scale line length (1 by default)
  27. */
  28. constructor(scene: Scene, scaleLines = 1) {
  29. this.scaleLines = scaleLines;
  30. this._xmesh = Mesh.CreateLines("xline", this._xline, scene, true);
  31. this._ymesh = Mesh.CreateLines("yline", this._yline, scene, true);
  32. this._zmesh = Mesh.CreateLines("zline", this._zline, scene, true);
  33. this._xmesh.renderingGroupId = 2;
  34. this._ymesh.renderingGroupId = 2;
  35. this._zmesh.renderingGroupId = 2;
  36. this._xmesh.material.checkReadyOnlyOnce = true;
  37. this._xmesh.color = new Color3(1, 0, 0);
  38. this._ymesh.material.checkReadyOnlyOnce = true;
  39. this._ymesh.color = new Color3(0, 1, 0);
  40. this._zmesh.material.checkReadyOnlyOnce = true;
  41. this._zmesh.color = new Color3(0, 0, 1);
  42. this.scene = scene;
  43. }
  44. /**
  45. * Force the viewer to update
  46. * @param position defines the position of the viewer
  47. * @param xaxis defines the x axis of the viewer
  48. * @param yaxis defines the y axis of the viewer
  49. * @param zaxis defines the z axis of the viewer
  50. */
  51. public update(position: Vector3, xaxis: Vector3, yaxis: Vector3, zaxis: Vector3): void {
  52. var scaleLines = this.scaleLines;
  53. if (this._xmesh) {
  54. this._xmesh.position.copyFrom(position);
  55. }
  56. if (this._ymesh) {
  57. this._ymesh.position.copyFrom(position);
  58. }
  59. if (this._zmesh) {
  60. this._zmesh.position.copyFrom(position);
  61. }
  62. var point2 = this._xline[1];
  63. point2.x = xaxis.x * scaleLines;
  64. point2.y = xaxis.y * scaleLines;
  65. point2.z = xaxis.z * scaleLines;
  66. Mesh.CreateLines("", this._xline, null, false, this._xmesh);
  67. point2 = this._yline[1];
  68. point2.x = yaxis.x * scaleLines;
  69. point2.y = yaxis.y * scaleLines;
  70. point2.z = yaxis.z * scaleLines;
  71. Mesh.CreateLines("", this._yline, null, false, this._ymesh);
  72. point2 = this._zline[1];
  73. point2.x = zaxis.x * scaleLines;
  74. point2.y = zaxis.y * scaleLines;
  75. point2.z = zaxis.z * scaleLines;
  76. Mesh.CreateLines("", this._zline, null, false, this._zmesh);
  77. }
  78. /** Releases resources */
  79. public dispose() {
  80. if (this._xmesh) {
  81. this._xmesh.dispose();
  82. }
  83. if (this._ymesh) {
  84. this._ymesh.dispose();
  85. }
  86. if (this._zmesh) {
  87. this._zmesh.dispose();
  88. }
  89. this._xmesh = null;
  90. this._ymesh = null;
  91. this._zmesh = null;
  92. this.scene = null;
  93. }
  94. }
  95. }