Home Reference Source

cables_dev/cables/src/libs/cgl/wireframes/cgl_wireframecube.js

  1. export { WireframeCube };
  2.  
  3. class WireframeCube
  4. {
  5. constructor(_cgl)
  6. {
  7. this.cgl = _cgl;
  8. this.geom = new CGL.Geometry("marker");
  9. this.geom.setPointVertices(
  10. [
  11. // frontal
  12. -1, -1, 1,
  13. 1, -1, 1,
  14.  
  15. 1, 1, 1,
  16. -1, 1, 1,
  17.  
  18. -1, -1, -1,
  19. 1, -1, -1,
  20.  
  21. -1, 1, -1,
  22. 1, 1, -1,
  23.  
  24. // vertical lines
  25. 1, -1, -1,
  26. 1, 1, -1,
  27.  
  28. -1, 1, -1,
  29. -1, -1, -1,
  30.  
  31. 1, 1, 1,
  32. 1, -1, 1,
  33.  
  34. -1, 1, 1,
  35. -1, -1, 1,
  36.  
  37. // horizontal lines
  38. 1, 1, -1,
  39. 1, 1, 1,
  40.  
  41. -1, 1, -1,
  42. -1, 1, 1,
  43.  
  44. 1, -1, 1,
  45. 1, -1, -1,
  46.  
  47. -1, -1, 1,
  48. -1, -1, -1,
  49. ]
  50. );
  51.  
  52. this.mesh = new CGL.Mesh(this.cgl, this.geom, this.cgl.gl.LINES);
  53. this.mesh.setGeom(this.geom);
  54.  
  55. this.colorShader = new CGL.UniColorShader(this.cgl);
  56. this.colorShader.setColor([0, 1, 1, 1]);
  57.  
  58. this._vScale = vec3.create();
  59. }
  60.  
  61. render(_scaleX, _scaleY, _scaleZ)
  62. {
  63. this.cgl.pushModelMatrix();
  64. this.cgl.pushShader(this.colorShader.shader);
  65. this.cgl.pushDepthTest(false);
  66.  
  67. if (_scaleX == undefined) _scaleX = 1.0;
  68. if (_scaleY == undefined) _scaleY = _scaleX;
  69. if (_scaleZ == undefined) _scaleZ = _scaleX;
  70.  
  71.  
  72. // vec3.set(this._vScale, _scaleX || 1, _scaleY || _scaleX || 1, _scaleZ || _scaleX || 1);
  73. vec3.set(this._vScale, _scaleX, _scaleY, _scaleZ);
  74. mat4.scale(this.cgl.mvMatrix, this.cgl.mvMatrix, this._vScale);
  75.  
  76. this.mesh.render(this.cgl.getShader());
  77.  
  78. this.cgl.popDepthTest();
  79. this.cgl.popShader();
  80. this.cgl.popModelMatrix();
  81. }
  82. }