babylon.axesViewer.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. module BABYLON.Debug {
  2. export class AxesViewer {
  3. private _xline = [Vector3.Zero(), Vector3.Zero()];
  4. private _yline = [Vector3.Zero(), Vector3.Zero()];
  5. private _zline = [Vector3.Zero(), Vector3.Zero()];
  6. private _xmesh: LinesMesh;
  7. private _ymesh: LinesMesh;
  8. private _zmesh: LinesMesh;
  9. public scene: Scene;
  10. public scaleLines = 1;
  11. constructor(scene: Scene, scaleLines = 1) {
  12. this.scaleLines = scaleLines;
  13. this._xmesh = Mesh.CreateLines("xline", this._xline, scene, true);
  14. this._ymesh = Mesh.CreateLines("yline", this._yline, scene, true);
  15. this._zmesh = Mesh.CreateLines("zline", this._zline, scene, true);
  16. this._xmesh.renderingGroupId = 2;
  17. this._ymesh.renderingGroupId = 2;
  18. this._zmesh.renderingGroupId = 2;
  19. this._xmesh.material.checkReadyOnlyOnce = true;
  20. this._xmesh.color = new BABYLON.Color3(1, 0, 0);
  21. this._ymesh.material.checkReadyOnlyOnce = true;
  22. this._ymesh.color = new BABYLON.Color3(0, 1, 0);
  23. this._zmesh.material.checkReadyOnlyOnce = true;
  24. this._zmesh.color = new BABYLON.Color3(0, 0, 1);
  25. this.scene = scene;
  26. }
  27. public update (position: Vector3, xaxis: Vector3, yaxis: Vector3, zaxis: Vector3): void {
  28. var scaleLines = this.scaleLines;
  29. var point1 = this._xline[0];
  30. var point2 = this._xline[1];
  31. point1.x = position.x;
  32. point1.y = position.y;
  33. point1.z = position.z;
  34. point2.x = point1.x + xaxis.x * scaleLines;
  35. point2.y = point1.y + xaxis.y * scaleLines;
  36. point2.z = point1.z + xaxis.z * scaleLines;
  37. Mesh.CreateLines(null, this._xline, null, null, this._xmesh);
  38. point1 = this._yline[0];
  39. point2 = this._yline[1];
  40. point1.x = position.x;
  41. point1.y = position.y;
  42. point1.z = position.z;
  43. point2.x = point1.x + yaxis.x * scaleLines;
  44. point2.y = point1.y + yaxis.y * scaleLines;
  45. point2.z = point1.z + yaxis.z * scaleLines;
  46. Mesh.CreateLines(null, this._yline, null, null, this._ymesh);
  47. point1 = this._zline[0];
  48. point2 = this._zline[1];
  49. point1.x = position.x;
  50. point1.y = position.y;
  51. point1.z = position.z;
  52. point2.x = point1.x + zaxis.x * scaleLines;
  53. point2.y = point1.y + zaxis.y * scaleLines;
  54. point2.z = point1.z + zaxis.z * scaleLines;
  55. Mesh.CreateLines(null, this._zline, null, null, this._zmesh);
  56. }
  57. public dispose() {
  58. if (this._xmesh) {
  59. this._xmesh.dispose();
  60. this._ymesh.dispose();
  61. this._zmesh.dispose();
  62. this._xmesh = null;
  63. this._ymesh = null;
  64. this._zmesh = null;
  65. this._xline = null;
  66. this._yline = null;
  67. this._zline = null;
  68. this.scene = null;
  69. }
  70. }
  71. }
  72. }