NURBSSurface.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ( function () {
  2. /**
  3. * NURBS surface object
  4. *
  5. * Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight.
  6. **/
  7. class NURBSSurface {
  8. constructor( degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */ ) {
  9. this.degree1 = degree1;
  10. this.degree2 = degree2;
  11. this.knots1 = knots1;
  12. this.knots2 = knots2;
  13. this.controlPoints = [];
  14. const len1 = knots1.length - degree1 - 1;
  15. const len2 = knots2.length - degree2 - 1;
  16. // ensure THREE.Vector4 for control points
  17. for ( let i = 0; i < len1; ++ i ) {
  18. this.controlPoints[ i ] = [];
  19. for ( let j = 0; j < len2; ++ j ) {
  20. const point = controlPoints[ i ][ j ];
  21. this.controlPoints[ i ][ j ] = new THREE.Vector4( point.x, point.y, point.z, point.w );
  22. }
  23. }
  24. }
  25. getPoint( t1, t2, target ) {
  26. const u = this.knots1[ 0 ] + t1 * ( this.knots1[ this.knots1.length - 1 ] - this.knots1[ 0 ] ); // linear mapping t1->u
  27. const v = this.knots2[ 0 ] + t2 * ( this.knots2[ this.knots2.length - 1 ] - this.knots2[ 0 ] ); // linear mapping t2->u
  28. THREE.NURBSUtils.calcSurfacePoint( this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v, target );
  29. }
  30. }
  31. THREE.NURBSSurface = NURBSSurface;
  32. } )();