2
0

NURBSSurface.js 1.2 KB

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