babylon.linesMesh.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /// <reference path="babylon.mesh.ts" />
  2. module BABYLON {
  3. export class LinesMesh extends Mesh {
  4. public color = new Color3(1, 1, 1);
  5. public alpha = 1;
  6. /**
  7. * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.
  8. * This margin is expressed in world space coordinates, so its value may vary.
  9. * Default value is 0.1
  10. * @returns the intersection Threshold value.
  11. */
  12. public get intersectionThreshold(): number {
  13. return this._intersectionThreshold;
  14. }
  15. /**
  16. * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.
  17. * This margin is expressed in world space coordinates, so its value may vary.
  18. * @param value the new threshold to apply
  19. */
  20. public set intersectionThreshold(value: number) {
  21. if (this._intersectionThreshold === value) {
  22. return;
  23. }
  24. this._intersectionThreshold = value;
  25. if (this.geometry) {
  26. this.geometry.boundingBias = new Vector2(0, value);
  27. }
  28. }
  29. private _intersectionThreshold: number;
  30. private _colorShader: ShaderMaterial;
  31. constructor(name: string, scene: Scene, parent: Node = null, source?: LinesMesh, doNotCloneChildren?: boolean, public useVertexColor? : boolean) {
  32. super(name, scene, parent, source, doNotCloneChildren);
  33. if (source) {
  34. this.color = source.color.clone();
  35. this.alpha = source.alpha;
  36. this.useVertexColor = source.useVertexColor;
  37. }
  38. this._intersectionThreshold = 0.1;
  39. var options = {
  40. attributes: [VertexBuffer.PositionKind],
  41. uniforms: ["world", "viewProjection"],
  42. needAlphaBlending: false,
  43. };
  44. if (!useVertexColor) {
  45. options.uniforms.push("color");
  46. options.needAlphaBlending = true;
  47. }
  48. this._colorShader = new ShaderMaterial("colorShader", scene, "color", options);
  49. }
  50. /**
  51. * Returns the string "LineMesh"
  52. */
  53. public getClassName(): string {
  54. return "LinesMesh";
  55. }
  56. public get material(): Material {
  57. return this._colorShader;
  58. }
  59. public get checkCollisions(): boolean {
  60. return false;
  61. }
  62. public createInstance(name: string): InstancedMesh {
  63. Tools.Log("LinesMeshes do not support createInstance.");
  64. return null;
  65. }
  66. public _bind(subMesh: SubMesh, effect: Effect, fillMode: number): LinesMesh {
  67. // VBOs
  68. this._geometry._bind(this._colorShader.getEffect() );
  69. // Color
  70. if (!this.useVertexColor) {
  71. this._colorShader.setColor4("color", this.color.toColor4(this.alpha));
  72. }
  73. return this;
  74. }
  75. public _draw(subMesh: SubMesh, fillMode: number, instancesCount?: number): LinesMesh {
  76. if (!this._geometry || !this._geometry.getVertexBuffers() || !this._geometry.getIndexBuffer()) {
  77. return this;
  78. }
  79. var engine = this.getScene().getEngine();
  80. // Draw order
  81. engine.draw(false, subMesh.indexStart, subMesh.indexCount);
  82. return this;
  83. }
  84. public dispose(doNotRecurse?: boolean): void {
  85. this._colorShader.dispose();
  86. super.dispose(doNotRecurse);
  87. }
  88. /**
  89. * Returns a new LineMesh object cloned from the current one.
  90. */
  91. public clone(name: string, newParent?: Node, doNotCloneChildren?: boolean): LinesMesh {
  92. return new LinesMesh(name, this.getScene(), newParent, this, doNotCloneChildren);
  93. }
  94. }
  95. }