babylon.axesViewer.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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: Nullable<LinesMesh>;
  7. private _ymesh: Nullable<LinesMesh>;
  8. private _zmesh: Nullable<LinesMesh>;
  9. public scene: Nullable<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 Color3(1, 0, 0);
  21. this._ymesh.material.checkReadyOnlyOnce = true;
  22. this._ymesh.color = new Color3(0, 1, 0);
  23. this._zmesh.material.checkReadyOnlyOnce = true;
  24. this._zmesh.color = new 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. if (this._xmesh) {
  30. this._xmesh.position.copyFrom(position);
  31. }
  32. if (this._ymesh) {
  33. this._ymesh.position.copyFrom(position);
  34. }
  35. if (this._zmesh) {
  36. this._zmesh.position.copyFrom(position);
  37. }
  38. var point2 = this._xline[1];
  39. point2.x = xaxis.x * scaleLines;
  40. point2.y = xaxis.y * scaleLines;
  41. point2.z = xaxis.z * scaleLines;
  42. Mesh.CreateLines("", this._xline, null, false, this._xmesh);
  43. point2 = this._yline[1];
  44. point2.x = yaxis.x * scaleLines;
  45. point2.y = yaxis.y * scaleLines;
  46. point2.z = yaxis.z * scaleLines;
  47. Mesh.CreateLines("", this._yline, null, false, this._ymesh);
  48. point2 = this._zline[1];
  49. point2.x = zaxis.x * scaleLines;
  50. point2.y = zaxis.y * scaleLines;
  51. point2.z = zaxis.z * scaleLines;
  52. Mesh.CreateLines("", this._zline, null, false, this._zmesh);
  53. }
  54. public dispose() {
  55. if (this._xmesh) {
  56. this._xmesh.dispose();
  57. }
  58. if (this._ymesh) {
  59. this._ymesh.dispose();
  60. }
  61. if (this._zmesh) {
  62. this._zmesh.dispose();
  63. }
  64. this._xmesh = null;
  65. this._ymesh = null;
  66. this._zmesh = null;
  67. this.scene = null;
  68. }
  69. }
  70. }