LineGeometry.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. THREE.LineGeometry = function () {
  2. THREE.LineSegmentsGeometry.call( this );
  3. this.type = 'LineGeometry';
  4. };
  5. THREE.LineGeometry.prototype = Object.assign( Object.create( THREE.LineSegmentsGeometry.prototype ), {
  6. constructor: THREE.LineGeometry,
  7. isLineGeometry: true,
  8. setPositions: function ( array ) {
  9. // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
  10. var length = array.length - 3;
  11. var points = new Float32Array( 2 * length );
  12. for ( var 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. THREE.LineSegmentsGeometry.prototype.setPositions.call( this, points );
  21. return this;
  22. },
  23. setColors: function ( array ) {
  24. // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
  25. var length = array.length - 3;
  26. var colors = new Float32Array( 2 * length );
  27. for ( var 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. THREE.LineSegmentsGeometry.prototype.setColors.call( this, colors );
  36. return this;
  37. },
  38. fromLine: function ( line ) {
  39. var geometry = line.geometry;
  40. if ( geometry.isGeometry ) {
  41. this.setPositions( geometry.vertices );
  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. copy: function ( /* source */ ) {
  49. // todo
  50. return this;
  51. }
  52. } );