2
0

LineGeometry.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. console.error( 'THREE.LineGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  42. return;
  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. } );