LineGeometry.js 1.6 KB

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