NURBSSurface.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @author renej
  3. * NURBS surface object
  4. *
  5. * Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight.
  6. *
  7. **/
  8. import {
  9. Vector4
  10. } from "../../../build/three.module.js";
  11. import { NURBSUtils } from "../curves/NURBSUtils.js";
  12. /**************************************************************
  13. * NURBS surface
  14. **************************************************************/
  15. var NURBSSurface = function ( degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */ ) {
  16. this.degree1 = degree1;
  17. this.degree2 = degree2;
  18. this.knots1 = knots1;
  19. this.knots2 = knots2;
  20. this.controlPoints = [];
  21. var len1 = knots1.length - degree1 - 1;
  22. var len2 = knots2.length - degree2 - 1;
  23. // ensure Vector4 for control points
  24. for ( var i = 0; i < len1; ++ i ) {
  25. this.controlPoints[ i ] = [];
  26. for ( var j = 0; j < len2; ++ j ) {
  27. var point = controlPoints[ i ][ j ];
  28. this.controlPoints[ i ][ j ] = new Vector4( point.x, point.y, point.z, point.w );
  29. }
  30. }
  31. };
  32. NURBSSurface.prototype = {
  33. constructor: NURBSSurface,
  34. getPoint: function ( t1, t2, target ) {
  35. var u = this.knots1[ 0 ] + t1 * ( this.knots1[ this.knots1.length - 1 ] - this.knots1[ 0 ] ); // linear mapping t1->u
  36. var v = this.knots2[ 0 ] + t2 * ( this.knots2[ this.knots2.length - 1 ] - this.knots2[ 0 ] ); // linear mapping t2->u
  37. NURBSUtils.calcSurfacePoint( this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v, target );
  38. }
  39. };
  40. export { NURBSSurface };