/home/lindsay/xeolabs/xeogl-next/xeogl/examples/js/helpers/splineCurveHelper.js
API Docs for:

File: /home/lindsay/xeolabs/xeogl-next/xeogl/examples/js/helpers/splineCurveHelper.js

  1. /**
  2. Shows the shape and control points of {{#crossLink "SplineCurve"}}{{/crossLink}}
  3.  
  4. @class SplineCurveHelper
  5. @module meshes
  6. @extends Component
  7. */
  8. xeogl.SplineCurveHelper = class xeoglSplineCurveHelper extends xeogl.Component {
  9.  
  10. init(cfg) {
  11. super.init(cfg);
  12. this._divisions = 100;
  13.  
  14. this._splineCurve = cfg.splineCurve;
  15. if (this._splineCurve) {
  16. const self = this;
  17. this._onPathCurves = this._splineCurve.on("curves", () => {
  18. self._needUpdate();
  19. });
  20. }
  21. }
  22.  
  23. _update() {
  24. if (this._line) {
  25. this._line.geometry.destroy();
  26. this._line.material.destroy();
  27. this._line.destroy();
  28. }
  29. const splineCurve = this._splineCurve;
  30. if (!splineCurve) {
  31. return;
  32. }
  33. const points = splineCurve.getPoints(this._divisions);
  34. const positions = [];
  35. let point;
  36. for (var i = 0, len = points.length; i < len; i++) {
  37. point = points[i];
  38. positions.push(point[0]);
  39. positions.push(point[1]);
  40. positions.push(point[2]);
  41. }
  42. const indices = [];
  43. for (var i = 0, len = points.length - 1; i < len; i++) {
  44. indices.push(i);
  45. indices.push(i + 1);
  46. }
  47. this._line = new xeogl.Mesh(this, {
  48. geometry: new xeogl.Geometry(this, {
  49. primitive: "lines",
  50. positions: positions,
  51. indices: indices
  52. }),
  53. material: new xeogl.PhongMaterial(this, {
  54. diffuse: [1, 0, 0]
  55. })
  56. });
  57. }
  58.  
  59. /**
  60. The SplineCurve for this SplineCurveHelper.
  61.  
  62. @property splinecurve
  63. @type {SplineCurve}
  64. @final
  65. */
  66.  
  67. get splineCurve() {
  68. return this._splineCurve;
  69. }
  70.  
  71. destroy() {
  72. if (this._splineCurve) {
  73. this._splineCurve.off(this._onPathCurves);
  74. }
  75. super.destroy();
  76. }
  77. };