Line2.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { LineSegments2 } from '../lines/LineSegments2.js';
  2. import { LineGeometry } from '../lines/LineGeometry.js';
  3. import { LineMaterial } from '../lines/LineMaterial.js';
  4. /**
  5. * A polyline drawn between vertices.
  6. *
  7. * This adds functionality beyond {@link Line}, like arbitrary line width and changing width to
  8. * be in world units.It extends {@link LineSegments2}, simplifying constructing segments from a
  9. * chain of points.
  10. *
  11. * This module can only be used with {@link WebGLRenderer}. When using {@link WebGPURenderer},
  12. * import the class from `lines/webgpu/Line2.js`.
  13. *
  14. * ```js
  15. * const geometry = new LineGeometry();
  16. * geometry.setPositions( positions );
  17. * geometry.setColors( colors );
  18. *
  19. * const material = new LineMaterial( { linewidth: 5, vertexColors: true } };
  20. *
  21. * const line = new Line2( geometry, material );
  22. * scene.add( line );
  23. * ```
  24. *
  25. * @augments LineSegments2
  26. * @three_import import { Line2 } from 'three/addons/lines/Line2.js';
  27. */
  28. class Line2 extends LineSegments2 {
  29. /**
  30. * Constructs a new wide line.
  31. *
  32. * @param {LineGeometry} [geometry] - The line geometry.
  33. * @param {LineMaterial} [material] - The line material.
  34. */
  35. constructor( geometry = new LineGeometry(), material = new LineMaterial( { color: Math.random() * 0xffffff } ) ) {
  36. super( geometry, material );
  37. /**
  38. * This flag can be used for type testing.
  39. *
  40. * @type {boolean}
  41. * @readonly
  42. * @default true
  43. */
  44. this.isLine2 = true;
  45. this.type = 'Line2';
  46. }
  47. }
  48. export { Line2 };