NURBSSurface.js 1.3 KB

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