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

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

  1. /**
  2.  
  3. Helper that visualizes the position and direction of a {{#crossLink "Clip"}}{{/crossLink}}.
  4.  
  5. The helper works by tracking updates to the {{#crossLink "Clip"}}{{/crossLink}}'s
  6. {{#crossLink "Clip/pos:property"}}{{/crossLink}} and {{#crossLink "Clip/dir:property"}}{{/crossLink}}.
  7.  
  8. @class ClipHelper
  9. @constructor
  10. @param cfg {*} Configuration
  11. @param cfg.clip {Clip} A {{#crossLink "Clip"}}{{/crossLink}} to visualize.
  12. @param [cfg.solid=true] {Boolean} Indicates whether or not this helper is filled with color or just wireframe.
  13. @param [cfg.visible=true] {Boolean} Indicates whether or not this helper is visible.
  14. @param [cfg.planeSize] {Float32Array} The width and height of the ClipHelper plane indicator.
  15. @param [cfg.autoPlaneSize=false] {Boolean} Indicates whether or not this ClipHelper's
  16. {{#crossLink "ClipHelper/planeSize:property"}}{{/crossLink}} is automatically sized to fit within
  17. the {{#crossLink "Scene/aabb:property"}}Scene's boundary{{/crossLink}}.
  18. */
  19. xeogl.ClipHelper = class xeoglClipHelper extends xeogl.Component {
  20.  
  21. init(cfg) {
  22.  
  23. super.init(cfg);
  24.  
  25. this._planeHelper = new xeogl.PlaneHelper(this);
  26.  
  27. this._clip = cfg.clip;
  28. this.planeSize = cfg.planeSize;
  29. this.autoPlaneSize = cfg.autoPlaneSize;
  30. this.solid = cfg.solid;
  31. this.visible = cfg.visible;
  32.  
  33. var self = this;
  34.  
  35. if (this._clip) {
  36. this._onPos = this._clip.on("pos", function (pos) {
  37. self._planeHelper.pos = pos;
  38. });
  39. this._onDir = this._clip.on("dir", function (dir) {
  40. self._planeHelper.dir = dir;
  41. });
  42. }
  43. }
  44.  
  45. /**
  46. The {{#crossLink "Clip"}}Clip{{/crossLink}} attached to this ClipHelper.
  47.  
  48. @property clip
  49. @type Clip
  50. */
  51. get clip() {
  52. return this._attached.clip;
  53. }
  54.  
  55. /**
  56. The width and height of the ClipHelper plane indicator.
  57.  
  58. When no value is specified, will automatically size to fit within the
  59. {{#crossLink "Scene/aabb:property"}}Scene's boundary{{/crossLink}}.
  60.  
  61. @property planeSize
  62. @default Fitted to scene boundary
  63. @type {Float32Array}
  64. */
  65. set planeSize(value) {
  66. this._planeHelper.planeSize = value;
  67. }
  68.  
  69. get planeSize() {
  70. return this._planeHelper.planeSize;
  71. }
  72.  
  73. /**
  74. Indicates whether this ClipHelper's {{#crossLink "ClipHelper/planeSize:property"}}{{/crossLink}} is automatically
  75. generated or not.
  76.  
  77. When auto-generated, {{#crossLink "ClipHelper/planeSize:property"}}{{/crossLink}} will automatically size
  78. to fit within the {{#crossLink "Scene/aabb:property"}}Scene's boundary{{/crossLink}}.
  79.  
  80. @property autoPlaneSize
  81. @default false
  82. @type {Boolean}
  83. */
  84. set autoPlaneSize(value) {
  85. this._planeHelper.autoPlaneSize = value;
  86. }
  87.  
  88. get autoPlaneSize() {
  89. return this._planeHelper.autoPlaneSize;
  90. }
  91.  
  92. /**
  93. Indicates whether this ClipHelper's plane is filled or just wireframe.
  94.  
  95. @property solid
  96. @default true
  97. @type Boolean
  98. */
  99. set solid(value) {
  100. this._planeHelper.solid = value;
  101. }
  102.  
  103. get solid() {
  104. return this._planeHelper.solid;
  105. }
  106.  
  107. /**
  108. Indicates whether this ClipHelper is visible or not.
  109.  
  110. @property visible
  111. @default true
  112. @type Boolean
  113. */
  114. set visible(value) {
  115. this._planeHelper.visible = value;
  116. }
  117.  
  118. get visible() {
  119. return this._planeHelper.visible;
  120. }
  121.  
  122. destroy() {
  123. super.destroy();
  124. if (this._onPos) {
  125. this._planeHelper.off(this._onPos);
  126. this._planeHelper.off(this._onDir);
  127. }
  128. }
  129. };
  130.