LineGeometry.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. console.warn( "THREE.LineGeometry: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
  2. THREE.LineGeometry = function () {
  3. THREE.LineSegmentsGeometry.call( this );
  4. this.type = 'LineGeometry';
  5. };
  6. THREE.LineGeometry.prototype = Object.assign( Object.create( THREE.LineSegmentsGeometry.prototype ), {
  7. constructor: THREE.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. THREE.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. THREE.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. } );