LineGeometry.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. this.setPositions( geometry.vertices );
  43. } else if ( geometry.isBufferGeometry ) {
  44. this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
  45. }
  46. // set colors, maybe
  47. return this;
  48. },
  49. copy: function ( /* source */ ) {
  50. // todo
  51. return this;
  52. }
  53. } );
  54. export { LineGeometry };