1 |
- {"ast":null,"code":"import { Curve, Vector3, Vector4 } from 'three';\nimport * as NURBSUtils from '../curves/NURBSUtils.js';\n\n/**\n * NURBS curve object\n *\n * Derives from Curve, overriding getPoint and getTangent.\n *\n * Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight.\n *\n **/\n\nclass NURBSCurve extends Curve {\n constructor(degree, knots /* array of reals */, controlPoints /* array of Vector(2|3|4) */, startKnot /* index in knots */, endKnot /* index in knots */) {\n super();\n this.degree = degree;\n this.knots = knots;\n this.controlPoints = [];\n // Used by periodic NURBS to remove hidden spans\n this.startKnot = startKnot || 0;\n this.endKnot = endKnot || this.knots.length - 1;\n for (let i = 0; i < controlPoints.length; ++i) {\n // ensure Vector4 for control points\n const point = controlPoints[i];\n this.controlPoints[i] = new Vector4(point.x, point.y, point.z, point.w);\n }\n }\n getPoint(t, optionalTarget = new Vector3()) {\n const point = optionalTarget;\n const u = this.knots[this.startKnot] + t * (this.knots[this.endKnot] - this.knots[this.startKnot]); // linear mapping t->u\n\n // following results in (wx, wy, wz, w) homogeneous point\n const hpoint = NURBSUtils.calcBSplinePoint(this.degree, this.knots, this.controlPoints, u);\n if (hpoint.w !== 1.0) {\n // project to 3D space: (wx, wy, wz, w) -> (x, y, z, 1)\n hpoint.divideScalar(hpoint.w);\n }\n return point.set(hpoint.x, hpoint.y, hpoint.z);\n }\n getTangent(t, optionalTarget = new Vector3()) {\n const tangent = optionalTarget;\n const u = this.knots[0] + t * (this.knots[this.knots.length - 1] - this.knots[0]);\n const ders = NURBSUtils.calcNURBSDerivatives(this.degree, this.knots, this.controlPoints, u, 1);\n tangent.copy(ders[1]).normalize();\n return tangent;\n }\n}\nexport { NURBSCurve };","map":{"version":3,"names":["Curve","Vector3","Vector4","NURBSUtils","NURBSCurve","constructor","degree","knots","controlPoints","startKnot","endKnot","length","i","point","x","y","z","w","getPoint","t","optionalTarget","u","hpoint","calcBSplinePoint","divideScalar","set","getTangent","tangent","ders","calcNURBSDerivatives","copy","normalize"],"sources":["/Users/mac/projects/mime/mine/public/curves/NURBSCurve.js"],"sourcesContent":["import {\n\tCurve,\n\tVector3,\n\tVector4\n} from 'three';\nimport * as NURBSUtils from '../curves/NURBSUtils.js';\n\n/**\n * NURBS curve object\n *\n * Derives from Curve, overriding getPoint and getTangent.\n *\n * Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight.\n *\n **/\n\nclass NURBSCurve extends Curve {\n\n\tconstructor(\n\t\tdegree,\n\t\tknots /* array of reals */,\n\t\tcontrolPoints /* array of Vector(2|3|4) */,\n\t\tstartKnot /* index in knots */,\n\t\tendKnot /* index in knots */\n\t) {\n\n\t\tsuper();\n\n\t\tthis.degree = degree;\n\t\tthis.knots = knots;\n\t\tthis.controlPoints = [];\n\t\t// Used by periodic NURBS to remove hidden spans\n\t\tthis.startKnot = startKnot || 0;\n\t\tthis.endKnot = endKnot || ( this.knots.length - 1 );\n\n\t\tfor ( let i = 0; i < controlPoints.length; ++ i ) {\n\n\t\t\t// ensure Vector4 for control points\n\t\t\tconst point = controlPoints[ i ];\n\t\t\tthis.controlPoints[ i ] = new Vector4( point.x, point.y, point.z, point.w );\n\n\t\t}\n\n\t}\n\n\tgetPoint( t, optionalTarget = new Vector3() ) {\n\n\t\tconst point = optionalTarget;\n\n\t\tconst u = this.knots[ this.startKnot ] + t * ( this.knots[ this.endKnot ] - this.knots[ this.startKnot ] ); // linear mapping t->u\n\n\t\t// following results in (wx, wy, wz, w) homogeneous point\n\t\tconst hpoint = NURBSUtils.calcBSplinePoint( this.degree, this.knots, this.controlPoints, u );\n\n\t\tif ( hpoint.w !== 1.0 ) {\n\n\t\t\t// project to 3D space: (wx, wy, wz, w) -> (x, y, z, 1)\n\t\t\thpoint.divideScalar( hpoint.w );\n\n\t\t}\n\n\t\treturn point.set( hpoint.x, hpoint.y, hpoint.z );\n\n\t}\n\n\tgetTangent( t, optionalTarget = new Vector3() ) {\n\n\t\tconst tangent = optionalTarget;\n\n\t\tconst u = this.knots[ 0 ] + t * ( this.knots[ this.knots.length - 1 ] - this.knots[ 0 ] );\n\t\tconst ders = NURBSUtils.calcNURBSDerivatives( this.degree, this.knots, this.controlPoints, u, 1 );\n\t\ttangent.copy( ders[ 1 ] ).normalize();\n\n\t\treturn tangent;\n\n\t}\n\n}\n\nexport { NURBSCurve };\n"],"mappings":"AAAA,SACCA,KAAK,EACLC,OAAO,EACPC,OAAO,QACD,OAAO;AACd,OAAO,KAAKC,UAAU,MAAM,yBAAyB;;AAErD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,UAAU,SAASJ,KAAK,CAAC;EAE9BK,WAAWA,CACVC,MAAM,EACNC,KAAK,CAAC,sBACNC,aAAa,CAAC,8BACdC,SAAS,CAAC,sBACVC,OAAO,CAAC,sBACP;IAED,KAAK,CAAC,CAAC;IAEP,IAAI,CAACJ,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,aAAa,GAAG,EAAE;IACvB;IACA,IAAI,CAACC,SAAS,GAAGA,SAAS,IAAI,CAAC;IAC/B,IAAI,CAACC,OAAO,GAAGA,OAAO,IAAM,IAAI,CAACH,KAAK,CAACI,MAAM,GAAG,CAAG;IAEnD,KAAM,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGJ,aAAa,CAACG,MAAM,EAAE,EAAGC,CAAC,EAAG;MAEjD;MACA,MAAMC,KAAK,GAAGL,aAAa,CAAEI,CAAC,CAAE;MAChC,IAAI,CAACJ,aAAa,CAAEI,CAAC,CAAE,GAAG,IAAIV,OAAO,CAAEW,KAAK,CAACC,CAAC,EAAED,KAAK,CAACE,CAAC,EAAEF,KAAK,CAACG,CAAC,EAAEH,KAAK,CAACI,CAAE,CAAC;IAE5E;EAED;EAEAC,QAAQA,CAAEC,CAAC,EAAEC,cAAc,GAAG,IAAInB,OAAO,CAAC,CAAC,EAAG;IAE7C,MAAMY,KAAK,GAAGO,cAAc;IAE5B,MAAMC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