babylon.linesMesh.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. var LinesMesh = (function (_super) {
  9. __extends(LinesMesh, _super);
  10. function LinesMesh(name, scene, parent, source, doNotCloneChildren) {
  11. if (parent === void 0) { parent = null; }
  12. _super.call(this, name, scene, parent, source, doNotCloneChildren);
  13. this.color = new BABYLON.Color3(1, 1, 1);
  14. this.alpha = 1;
  15. this._intersectionThreshold = 0.1;
  16. this._colorShader = new BABYLON.ShaderMaterial("colorShader", scene, "color", {
  17. attributes: ["position"],
  18. uniforms: ["worldViewProjection", "color"],
  19. needAlphaBlending: true
  20. });
  21. }
  22. Object.defineProperty(LinesMesh.prototype, "intersectionThreshold", {
  23. /**
  24. * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.
  25. * This margin is expressed in world space coordinates, so its value may vary.
  26. * Default value is 0.1
  27. * @returns the intersection Threshold value.
  28. */
  29. get: function () {
  30. return this._intersectionThreshold;
  31. },
  32. /**
  33. * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.
  34. * This margin is expressed in world space coordinates, so its value may vary.
  35. * @param value the new threshold to apply
  36. */
  37. set: function (value) {
  38. if (this._intersectionThreshold === value) {
  39. return;
  40. }
  41. this._intersectionThreshold = value;
  42. if (this.geometry) {
  43. this.geometry.boundingBias = new BABYLON.Vector2(0, value);
  44. }
  45. },
  46. enumerable: true,
  47. configurable: true
  48. });
  49. Object.defineProperty(LinesMesh.prototype, "material", {
  50. get: function () {
  51. return this._colorShader;
  52. },
  53. enumerable: true,
  54. configurable: true
  55. });
  56. Object.defineProperty(LinesMesh.prototype, "isPickable", {
  57. get: function () {
  58. return true;
  59. },
  60. enumerable: true,
  61. configurable: true
  62. });
  63. Object.defineProperty(LinesMesh.prototype, "checkCollisions", {
  64. get: function () {
  65. return false;
  66. },
  67. enumerable: true,
  68. configurable: true
  69. });
  70. LinesMesh.prototype._bind = function (subMesh, effect, fillMode) {
  71. var engine = this.getScene().getEngine();
  72. var indexToBind = this._geometry.getIndexBuffer();
  73. // VBOs
  74. engine.bindBuffers(this._geometry.getVertexBuffer(BABYLON.VertexBuffer.PositionKind).getBuffer(), indexToBind, [3], 3 * 4, this._colorShader.getEffect());
  75. // Color
  76. this._colorShader.setColor4("color", this.color.toColor4(this.alpha));
  77. };
  78. LinesMesh.prototype._draw = function (subMesh, fillMode, instancesCount) {
  79. if (!this._geometry || !this._geometry.getVertexBuffers() || !this._geometry.getIndexBuffer()) {
  80. return;
  81. }
  82. var engine = this.getScene().getEngine();
  83. // Draw order
  84. engine.draw(false, subMesh.indexStart, subMesh.indexCount);
  85. };
  86. LinesMesh.prototype.dispose = function (doNotRecurse) {
  87. this._colorShader.dispose();
  88. _super.prototype.dispose.call(this, doNotRecurse);
  89. };
  90. LinesMesh.prototype.clone = function (name, newParent, doNotCloneChildren) {
  91. return new LinesMesh(name, this.getScene(), newParent, this, doNotCloneChildren);
  92. };
  93. return LinesMesh;
  94. })(BABYLON.Mesh);
  95. BABYLON.LinesMesh = LinesMesh;
  96. })(BABYLON || (BABYLON = {}));