LineGeometry.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ( function () {
  2. class LineGeometry extends THREE.LineSegmentsGeometry {
  3. constructor() {
  4. super();
  5. this.type = 'LineGeometry';
  6. }
  7. setPositions( array ) {
  8. // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
  9. var length = array.length - 3;
  10. var points = new Float32Array( 2 * length );
  11. for ( var i = 0; i < length; i += 3 ) {
  12. points[ 2 * i ] = array[ i ];
  13. points[ 2 * i + 1 ] = array[ i + 1 ];
  14. points[ 2 * i + 2 ] = array[ i + 2 ];
  15. points[ 2 * i + 3 ] = array[ i + 3 ];
  16. points[ 2 * i + 4 ] = array[ i + 4 ];
  17. points[ 2 * i + 5 ] = array[ i + 5 ];
  18. }
  19. super.setPositions( points );
  20. return this;
  21. }
  22. setColors( array ) {
  23. // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
  24. var length = array.length - 3;
  25. var colors = new Float32Array( 2 * length );
  26. for ( var i = 0; i < length; i += 3 ) {
  27. colors[ 2 * i ] = array[ i ];
  28. colors[ 2 * i + 1 ] = array[ i + 1 ];
  29. colors[ 2 * i + 2 ] = array[ i + 2 ];
  30. colors[ 2 * i + 3 ] = array[ i + 3 ];
  31. colors[ 2 * i + 4 ] = array[ i + 4 ];
  32. colors[ 2 * i + 5 ] = array[ i + 5 ];
  33. }
  34. super.setColors( colors );
  35. return this;
  36. }
  37. fromLine( line ) {
  38. var geometry = line.geometry;
  39. if ( geometry.isGeometry ) {
  40. console.error( 'THREE.LineGeometry no longer supports Geometry. Use THREE.BufferGeometry instead.' );
  41. return;
  42. } else if ( geometry.isBufferGeometry ) {
  43. this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
  44. } // set colors, maybe
  45. return this;
  46. }
  47. }
  48. LineGeometry.prototype.isLineGeometry = true;
  49. THREE.LineGeometry = LineGeometry;
  50. } )();