LineGeometry.js 1.8 KB

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