NURBSVolume.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {
  2. Vector4
  3. } from 'three';
  4. import * as NURBSUtils from '../curves/NURBSUtils.js';
  5. /**
  6. * NURBS volume object
  7. *
  8. * Implementation is based on (x, y, z [, w=1]]) control points with w=weight.
  9. **/
  10. class NURBSVolume {
  11. constructor( degree1, degree2, degree3, knots1, knots2, knots3 /* arrays of reals */, controlPoints /* array^3 of Vector(2|3|4) */ ) {
  12. this.degree1 = degree1;
  13. this.degree2 = degree2;
  14. this.degree3 = degree3;
  15. this.knots1 = knots1;
  16. this.knots2 = knots2;
  17. this.knots3 = knots3;
  18. this.controlPoints = [];
  19. const len1 = knots1.length - degree1 - 1;
  20. const len2 = knots2.length - degree2 - 1;
  21. const len3 = knots3.length - degree3 - 1;
  22. // ensure Vector4 for control points
  23. for ( let i = 0; i < len1; ++ i ) {
  24. this.controlPoints[ i ] = [];
  25. for ( let j = 0; j < len2; ++ j ) {
  26. this.controlPoints[ i ][ j ] = [];
  27. for ( let k = 0; k < len3; ++ k ) {
  28. const point = controlPoints[ i ][ j ][ k ];
  29. this.controlPoints[ i ][ j ][ k ] = new Vector4( point.x, point.y, point.z, point.w );
  30. }
  31. }
  32. }
  33. }
  34. getPoint( t1, t2, t3, target ) {
  35. const u = this.knots1[ 0 ] + t1 * ( this.knots1[ this.knots1.length - 1 ] - this.knots1[ 0 ] ); // linear mapping t1->u
  36. const v = this.knots2[ 0 ] + t2 * ( this.knots2[ this.knots2.length - 1 ] - this.knots2[ 0 ] ); // linear mapping t2->v
  37. const w = this.knots3[ 0 ] + t3 * ( this.knots3[ this.knots3.length - 1 ] - this.knots3[ 0 ] ); // linear mapping t3->w
  38. NURBSUtils.calcVolumePoint( this.degree1, this.degree2, this.degree3, this.knots1, this.knots2, this.knots3, this.controlPoints, u, v, w, target );
  39. }
  40. }
  41. export { NURBSVolume };