LineGeometry.js 1.9 KB

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