LineGeometry.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. console.warn( "THREE.LineGeometry: As part of the transition to ES6 Modules, the files in 'examples/js' have been deprecated in r117 (May 2020) and will be deleted in r124 (December 2020). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author WestLangley / http://github.com/WestLangley
  4. *
  5. */
  6. THREE.LineGeometry = function () {
  7. THREE.LineSegmentsGeometry.call( this );
  8. this.type = 'LineGeometry';
  9. };
  10. THREE.LineGeometry.prototype = Object.assign( Object.create( THREE.LineSegmentsGeometry.prototype ), {
  11. constructor: THREE.LineGeometry,
  12. isLineGeometry: true,
  13. setPositions: function ( array ) {
  14. // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
  15. var length = array.length - 3;
  16. var points = new Float32Array( 2 * length );
  17. for ( var i = 0; i < length; i += 3 ) {
  18. points[ 2 * i ] = array[ i ];
  19. points[ 2 * i + 1 ] = array[ i + 1 ];
  20. points[ 2 * i + 2 ] = array[ i + 2 ];
  21. points[ 2 * i + 3 ] = array[ i + 3 ];
  22. points[ 2 * i + 4 ] = array[ i + 4 ];
  23. points[ 2 * i + 5 ] = array[ i + 5 ];
  24. }
  25. THREE.LineSegmentsGeometry.prototype.setPositions.call( this, points );
  26. return this;
  27. },
  28. setColors: function ( array ) {
  29. // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
  30. var length = array.length - 3;
  31. var colors = new Float32Array( 2 * length );
  32. for ( var i = 0; i < length; i += 3 ) {
  33. colors[ 2 * i ] = array[ i ];
  34. colors[ 2 * i + 1 ] = array[ i + 1 ];
  35. colors[ 2 * i + 2 ] = array[ i + 2 ];
  36. colors[ 2 * i + 3 ] = array[ i + 3 ];
  37. colors[ 2 * i + 4 ] = array[ i + 4 ];
  38. colors[ 2 * i + 5 ] = array[ i + 5 ];
  39. }
  40. THREE.LineSegmentsGeometry.prototype.setColors.call( this, colors );
  41. return this;
  42. },
  43. fromLine: function ( line ) {
  44. var geometry = line.geometry;
  45. if ( geometry.isGeometry ) {
  46. this.setPositions( geometry.vertices );
  47. } else if ( geometry.isBufferGeometry ) {
  48. this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
  49. }
  50. // set colors, maybe
  51. return this;
  52. },
  53. copy: function ( /* source */ ) {
  54. // todo
  55. return this;
  56. }
  57. } );