LineGeometry.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { LineSegmentsGeometry } from '../lines/LineSegmentsGeometry.js';
  2. class LineGeometry extends LineSegmentsGeometry {
  3. constructor() {
  4. super();
  5. this.isLineGeometry = true;
  6. this.type = 'LineGeometry';
  7. }
  8. setPositions( array ) {
  9. // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
  10. const length = array.length - 3;
  11. const points = new Float32Array( 2 * length );
  12. for ( let i = 0; i < length; i += 3 ) {
  13. points[ 2 * i ] = array[ i ];
  14. points[ 2 * i + 1 ] = array[ i + 1 ];
  15. points[ 2 * i + 2 ] = array[ i + 2 ];
  16. points[ 2 * i + 3 ] = array[ i + 3 ];
  17. points[ 2 * i + 4 ] = array[ i + 4 ];
  18. points[ 2 * i + 5 ] = array[ i + 5 ];
  19. }
  20. super.setPositions( points );
  21. return this;
  22. }
  23. setColors( array ) {
  24. // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
  25. const length = array.length - 3;
  26. const colors = new Float32Array( 2 * length );
  27. for ( let i = 0; i < length; i += 3 ) {
  28. colors[ 2 * i ] = array[ i ];
  29. colors[ 2 * i + 1 ] = array[ i + 1 ];
  30. colors[ 2 * i + 2 ] = array[ i + 2 ];
  31. colors[ 2 * i + 3 ] = array[ i + 3 ];
  32. colors[ 2 * i + 4 ] = array[ i + 4 ];
  33. colors[ 2 * i + 5 ] = array[ i + 5 ];
  34. }
  35. super.setColors( colors );
  36. return this;
  37. }
  38. fromLine( line ) {
  39. const geometry = line.geometry;
  40. this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
  41. // set colors, maybe
  42. return this;
  43. }
  44. }
  45. export { LineGeometry };