LineGeometry.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @author WestLangley / http://github.com/WestLangley
  3. *
  4. */
  5. THREE.LineGeometry = function () {
  6. THREE.LineSegmentsGeometry.call( this );
  7. this.type = 'LineGeometry';
  8. };
  9. THREE.LineGeometry.prototype = Object.assign(Object.create(THREE.LineSegmentsGeometry.prototype), {
  10. constructor: THREE.LineGeometry,
  11. isLineGeometry: true,
  12. setPositions: function (array, unpack = false ) {
  13. // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
  14. if (unpack) {
  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. }
  27. else
  28. THREE.LineSegmentsGeometry.prototype.setPositions.call(this, array);
  29. return this;
  30. },
  31. setColors: function (array, unpack = false ) {
  32. // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
  33. if (unpack) {
  34. var length = array.length - 3;
  35. var colors = new Float32Array( 2 * length );
  36. for ( var i = 0; i < length; i += 3 ) {
  37. colors[ 2 * i ] = array[ i ];
  38. colors[ 2 * i + 1 ] = array[ i + 1 ];
  39. colors[ 2 * i + 2 ] = array[ i + 2 ];
  40. colors[ 2 * i + 3 ] = array[ i + 3 ];
  41. colors[ 2 * i + 4 ] = array[ i + 4 ];
  42. colors[ 2 * i + 5 ] = array[ i + 5 ];
  43. }
  44. THREE.LineSegmentsGeometry.prototype.setColors.call( this, colors );
  45. }
  46. else
  47. THREE.LineSegmentsGeometry.prototype.setColors.call(this, array);
  48. return this;
  49. },
  50. fromLine: function ( line ) {
  51. var geometry = line.geometry;
  52. if ( geometry.isGeometry ) {
  53. this.setPositions( geometry.vertices );
  54. } else if ( geometry.isBufferGeometry ) {
  55. this.setPositions( geometry.position.array ); // assumes non-indexed
  56. }
  57. // set colors, maybe
  58. return this;
  59. },
  60. copy: function ( /* source */ ) {
  61. // todo
  62. return this;
  63. }
  64. } );