LineGeometry.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { LineSegmentsGeometry } from '../lines/LineSegmentsGeometry.js';
  2. var LineGeometry = function () {
  3. LineSegmentsGeometry.call( this );
  4. this.type = 'LineGeometry';
  5. };
  6. LineGeometry.prototype = Object.assign( Object.create( 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. 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. 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. }
  47. // set colors, maybe
  48. return this;
  49. },
  50. copy: function ( /* source */ ) {
  51. // todo
  52. return this;
  53. }
  54. } );
  55. export { LineGeometry };