LineGeometry.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. setFromPoints( points ) {
  39. // converts a vector3 or vector2 array to pairs format
  40. const length = points.length - 1;
  41. const positions = new Float32Array( 6 * length );
  42. for ( let i = 0; i < length; i ++ ) {
  43. positions[ 6 * i ] = points[ i ].x;
  44. positions[ 6 * i + 1 ] = points[ i ].y;
  45. positions[ 6 * i + 2 ] = points[ i ].z || 0;
  46. positions[ 6 * i + 3 ] = points[ i + 1 ].x;
  47. positions[ 6 * i + 4 ] = points[ i + 1 ].y;
  48. positions[ 6 * i + 5 ] = points[ i + 1 ].z || 0;
  49. }
  50. super.setPositions( positions );
  51. return this;
  52. }
  53. fromLine( line ) {
  54. const geometry = line.geometry;
  55. this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
  56. // set colors, maybe
  57. return this;
  58. }
  59. }
  60. export { LineGeometry };
粤ICP备19079148号