NURBSSurface.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. console.warn( "THREE.NURBSSurface: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author renej
  4. * NURBS surface object
  5. *
  6. * Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight.
  7. *
  8. **/
  9. /**************************************************************
  10. * NURBS surface
  11. **************************************************************/
  12. THREE.NURBSSurface = function ( degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */ ) {
  13. this.degree1 = degree1;
  14. this.degree2 = degree2;
  15. this.knots1 = knots1;
  16. this.knots2 = knots2;
  17. this.controlPoints = [];
  18. var len1 = knots1.length - degree1 - 1;
  19. var len2 = knots2.length - degree2 - 1;
  20. // ensure Vector4 for control points
  21. for ( var i = 0; i < len1; ++ i ) {
  22. this.controlPoints[ i ] = [];
  23. for ( var j = 0; j < len2; ++ j ) {
  24. var point = controlPoints[ i ][ j ];
  25. this.controlPoints[ i ][ j ] = new THREE.Vector4( point.x, point.y, point.z, point.w );
  26. }
  27. }
  28. };
  29. THREE.NURBSSurface.prototype = {
  30. constructor: THREE.NURBSSurface,
  31. getPoint: function ( t1, t2, target ) {
  32. var u = this.knots1[ 0 ] + t1 * ( this.knots1[ this.knots1.length - 1 ] - this.knots1[ 0 ] ); // linear mapping t1->u
  33. var v = this.knots2[ 0 ] + t2 * ( this.knots2[ this.knots2.length - 1 ] - this.knots2[ 0 ] ); // linear mapping t2->u
  34. THREE.NURBSUtils.calcSurfacePoint( this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v, target );
  35. }
  36. };