Favivon - Correção

This commit is contained in:
2026-05-30 19:59:39 -03:00
parent 76ddaa815d
commit d7dfd221f0
32859 changed files with 5459654 additions and 404 deletions
+215
View File
@@ -0,0 +1,215 @@
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const THREE = require("three");
class GrannyKnot extends THREE.Curve {
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
t = 2 * Math.PI * t;
const x = -0.22 * Math.cos(t) - 1.28 * Math.sin(t) - 0.44 * Math.cos(3 * t) - 0.78 * Math.sin(3 * t);
const y = -0.1 * Math.cos(2 * t) - 0.27 * Math.sin(2 * t) + 0.38 * Math.cos(4 * t) + 0.46 * Math.sin(4 * t);
const z = 0.7 * Math.cos(3 * t) - 0.4 * Math.sin(3 * t);
return point.set(x, y, z).multiplyScalar(20);
}
}
class HeartCurve extends THREE.Curve {
constructor(scale = 5) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
t *= 2 * Math.PI;
const x = 16 * Math.pow(Math.sin(t), 3);
const y = 13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t);
const z = 0;
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class VivianiCurve extends THREE.Curve {
constructor(scale = 70) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
t = t * 4 * Math.PI;
const a = this.scale / 2;
const x = a * (1 + Math.cos(t));
const y = a * Math.sin(t);
const z = 2 * a * Math.sin(t / 2);
return point.set(x, y, z);
}
}
class KnotCurve extends THREE.Curve {
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
t *= 2 * Math.PI;
const R = 10;
const s = 50;
const x = s * Math.sin(t);
const y = Math.cos(t) * (R + s * Math.cos(t));
const z = Math.sin(t) * (R + s * Math.cos(t));
return point.set(x, y, z);
}
}
class HelixCurve extends THREE.Curve {
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
const a = 30;
const b = 150;
const t2 = 2 * Math.PI * t * b / 30;
const x = Math.cos(t2) * a;
const y = Math.sin(t2) * a;
const z = b * t;
return point.set(x, y, z);
}
}
class TrefoilKnot extends THREE.Curve {
constructor(scale = 10) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
t *= Math.PI * 2;
const x = (2 + Math.cos(3 * t)) * Math.cos(2 * t);
const y = (2 + Math.cos(3 * t)) * Math.sin(2 * t);
const z = Math.sin(3 * t);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class TorusKnot extends THREE.Curve {
constructor(scale = 10) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
const p = 3;
const q = 4;
t *= Math.PI * 2;
const x = (2 + Math.cos(q * t)) * Math.cos(p * t);
const y = (2 + Math.cos(q * t)) * Math.sin(p * t);
const z = Math.sin(q * t);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class CinquefoilKnot extends THREE.Curve {
constructor(scale = 10) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
const p = 2;
const q = 5;
t *= Math.PI * 2;
const x = (2 + Math.cos(q * t)) * Math.cos(p * t);
const y = (2 + Math.cos(q * t)) * Math.sin(p * t);
const z = Math.sin(q * t);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class TrefoilPolynomialKnot extends THREE.Curve {
constructor(scale = 10) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
t = t * 4 - 2;
const x = Math.pow(t, 3) - 3 * t;
const y = Math.pow(t, 4) - 4 * t * t;
const z = 1 / 5 * Math.pow(t, 5) - 2 * t;
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
function scaleTo(x, y, t) {
const r = y - x;
return t * r + x;
}
class FigureEightPolynomialKnot extends THREE.Curve {
constructor(scale = 1) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
t = scaleTo(-4, 4, t);
const x = 2 / 5 * t * (t * t - 7) * (t * t - 10);
const y = Math.pow(t, 4) - 13 * t * t;
const z = 1 / 10 * t * (t * t - 4) * (t * t - 9) * (t * t - 12);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class DecoratedTorusKnot4a extends THREE.Curve {
constructor(scale = 40) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
t *= Math.PI * 2;
const x = Math.cos(2 * t) * (1 + 0.6 * (Math.cos(5 * t) + 0.75 * Math.cos(10 * t)));
const y = Math.sin(2 * t) * (1 + 0.6 * (Math.cos(5 * t) + 0.75 * Math.cos(10 * t)));
const z = 0.35 * Math.sin(5 * t);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class DecoratedTorusKnot4b extends THREE.Curve {
constructor(scale = 40) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
const fi = t * Math.PI * 2;
const x = Math.cos(2 * fi) * (1 + 0.45 * Math.cos(3 * fi) + 0.4 * Math.cos(9 * fi));
const y = Math.sin(2 * fi) * (1 + 0.45 * Math.cos(3 * fi) + 0.4 * Math.cos(9 * fi));
const z = 0.2 * Math.sin(9 * fi);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class DecoratedTorusKnot5a extends THREE.Curve {
constructor(scale = 40) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
const fi = t * Math.PI * 2;
const x = Math.cos(3 * fi) * (1 + 0.3 * Math.cos(5 * fi) + 0.5 * Math.cos(10 * fi));
const y = Math.sin(3 * fi) * (1 + 0.3 * Math.cos(5 * fi) + 0.5 * Math.cos(10 * fi));
const z = 0.2 * Math.sin(20 * fi);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class DecoratedTorusKnot5c extends THREE.Curve {
constructor(scale = 40) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new THREE.Vector3()) {
const point = optionalTarget;
const fi = t * Math.PI * 2;
const x = Math.cos(4 * fi) * (1 + 0.5 * (Math.cos(5 * fi) + 0.4 * Math.cos(20 * fi)));
const y = Math.sin(4 * fi) * (1 + 0.5 * (Math.cos(5 * fi) + 0.4 * Math.cos(20 * fi)));
const z = 0.35 * Math.sin(15 * fi);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
exports.CinquefoilKnot = CinquefoilKnot;
exports.DecoratedTorusKnot4a = DecoratedTorusKnot4a;
exports.DecoratedTorusKnot4b = DecoratedTorusKnot4b;
exports.DecoratedTorusKnot5a = DecoratedTorusKnot5a;
exports.DecoratedTorusKnot5c = DecoratedTorusKnot5c;
exports.FigureEightPolynomialKnot = FigureEightPolynomialKnot;
exports.GrannyKnot = GrannyKnot;
exports.HeartCurve = HeartCurve;
exports.HelixCurve = HelixCurve;
exports.KnotCurve = KnotCurve;
exports.TorusKnot = TorusKnot;
exports.TrefoilKnot = TrefoilKnot;
exports.TrefoilPolynomialKnot = TrefoilPolynomialKnot;
exports.VivianiCurve = VivianiCurve;
//# sourceMappingURL=CurveExtras.cjs.map
File diff suppressed because one or more lines are too long
+68
View File
@@ -0,0 +1,68 @@
import { Curve, Vector3 } from 'three'
export class GrannyKnot extends Curve<Vector3> {
constructor()
}
export class HeartCurve extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
export class VivianiCurve extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
export class KnotCurve extends Curve<Vector3> {
constructor()
}
export class HelixCurve extends Curve<Vector3> {
constructor()
}
export class TrefoilKnot extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
export class TorusKnot extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
export class CinquefoilKnot extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
export class TrefoilPolynomialKnot extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
export class FigureEightPolynomialKnot extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
export class DecoratedTorusKnot4a extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
export class DecoratedTorusKnot4b extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
export class DecoratedTorusKnot5a extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
export class DecoratedTorusKnot5c extends Curve<Vector3> {
constructor(scale?: number)
scale: number
}
+215
View File
@@ -0,0 +1,215 @@
import { Curve, Vector3 } from "three";
class GrannyKnot extends Curve {
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
t = 2 * Math.PI * t;
const x = -0.22 * Math.cos(t) - 1.28 * Math.sin(t) - 0.44 * Math.cos(3 * t) - 0.78 * Math.sin(3 * t);
const y = -0.1 * Math.cos(2 * t) - 0.27 * Math.sin(2 * t) + 0.38 * Math.cos(4 * t) + 0.46 * Math.sin(4 * t);
const z = 0.7 * Math.cos(3 * t) - 0.4 * Math.sin(3 * t);
return point.set(x, y, z).multiplyScalar(20);
}
}
class HeartCurve extends Curve {
constructor(scale = 5) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
t *= 2 * Math.PI;
const x = 16 * Math.pow(Math.sin(t), 3);
const y = 13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t);
const z = 0;
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class VivianiCurve extends Curve {
constructor(scale = 70) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
t = t * 4 * Math.PI;
const a = this.scale / 2;
const x = a * (1 + Math.cos(t));
const y = a * Math.sin(t);
const z = 2 * a * Math.sin(t / 2);
return point.set(x, y, z);
}
}
class KnotCurve extends Curve {
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
t *= 2 * Math.PI;
const R = 10;
const s = 50;
const x = s * Math.sin(t);
const y = Math.cos(t) * (R + s * Math.cos(t));
const z = Math.sin(t) * (R + s * Math.cos(t));
return point.set(x, y, z);
}
}
class HelixCurve extends Curve {
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
const a = 30;
const b = 150;
const t2 = 2 * Math.PI * t * b / 30;
const x = Math.cos(t2) * a;
const y = Math.sin(t2) * a;
const z = b * t;
return point.set(x, y, z);
}
}
class TrefoilKnot extends Curve {
constructor(scale = 10) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
t *= Math.PI * 2;
const x = (2 + Math.cos(3 * t)) * Math.cos(2 * t);
const y = (2 + Math.cos(3 * t)) * Math.sin(2 * t);
const z = Math.sin(3 * t);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class TorusKnot extends Curve {
constructor(scale = 10) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
const p = 3;
const q = 4;
t *= Math.PI * 2;
const x = (2 + Math.cos(q * t)) * Math.cos(p * t);
const y = (2 + Math.cos(q * t)) * Math.sin(p * t);
const z = Math.sin(q * t);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class CinquefoilKnot extends Curve {
constructor(scale = 10) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
const p = 2;
const q = 5;
t *= Math.PI * 2;
const x = (2 + Math.cos(q * t)) * Math.cos(p * t);
const y = (2 + Math.cos(q * t)) * Math.sin(p * t);
const z = Math.sin(q * t);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class TrefoilPolynomialKnot extends Curve {
constructor(scale = 10) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
t = t * 4 - 2;
const x = Math.pow(t, 3) - 3 * t;
const y = Math.pow(t, 4) - 4 * t * t;
const z = 1 / 5 * Math.pow(t, 5) - 2 * t;
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
function scaleTo(x, y, t) {
const r = y - x;
return t * r + x;
}
class FigureEightPolynomialKnot extends Curve {
constructor(scale = 1) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
t = scaleTo(-4, 4, t);
const x = 2 / 5 * t * (t * t - 7) * (t * t - 10);
const y = Math.pow(t, 4) - 13 * t * t;
const z = 1 / 10 * t * (t * t - 4) * (t * t - 9) * (t * t - 12);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class DecoratedTorusKnot4a extends Curve {
constructor(scale = 40) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
t *= Math.PI * 2;
const x = Math.cos(2 * t) * (1 + 0.6 * (Math.cos(5 * t) + 0.75 * Math.cos(10 * t)));
const y = Math.sin(2 * t) * (1 + 0.6 * (Math.cos(5 * t) + 0.75 * Math.cos(10 * t)));
const z = 0.35 * Math.sin(5 * t);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class DecoratedTorusKnot4b extends Curve {
constructor(scale = 40) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
const fi = t * Math.PI * 2;
const x = Math.cos(2 * fi) * (1 + 0.45 * Math.cos(3 * fi) + 0.4 * Math.cos(9 * fi));
const y = Math.sin(2 * fi) * (1 + 0.45 * Math.cos(3 * fi) + 0.4 * Math.cos(9 * fi));
const z = 0.2 * Math.sin(9 * fi);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class DecoratedTorusKnot5a extends Curve {
constructor(scale = 40) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
const fi = t * Math.PI * 2;
const x = Math.cos(3 * fi) * (1 + 0.3 * Math.cos(5 * fi) + 0.5 * Math.cos(10 * fi));
const y = Math.sin(3 * fi) * (1 + 0.3 * Math.cos(5 * fi) + 0.5 * Math.cos(10 * fi));
const z = 0.2 * Math.sin(20 * fi);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
class DecoratedTorusKnot5c extends Curve {
constructor(scale = 40) {
super();
this.scale = scale;
}
getPoint(t, optionalTarget = new Vector3()) {
const point = optionalTarget;
const fi = t * Math.PI * 2;
const x = Math.cos(4 * fi) * (1 + 0.5 * (Math.cos(5 * fi) + 0.4 * Math.cos(20 * fi)));
const y = Math.sin(4 * fi) * (1 + 0.5 * (Math.cos(5 * fi) + 0.4 * Math.cos(20 * fi)));
const z = 0.35 * Math.sin(15 * fi);
return point.set(x, y, z).multiplyScalar(this.scale);
}
}
export {
CinquefoilKnot,
DecoratedTorusKnot4a,
DecoratedTorusKnot4b,
DecoratedTorusKnot5a,
DecoratedTorusKnot5c,
FigureEightPolynomialKnot,
GrannyKnot,
HeartCurve,
HelixCurve,
KnotCurve,
TorusKnot,
TrefoilKnot,
TrefoilPolynomialKnot,
VivianiCurve
};
//# sourceMappingURL=CurveExtras.js.map
File diff suppressed because one or more lines are too long
+36
View File
@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const THREE = require("three");
const NURBSUtils = require("./NURBSUtils.cjs");
class NURBSCurve extends THREE.Curve {
constructor(degree, knots, controlPoints, startKnot, endKnot) {
super();
this.degree = degree;
this.knots = knots;
this.controlPoints = [];
this.startKnot = startKnot || 0;
this.endKnot = endKnot || this.knots.length - 1;
for (let i = 0; i < controlPoints.length; ++i) {
const point = controlPoints[i];
this.controlPoints[i] = new THREE.Vector4(point.x, point.y, point.z, point.w);
}
}
getPoint(t, optionalTarget) {
const point = optionalTarget || new THREE.Vector3();
const u = this.knots[this.startKnot] + t * (this.knots[this.endKnot] - this.knots[this.startKnot]);
const hpoint = NURBSUtils.calcBSplinePoint(this.degree, this.knots, this.controlPoints, u);
if (hpoint.w != 1) {
hpoint.divideScalar(hpoint.w);
}
return point.set(hpoint.x, hpoint.y, hpoint.z);
}
getTangent(t, optionalTarget) {
const tangent = optionalTarget || new THREE.Vector3();
const u = this.knots[0] + t * (this.knots[this.knots.length - 1] - this.knots[0]);
const ders = NURBSUtils.calcNURBSDerivatives(this.degree, this.knots, this.controlPoints, u, 1);
tangent.copy(ders[1]).normalize();
return tangent;
}
}
exports.NURBSCurve = NURBSCurve;
//# sourceMappingURL=NURBSCurve.cjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"NURBSCurve.cjs","sources":["../../src/curves/NURBSCurve.js"],"sourcesContent":["import { Curve, Vector3, Vector4 } from 'three'\nimport * as NURBSUtils from '../curves/NURBSUtils'\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(\n degree,\n knots /* array of reals */,\n controlPoints /* array of Vector(2|3|4) */,\n startKnot /* index in knots */,\n endKnot /* index in knots */,\n ) {\n super()\n\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\n getPoint(t, optionalTarget) {\n const point = optionalTarget || new Vector3()\n\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\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\n return point.set(hpoint.x, hpoint.y, hpoint.z)\n }\n\n getTangent(t, optionalTarget) {\n const tangent = optionalTarget || new Vector3()\n\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\n return tangent\n }\n}\n\nexport { NURBSCurve }\n"],"names":["Curve","Vector4","Vector3","NURBSUtils.calcBSplinePoint","NURBSUtils.calcNURBSDerivatives"],"mappings":";;;;AAYA,MAAM,mBAAmBA,MAAAA,MAAM;AAAA,EAC7B,YACE,QACA,OACA,eACA,WACA,SACA;AACA,UAAO;AAEP,SAAK,SAAS;AACd,SAAK,QAAQ;AACb,SAAK,gBAAgB,CAAE;AAEvB,SAAK,YAAY,aAAa;AAC9B,SAAK,UAAU,WAAW,KAAK,MAAM,SAAS;AAC9C,aAAS,IAAI,GAAG,IAAI,cAAc,QAAQ,EAAE,GAAG;AAE7C,YAAM,QAAQ,cAAc,CAAC;AAC7B,WAAK,cAAc,CAAC,IAAI,IAAIC,MAAO,QAAC,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAAA,IACvE;AAAA,EACF;AAAA,EAED,SAAS,GAAG,gBAAgB;AAC1B,UAAM,QAAQ,kBAAkB,IAAIC,cAAS;AAE7C,UAAM,IAAI,KAAK,MAAM,KAAK,SAAS,IAAI,KAAK,KAAK,MAAM,KAAK,OAAO,IAAI,KAAK,MAAM,KAAK,SAAS;AAGhG,UAAM,SAASC,4BAA4B,KAAK,QAAQ,KAAK,OAAO,KAAK,eAAe,CAAC;AAEzF,QAAI,OAAO,KAAK,GAAK;AAEnB,aAAO,aAAa,OAAO,CAAC;AAAA,IAC7B;AAED,WAAO,MAAM,IAAI,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAAA,EAC9C;AAAA,EAED,WAAW,GAAG,gBAAgB;AAC5B,UAAM,UAAU,kBAAkB,IAAID,cAAS;AAE/C,UAAM,IAAI,KAAK,MAAM,CAAC,IAAI,KAAK,KAAK,MAAM,KAAK,MAAM,SAAS,CAAC,IAAI,KAAK,MAAM,CAAC;AAC/E,UAAM,OAAOE,WAAAA,qBAAgC,KAAK,QAAQ,KAAK,OAAO,KAAK,eAAe,GAAG,CAAC;AAC9F,YAAQ,KAAK,KAAK,CAAC,CAAC,EAAE,UAAW;AAEjC,WAAO;AAAA,EACR;AACH;;"}
+11
View File
@@ -0,0 +1,11 @@
import { Curve, Vector2, Vector3, Vector4 } from 'three'
export class NURBSCurve extends Curve<Vector3> {
constructor(
degree: number,
knots: number[],
controlPoints: Vector2[] | Vector3[] | Vector4[],
startKnot: number,
endKnot: number,
)
}
+36
View File
@@ -0,0 +1,36 @@
import { Curve, Vector4, Vector3 } from "three";
import { calcBSplinePoint, calcNURBSDerivatives } from "./NURBSUtils.js";
class NURBSCurve extends Curve {
constructor(degree, knots, controlPoints, startKnot, endKnot) {
super();
this.degree = degree;
this.knots = knots;
this.controlPoints = [];
this.startKnot = startKnot || 0;
this.endKnot = endKnot || this.knots.length - 1;
for (let i = 0; i < controlPoints.length; ++i) {
const point = controlPoints[i];
this.controlPoints[i] = new Vector4(point.x, point.y, point.z, point.w);
}
}
getPoint(t, optionalTarget) {
const point = optionalTarget || new Vector3();
const u = this.knots[this.startKnot] + t * (this.knots[this.endKnot] - this.knots[this.startKnot]);
const hpoint = calcBSplinePoint(this.degree, this.knots, this.controlPoints, u);
if (hpoint.w != 1) {
hpoint.divideScalar(hpoint.w);
}
return point.set(hpoint.x, hpoint.y, hpoint.z);
}
getTangent(t, optionalTarget) {
const tangent = optionalTarget || new Vector3();
const u = this.knots[0] + t * (this.knots[this.knots.length - 1] - this.knots[0]);
const ders = calcNURBSDerivatives(this.degree, this.knots, this.controlPoints, u, 1);
tangent.copy(ders[1]).normalize();
return tangent;
}
}
export {
NURBSCurve
};
//# sourceMappingURL=NURBSCurve.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"NURBSCurve.js","sources":["../../src/curves/NURBSCurve.js"],"sourcesContent":["import { Curve, Vector3, Vector4 } from 'three'\nimport * as NURBSUtils from '../curves/NURBSUtils'\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(\n degree,\n knots /* array of reals */,\n controlPoints /* array of Vector(2|3|4) */,\n startKnot /* index in knots */,\n endKnot /* index in knots */,\n ) {\n super()\n\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\n getPoint(t, optionalTarget) {\n const point = optionalTarget || new Vector3()\n\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\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\n return point.set(hpoint.x, hpoint.y, hpoint.z)\n }\n\n getTangent(t, optionalTarget) {\n const tangent = optionalTarget || new Vector3()\n\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\n return tangent\n }\n}\n\nexport { NURBSCurve }\n"],"names":["NURBSUtils.calcBSplinePoint","NURBSUtils.calcNURBSDerivatives"],"mappings":";;AAYA,MAAM,mBAAmB,MAAM;AAAA,EAC7B,YACE,QACA,OACA,eACA,WACA,SACA;AACA,UAAO;AAEP,SAAK,SAAS;AACd,SAAK,QAAQ;AACb,SAAK,gBAAgB,CAAE;AAEvB,SAAK,YAAY,aAAa;AAC9B,SAAK,UAAU,WAAW,KAAK,MAAM,SAAS;AAC9C,aAAS,IAAI,GAAG,IAAI,cAAc,QAAQ,EAAE,GAAG;AAE7C,YAAM,QAAQ,cAAc,CAAC;AAC7B,WAAK,cAAc,CAAC,IAAI,IAAI,QAAQ,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAAA,IACvE;AAAA,EACF;AAAA,EAED,SAAS,GAAG,gBAAgB;AAC1B,UAAM,QAAQ,kBAAkB,IAAI,QAAS;AAE7C,UAAM,IAAI,KAAK,MAAM,KAAK,SAAS,IAAI,KAAK,KAAK,MAAM,KAAK,OAAO,IAAI,KAAK,MAAM,KAAK,SAAS;AAGhG,UAAM,SAASA,iBAA4B,KAAK,QAAQ,KAAK,OAAO,KAAK,eAAe,CAAC;AAEzF,QAAI,OAAO,KAAK,GAAK;AAEnB,aAAO,aAAa,OAAO,CAAC;AAAA,IAC7B;AAED,WAAO,MAAM,IAAI,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAAA,EAC9C;AAAA,EAED,WAAW,GAAG,gBAAgB;AAC5B,UAAM,UAAU,kBAAkB,IAAI,QAAS;AAE/C,UAAM,IAAI,KAAK,MAAM,CAAC,IAAI,KAAK,KAAK,MAAM,KAAK,MAAM,SAAS,CAAC,IAAI,KAAK,MAAM,CAAC;AAC/E,UAAM,OAAOC,qBAAgC,KAAK,QAAQ,KAAK,OAAO,KAAK,eAAe,GAAG,CAAC;AAC9F,YAAQ,KAAK,KAAK,CAAC,CAAC,EAAE,UAAW;AAEjC,WAAO;AAAA,EACR;AACH;"}
+29
View File
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const THREE = require("three");
const NURBSUtils = require("./NURBSUtils.cjs");
class NURBSSurface {
constructor(degree1, degree2, knots1, knots2, controlPoints) {
this.degree1 = degree1;
this.degree2 = degree2;
this.knots1 = knots1;
this.knots2 = knots2;
this.controlPoints = [];
const len1 = knots1.length - degree1 - 1;
const len2 = knots2.length - degree2 - 1;
for (let i = 0; i < len1; ++i) {
this.controlPoints[i] = [];
for (let j = 0; j < len2; ++j) {
const point = controlPoints[i][j];
this.controlPoints[i][j] = new THREE.Vector4(point.x, point.y, point.z, point.w);
}
}
}
getPoint(t1, t2, target) {
const u = this.knots1[0] + t1 * (this.knots1[this.knots1.length - 1] - this.knots1[0]);
const v = this.knots2[0] + t2 * (this.knots2[this.knots2.length - 1] - this.knots2[0]);
NURBSUtils.calcSurfacePoint(this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v, target);
}
}
exports.NURBSSurface = NURBSSurface;
//# sourceMappingURL=NURBSSurface.cjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"NURBSSurface.cjs","sources":["../../src/curves/NURBSSurface.js"],"sourcesContent":["import { Vector4 } from 'three'\nimport * as NURBSUtils from '../curves/NURBSUtils'\n\n/**\n * NURBS surface object\n *\n * Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight.\n **/\n\nclass NURBSSurface {\n constructor(degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */) {\n this.degree1 = degree1\n this.degree2 = degree2\n this.knots1 = knots1\n this.knots2 = knots2\n this.controlPoints = []\n\n const len1 = knots1.length - degree1 - 1\n const len2 = knots2.length - degree2 - 1\n\n // ensure Vector4 for control points\n for (let i = 0; i < len1; ++i) {\n this.controlPoints[i] = []\n for (let j = 0; j < len2; ++j) {\n const point = controlPoints[i][j]\n this.controlPoints[i][j] = new Vector4(point.x, point.y, point.z, point.w)\n }\n }\n }\n\n getPoint(t1, t2, target) {\n const u = this.knots1[0] + t1 * (this.knots1[this.knots1.length - 1] - this.knots1[0]) // linear mapping t1->u\n const v = this.knots2[0] + t2 * (this.knots2[this.knots2.length - 1] - this.knots2[0]) // linear mapping t2->u\n\n NURBSUtils.calcSurfacePoint(this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v, target)\n }\n}\n\nexport { NURBSSurface }\n"],"names":["Vector4","NURBSUtils.calcSurfacePoint"],"mappings":";;;;AASA,MAAM,aAAa;AAAA,EACjB,YAAY,SAAS,SAAS,QAAQ,QAA8B,eAA8C;AAChH,SAAK,UAAU;AACf,SAAK,UAAU;AACf,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,gBAAgB,CAAE;AAEvB,UAAM,OAAO,OAAO,SAAS,UAAU;AACvC,UAAM,OAAO,OAAO,SAAS,UAAU;AAGvC,aAAS,IAAI,GAAG,IAAI,MAAM,EAAE,GAAG;AAC7B,WAAK,cAAc,CAAC,IAAI,CAAE;AAC1B,eAAS,IAAI,GAAG,IAAI,MAAM,EAAE,GAAG;AAC7B,cAAM,QAAQ,cAAc,CAAC,EAAE,CAAC;AAChC,aAAK,cAAc,CAAC,EAAE,CAAC,IAAI,IAAIA,MAAAA,QAAQ,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAAA,MAC1E;AAAA,IACF;AAAA,EACF;AAAA,EAED,SAAS,IAAI,IAAI,QAAQ;AACvB,UAAM,IAAI,KAAK,OAAO,CAAC,IAAI,MAAM,KAAK,OAAO,KAAK,OAAO,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC;AACpF,UAAM,IAAI,KAAK,OAAO,CAAC,IAAI,MAAM,KAAK,OAAO,KAAK,OAAO,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC;AAEpFC,eAAAA,iBAA4B,KAAK,SAAS,KAAK,SAAS,KAAK,QAAQ,KAAK,QAAQ,KAAK,eAAe,GAAG,GAAG,MAAM;AAAA,EACnH;AACH;;"}
+13
View File
@@ -0,0 +1,13 @@
import { Vector2, Vector3, Vector4 } from 'three'
export class NURBSSurface {
constructor(
degree1: number,
degree2: number,
knots1: number[],
knots2: number[],
controlPoints: Vector2[][] | Vector3[][] | Vector4[][],
)
getPoint(t1: number, t2: number, target: Vector3): void
}
+29
View File
@@ -0,0 +1,29 @@
import { Vector4 } from "three";
import { calcSurfacePoint } from "./NURBSUtils.js";
class NURBSSurface {
constructor(degree1, degree2, knots1, knots2, controlPoints) {
this.degree1 = degree1;
this.degree2 = degree2;
this.knots1 = knots1;
this.knots2 = knots2;
this.controlPoints = [];
const len1 = knots1.length - degree1 - 1;
const len2 = knots2.length - degree2 - 1;
for (let i = 0; i < len1; ++i) {
this.controlPoints[i] = [];
for (let j = 0; j < len2; ++j) {
const point = controlPoints[i][j];
this.controlPoints[i][j] = new Vector4(point.x, point.y, point.z, point.w);
}
}
}
getPoint(t1, t2, target) {
const u = this.knots1[0] + t1 * (this.knots1[this.knots1.length - 1] - this.knots1[0]);
const v = this.knots2[0] + t2 * (this.knots2[this.knots2.length - 1] - this.knots2[0]);
calcSurfacePoint(this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v, target);
}
}
export {
NURBSSurface
};
//# sourceMappingURL=NURBSSurface.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"NURBSSurface.js","sources":["../../src/curves/NURBSSurface.js"],"sourcesContent":["import { Vector4 } from 'three'\nimport * as NURBSUtils from '../curves/NURBSUtils'\n\n/**\n * NURBS surface object\n *\n * Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight.\n **/\n\nclass NURBSSurface {\n constructor(degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */) {\n this.degree1 = degree1\n this.degree2 = degree2\n this.knots1 = knots1\n this.knots2 = knots2\n this.controlPoints = []\n\n const len1 = knots1.length - degree1 - 1\n const len2 = knots2.length - degree2 - 1\n\n // ensure Vector4 for control points\n for (let i = 0; i < len1; ++i) {\n this.controlPoints[i] = []\n for (let j = 0; j < len2; ++j) {\n const point = controlPoints[i][j]\n this.controlPoints[i][j] = new Vector4(point.x, point.y, point.z, point.w)\n }\n }\n }\n\n getPoint(t1, t2, target) {\n const u = this.knots1[0] + t1 * (this.knots1[this.knots1.length - 1] - this.knots1[0]) // linear mapping t1->u\n const v = this.knots2[0] + t2 * (this.knots2[this.knots2.length - 1] - this.knots2[0]) // linear mapping t2->u\n\n NURBSUtils.calcSurfacePoint(this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v, target)\n }\n}\n\nexport { NURBSSurface }\n"],"names":["NURBSUtils.calcSurfacePoint"],"mappings":";;AASA,MAAM,aAAa;AAAA,EACjB,YAAY,SAAS,SAAS,QAAQ,QAA8B,eAA8C;AAChH,SAAK,UAAU;AACf,SAAK,UAAU;AACf,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,gBAAgB,CAAE;AAEvB,UAAM,OAAO,OAAO,SAAS,UAAU;AACvC,UAAM,OAAO,OAAO,SAAS,UAAU;AAGvC,aAAS,IAAI,GAAG,IAAI,MAAM,EAAE,GAAG;AAC7B,WAAK,cAAc,CAAC,IAAI,CAAE;AAC1B,eAAS,IAAI,GAAG,IAAI,MAAM,EAAE,GAAG;AAC7B,cAAM,QAAQ,cAAc,CAAC,EAAE,CAAC;AAChC,aAAK,cAAc,CAAC,EAAE,CAAC,IAAI,IAAI,QAAQ,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAAA,MAC1E;AAAA,IACF;AAAA,EACF;AAAA,EAED,SAAS,IAAI,IAAI,QAAQ;AACvB,UAAM,IAAI,KAAK,OAAO,CAAC,IAAI,MAAM,KAAK,OAAO,KAAK,OAAO,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC;AACpF,UAAM,IAAI,KAAK,OAAO,CAAC,IAAI,MAAM,KAAK,OAAO,KAAK,OAAO,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC;AAEpFA,qBAA4B,KAAK,SAAS,KAAK,SAAS,KAAK,QAAQ,KAAK,QAAQ,KAAK,eAAe,GAAG,GAAG,MAAM;AAAA,EACnH;AACH;"}
+227
View File
@@ -0,0 +1,227 @@
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const THREE = require("three");
function findSpan(p, u, U) {
const n = U.length - p - 1;
if (u >= U[n]) {
return n - 1;
}
if (u <= U[p]) {
return p;
}
let low = p;
let high = n;
let mid = Math.floor((low + high) / 2);
while (u < U[mid] || u >= U[mid + 1]) {
if (u < U[mid]) {
high = mid;
} else {
low = mid;
}
mid = Math.floor((low + high) / 2);
}
return mid;
}
function calcBasisFunctions(span, u, p, U) {
const N = [];
const left = [];
const right = [];
N[0] = 1;
for (let j = 1; j <= p; ++j) {
left[j] = u - U[span + 1 - j];
right[j] = U[span + j] - u;
let saved = 0;
for (let r = 0; r < j; ++r) {
const rv = right[r + 1];
const lv = left[j - r];
const temp = N[r] / (rv + lv);
N[r] = saved + rv * temp;
saved = lv * temp;
}
N[j] = saved;
}
return N;
}
function calcBSplinePoint(p, U, P, u) {
const span = findSpan(p, u, U);
const N = calcBasisFunctions(span, u, p, U);
const C = new THREE.Vector4(0, 0, 0, 0);
for (let j = 0; j <= p; ++j) {
const point = P[span - p + j];
const Nj = N[j];
const wNj = point.w * Nj;
C.x += point.x * wNj;
C.y += point.y * wNj;
C.z += point.z * wNj;
C.w += point.w * Nj;
}
return C;
}
function calcBasisFunctionDerivatives(span, u, p, n, U) {
const zeroArr = [];
for (let i = 0; i <= p; ++i)
zeroArr[i] = 0;
const ders = [];
for (let i = 0; i <= n; ++i)
ders[i] = zeroArr.slice(0);
const ndu = [];
for (let i = 0; i <= p; ++i)
ndu[i] = zeroArr.slice(0);
ndu[0][0] = 1;
const left = zeroArr.slice(0);
const right = zeroArr.slice(0);
for (let j = 1; j <= p; ++j) {
left[j] = u - U[span + 1 - j];
right[j] = U[span + j] - u;
let saved = 0;
for (let r2 = 0; r2 < j; ++r2) {
const rv = right[r2 + 1];
const lv = left[j - r2];
ndu[j][r2] = rv + lv;
const temp = ndu[r2][j - 1] / ndu[j][r2];
ndu[r2][j] = saved + rv * temp;
saved = lv * temp;
}
ndu[j][j] = saved;
}
for (let j = 0; j <= p; ++j) {
ders[0][j] = ndu[j][p];
}
for (let r2 = 0; r2 <= p; ++r2) {
let s1 = 0;
let s2 = 1;
const a = [];
for (let i = 0; i <= p; ++i) {
a[i] = zeroArr.slice(0);
}
a[0][0] = 1;
for (let k = 1; k <= n; ++k) {
let d = 0;
const rk = r2 - k;
const pk = p - k;
if (r2 >= k) {
a[s2][0] = a[s1][0] / ndu[pk + 1][rk];
d = a[s2][0] * ndu[rk][pk];
}
const j1 = rk >= -1 ? 1 : -rk;
const j2 = r2 - 1 <= pk ? k - 1 : p - r2;
for (let j3 = j1; j3 <= j2; ++j3) {
a[s2][j3] = (a[s1][j3] - a[s1][j3 - 1]) / ndu[pk + 1][rk + j3];
d += a[s2][j3] * ndu[rk + j3][pk];
}
if (r2 <= pk) {
a[s2][k] = -a[s1][k - 1] / ndu[pk + 1][r2];
d += a[s2][k] * ndu[r2][pk];
}
ders[k][r2] = d;
const j = s1;
s1 = s2;
s2 = j;
}
}
let r = p;
for (let k = 1; k <= n; ++k) {
for (let j = 0; j <= p; ++j) {
ders[k][j] *= r;
}
r *= p - k;
}
return ders;
}
function calcBSplineDerivatives(p, U, P, u, nd) {
const du = nd < p ? nd : p;
const CK = [];
const span = findSpan(p, u, U);
const nders = calcBasisFunctionDerivatives(span, u, p, du, U);
const Pw = [];
for (let i = 0; i < P.length; ++i) {
const point = P[i].clone();
const w = point.w;
point.x *= w;
point.y *= w;
point.z *= w;
Pw[i] = point;
}
for (let k = 0; k <= du; ++k) {
const point = Pw[span - p].clone().multiplyScalar(nders[k][0]);
for (let j = 1; j <= p; ++j) {
point.add(Pw[span - p + j].clone().multiplyScalar(nders[k][j]));
}
CK[k] = point;
}
for (let k = du + 1; k <= nd + 1; ++k) {
CK[k] = new THREE.Vector4(0, 0, 0);
}
return CK;
}
function calcKoverI(k, i) {
let nom = 1;
for (let j = 2; j <= k; ++j) {
nom *= j;
}
let denom = 1;
for (let j = 2; j <= i; ++j) {
denom *= j;
}
for (let j = 2; j <= k - i; ++j) {
denom *= j;
}
return nom / denom;
}
function calcRationalCurveDerivatives(Pders) {
const nd = Pders.length;
const Aders = [];
const wders = [];
for (let i = 0; i < nd; ++i) {
const point = Pders[i];
Aders[i] = new THREE.Vector3(point.x, point.y, point.z);
wders[i] = point.w;
}
const CK = [];
for (let k = 0; k < nd; ++k) {
const v = Aders[k].clone();
for (let i = 1; i <= k; ++i) {
v.sub(CK[k - i].clone().multiplyScalar(calcKoverI(k, i) * wders[i]));
}
CK[k] = v.divideScalar(wders[0]);
}
return CK;
}
function calcNURBSDerivatives(p, U, P, u, nd) {
const Pders = calcBSplineDerivatives(p, U, P, u, nd);
return calcRationalCurveDerivatives(Pders);
}
function calcSurfacePoint(p, q, U, V, P, u, v, target) {
const uspan = findSpan(p, u, U);
const vspan = findSpan(q, v, V);
const Nu = calcBasisFunctions(uspan, u, p, U);
const Nv = calcBasisFunctions(vspan, v, q, V);
const temp = [];
for (let l = 0; l <= q; ++l) {
temp[l] = new THREE.Vector4(0, 0, 0, 0);
for (let k = 0; k <= p; ++k) {
const point = P[uspan - p + k][vspan - q + l].clone();
const w = point.w;
point.x *= w;
point.y *= w;
point.z *= w;
temp[l].add(point.multiplyScalar(Nu[k]));
}
}
const Sw = new THREE.Vector4(0, 0, 0, 0);
for (let l = 0; l <= q; ++l) {
Sw.add(temp[l].multiplyScalar(Nv[l]));
}
Sw.divideScalar(Sw.w);
target.set(Sw.x, Sw.y, Sw.z);
}
exports.calcBSplineDerivatives = calcBSplineDerivatives;
exports.calcBSplinePoint = calcBSplinePoint;
exports.calcBasisFunctionDerivatives = calcBasisFunctionDerivatives;
exports.calcBasisFunctions = calcBasisFunctions;
exports.calcKoverI = calcKoverI;
exports.calcNURBSDerivatives = calcNURBSDerivatives;
exports.calcRationalCurveDerivatives = calcRationalCurveDerivatives;
exports.calcSurfacePoint = calcSurfacePoint;
exports.findSpan = findSpan;
//# sourceMappingURL=NURBSUtils.cjs.map
File diff suppressed because one or more lines are too long
+20
View File
@@ -0,0 +1,20 @@
import { Vector3, Vector4 } from 'three'
export function findSpan(p: number, u: number, U: number[]): number
export function calcBasisFunctions(span: number, u: number, p: number, U: number[]): number[]
export function calcBSplinePoint(p: number, U: number[], P: Vector4[], u: number): Vector4
export function calcBasisFunctionDerivatives(span: number, u: number, p: number, n: number, U: number[]): number[][]
export function calcBSplineDerivatives(p: number, U: number[], P: Vector4[], u: number, nd: number): Vector4[]
export function calcKoverI(k: number, i: number): number
export function calcRationalCurveDerivatives(Pders: Vector4[]): Vector3[]
export function calcNURBSDerivatives(p: number, U: number[], P: Vector4[], u: number, nd: number): Vector3[]
export function calcSurfacePoint(
p: number,
q: number,
U: number[],
V: number[],
P: Vector4[],
u: number,
v: number,
target: Vector3,
): Vector3
+227
View File
@@ -0,0 +1,227 @@
import { Vector4, Vector3 } from "three";
function findSpan(p, u, U) {
const n = U.length - p - 1;
if (u >= U[n]) {
return n - 1;
}
if (u <= U[p]) {
return p;
}
let low = p;
let high = n;
let mid = Math.floor((low + high) / 2);
while (u < U[mid] || u >= U[mid + 1]) {
if (u < U[mid]) {
high = mid;
} else {
low = mid;
}
mid = Math.floor((low + high) / 2);
}
return mid;
}
function calcBasisFunctions(span, u, p, U) {
const N = [];
const left = [];
const right = [];
N[0] = 1;
for (let j = 1; j <= p; ++j) {
left[j] = u - U[span + 1 - j];
right[j] = U[span + j] - u;
let saved = 0;
for (let r = 0; r < j; ++r) {
const rv = right[r + 1];
const lv = left[j - r];
const temp = N[r] / (rv + lv);
N[r] = saved + rv * temp;
saved = lv * temp;
}
N[j] = saved;
}
return N;
}
function calcBSplinePoint(p, U, P, u) {
const span = findSpan(p, u, U);
const N = calcBasisFunctions(span, u, p, U);
const C = new Vector4(0, 0, 0, 0);
for (let j = 0; j <= p; ++j) {
const point = P[span - p + j];
const Nj = N[j];
const wNj = point.w * Nj;
C.x += point.x * wNj;
C.y += point.y * wNj;
C.z += point.z * wNj;
C.w += point.w * Nj;
}
return C;
}
function calcBasisFunctionDerivatives(span, u, p, n, U) {
const zeroArr = [];
for (let i = 0; i <= p; ++i)
zeroArr[i] = 0;
const ders = [];
for (let i = 0; i <= n; ++i)
ders[i] = zeroArr.slice(0);
const ndu = [];
for (let i = 0; i <= p; ++i)
ndu[i] = zeroArr.slice(0);
ndu[0][0] = 1;
const left = zeroArr.slice(0);
const right = zeroArr.slice(0);
for (let j = 1; j <= p; ++j) {
left[j] = u - U[span + 1 - j];
right[j] = U[span + j] - u;
let saved = 0;
for (let r2 = 0; r2 < j; ++r2) {
const rv = right[r2 + 1];
const lv = left[j - r2];
ndu[j][r2] = rv + lv;
const temp = ndu[r2][j - 1] / ndu[j][r2];
ndu[r2][j] = saved + rv * temp;
saved = lv * temp;
}
ndu[j][j] = saved;
}
for (let j = 0; j <= p; ++j) {
ders[0][j] = ndu[j][p];
}
for (let r2 = 0; r2 <= p; ++r2) {
let s1 = 0;
let s2 = 1;
const a = [];
for (let i = 0; i <= p; ++i) {
a[i] = zeroArr.slice(0);
}
a[0][0] = 1;
for (let k = 1; k <= n; ++k) {
let d = 0;
const rk = r2 - k;
const pk = p - k;
if (r2 >= k) {
a[s2][0] = a[s1][0] / ndu[pk + 1][rk];
d = a[s2][0] * ndu[rk][pk];
}
const j1 = rk >= -1 ? 1 : -rk;
const j2 = r2 - 1 <= pk ? k - 1 : p - r2;
for (let j3 = j1; j3 <= j2; ++j3) {
a[s2][j3] = (a[s1][j3] - a[s1][j3 - 1]) / ndu[pk + 1][rk + j3];
d += a[s2][j3] * ndu[rk + j3][pk];
}
if (r2 <= pk) {
a[s2][k] = -a[s1][k - 1] / ndu[pk + 1][r2];
d += a[s2][k] * ndu[r2][pk];
}
ders[k][r2] = d;
const j = s1;
s1 = s2;
s2 = j;
}
}
let r = p;
for (let k = 1; k <= n; ++k) {
for (let j = 0; j <= p; ++j) {
ders[k][j] *= r;
}
r *= p - k;
}
return ders;
}
function calcBSplineDerivatives(p, U, P, u, nd) {
const du = nd < p ? nd : p;
const CK = [];
const span = findSpan(p, u, U);
const nders = calcBasisFunctionDerivatives(span, u, p, du, U);
const Pw = [];
for (let i = 0; i < P.length; ++i) {
const point = P[i].clone();
const w = point.w;
point.x *= w;
point.y *= w;
point.z *= w;
Pw[i] = point;
}
for (let k = 0; k <= du; ++k) {
const point = Pw[span - p].clone().multiplyScalar(nders[k][0]);
for (let j = 1; j <= p; ++j) {
point.add(Pw[span - p + j].clone().multiplyScalar(nders[k][j]));
}
CK[k] = point;
}
for (let k = du + 1; k <= nd + 1; ++k) {
CK[k] = new Vector4(0, 0, 0);
}
return CK;
}
function calcKoverI(k, i) {
let nom = 1;
for (let j = 2; j <= k; ++j) {
nom *= j;
}
let denom = 1;
for (let j = 2; j <= i; ++j) {
denom *= j;
}
for (let j = 2; j <= k - i; ++j) {
denom *= j;
}
return nom / denom;
}
function calcRationalCurveDerivatives(Pders) {
const nd = Pders.length;
const Aders = [];
const wders = [];
for (let i = 0; i < nd; ++i) {
const point = Pders[i];
Aders[i] = new Vector3(point.x, point.y, point.z);
wders[i] = point.w;
}
const CK = [];
for (let k = 0; k < nd; ++k) {
const v = Aders[k].clone();
for (let i = 1; i <= k; ++i) {
v.sub(CK[k - i].clone().multiplyScalar(calcKoverI(k, i) * wders[i]));
}
CK[k] = v.divideScalar(wders[0]);
}
return CK;
}
function calcNURBSDerivatives(p, U, P, u, nd) {
const Pders = calcBSplineDerivatives(p, U, P, u, nd);
return calcRationalCurveDerivatives(Pders);
}
function calcSurfacePoint(p, q, U, V, P, u, v, target) {
const uspan = findSpan(p, u, U);
const vspan = findSpan(q, v, V);
const Nu = calcBasisFunctions(uspan, u, p, U);
const Nv = calcBasisFunctions(vspan, v, q, V);
const temp = [];
for (let l = 0; l <= q; ++l) {
temp[l] = new Vector4(0, 0, 0, 0);
for (let k = 0; k <= p; ++k) {
const point = P[uspan - p + k][vspan - q + l].clone();
const w = point.w;
point.x *= w;
point.y *= w;
point.z *= w;
temp[l].add(point.multiplyScalar(Nu[k]));
}
}
const Sw = new Vector4(0, 0, 0, 0);
for (let l = 0; l <= q; ++l) {
Sw.add(temp[l].multiplyScalar(Nv[l]));
}
Sw.divideScalar(Sw.w);
target.set(Sw.x, Sw.y, Sw.z);
}
export {
calcBSplineDerivatives,
calcBSplinePoint,
calcBasisFunctionDerivatives,
calcBasisFunctions,
calcKoverI,
calcNURBSDerivatives,
calcRationalCurveDerivatives,
calcSurfacePoint,
findSpan
};
//# sourceMappingURL=NURBSUtils.js.map
File diff suppressed because one or more lines are too long