Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volumetric NURBS #782

Merged
merged 6 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions examples-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4348,11 +4348,11 @@ index 537d8d5..bfa97ba 100644
}

diff --git a/examples-testing/examples/webgl_geometry_nurbs.ts b/examples-testing/examples/webgl_geometry_nurbs.ts
index 8336ef0..d9c564d 100644
index 6ab8b32..47ab35c 100644
--- a/examples-testing/examples/webgl_geometry_nurbs.ts
+++ b/examples-testing/examples/webgl_geometry_nurbs.ts
@@ -6,10 +6,10 @@ import { NURBSCurve } from 'three/addons/curves/NURBSCurve.js';
import { NURBSSurface } from 'three/addons/curves/NURBSSurface.js';
@@ -7,10 +7,10 @@ import { NURBSSurface } from 'three/addons/curves/NURBSSurface.js';
import { NURBSVolume } from 'three/addons/curves/NURBSVolume.js';
import { ParametricGeometry } from 'three/addons/geometries/ParametricGeometry.js';

-let container, stats;
Expand All @@ -4365,7 +4365,7 @@ index 8336ef0..d9c564d 100644

let targetRotation = 0;
let targetRotationOnPointerDown = 0;
@@ -78,7 +78,7 @@ function init() {
@@ -79,7 +79,7 @@ function init() {
group.add(nurbsLine);

const nurbsControlPointsGeometry = new THREE.BufferGeometry();
Expand All @@ -4374,16 +4374,45 @@ index 8336ef0..d9c564d 100644

const nurbsControlPointsMaterial = new THREE.LineBasicMaterial({
color: 0x333333,
@@ -123,7 +123,7 @@ function init() {
map.anisotropy = 16;
map.colorSpace = THREE.SRGBColorSpace;
@@ -124,7 +124,7 @@ function init() {
map.anisotropy = 16;
map.colorSpace = THREE.SRGBColorSpace;

- function getSurfacePoint(u, v, target) {
+ function getSurfacePoint(u: number, v: number, target: THREE.Vector3) {
return nurbsSurface.getPoint(u, v, target);
}
- function getSurfacePoint(u, v, target) {
+ function getSurfacePoint(u: number, v: number, target: THREE.Vector3) {
return nurbsSurface.getPoint(u, v, target);
}

@@ -175,23 +175,23 @@ function init() {
// we create evaluation functions for different surfaces with one of the three
// parameter values (u, v, w) kept constant and create multiple THREE.Mesh
// objects one for each surface
- function getSurfacePointFront(u, v, target) {
+ function getSurfacePointFront(u: number, v: number, target: THREE.Vector3) {
return nurbsVolume.getPoint(u, v, 0, target);
}

- function getSurfacePointMiddle(u, v, target) {
+ function getSurfacePointMiddle(u: number, v: number, target: THREE.Vector3) {
return nurbsVolume.getPoint(u, v, 0.5, target);
}

- function getSurfacePointBack(u, v, target) {
+ function getSurfacePointBack(u: number, v: number, target: THREE.Vector3) {
return nurbsVolume.getPoint(u, v, 1, target);
}

- function getSurfacePointTop(u, w, target) {
+ function getSurfacePointTop(u: number, w: number, target: THREE.Vector3) {
return nurbsVolume.getPoint(u, 1, w, target);
}

- function getSurfacePointSide(v, w, target) {
+ function getSurfacePointSide(v: number, w: number, target: THREE.Vector3) {
return nurbsVolume.getPoint(0, v, w, target);
}

@@ -163,7 +163,7 @@ function onWindowResize() {
@@ -260,7 +260,7 @@ function onWindowResize() {

//

Expand All @@ -4392,7 +4421,7 @@ index 8336ef0..d9c564d 100644
if (event.isPrimary === false) return;

pointerXOnPointerDown = event.clientX - windowHalfX;
@@ -173,7 +173,7 @@ function onPointerDown(event) {
@@ -270,7 +270,7 @@ function onPointerDown(event) {
document.addEventListener('pointerup', onPointerUp);
}

Expand All @@ -4401,7 +4430,7 @@ index 8336ef0..d9c564d 100644
if (event.isPrimary === false) return;

pointerX = event.clientX - windowHalfX;
@@ -181,7 +181,7 @@ function onPointerMove(event) {
@@ -278,7 +278,7 @@ function onPointerMove(event) {
targetRotation = targetRotationOnPointerDown + (pointerX - pointerXOnPointerDown) * 0.02;
}

Expand Down
1 change: 1 addition & 0 deletions types/three/examples/jsm/Addons.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export * from './csm/CSMShader.js';
export * as Curves from './curves/CurveExtras.js';
export * from './curves/NURBSCurve.js';
export * from './curves/NURBSSurface.js';
export * from './curves/NURBSVolume.js';
export * as NURBSUtils from './curves/NURBSUtils.js';

export * from './effects/AnaglyphEffect.js';
Expand Down
146 changes: 136 additions & 10 deletions types/three/examples/jsm/curves/NURBSUtils.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,146 @@
import { Vector3, Vector4 } from '../../../src/Three.js';

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[];
/**
* Finds knot vector span.
* @param p degree
* @param u parametric value
* @param U knot vector
* @returns the span
*/
export function findSpan(p: number, u: number, U: readonly number[]): number;

/**
* Calculate basis functions. See The NURBS Book, page 70, algorithm A2.2
* @param span span in which u lies
* @param u parametric point
* @param p degrees
* @param U knot vector
* @returns array[p+1] with basis function values
*/
export function calcBasisFunctions(span: number, u: number, p: number, U: readonly number[]): number[];

/**
* Calculate B-Spline curve points. See The NURBS Book, page 82, algorithm A3.1.
* @param p degree of B-Spline
* @param U knot vector
* @param P control points (x, y, z, w)
* @param u parametric point
* @returns point for given u
*/
export function calcBSplinePoint(p: number, U: readonly number[], P: readonly Vector4[], u: number): Vector4;

/**
* Calculate basis functions derivatives. See The NURBS Book, page 72, algorithm A2.3.
* @param span span in which u lies
* @param u parametric point
* @param p degree
* @param n number of derivatives to calculate
* @param U knot vector
* @returns array[n+1][p+1] with basis functions derivatives
*/
export function calcBasisFunctionDerivatives(
span: number,
u: number,
p: number,
n: number,
U: readonly number[],
): number[][];

/**
* Calculate derivatives of a B-Spline. See The NURBS Book, page 93, algorithm A3.2.
* @param p degree
* @param U knot vector
* @param P control points
* @param u Parametric points
* @param nd number of derivatives
* @returns array[d+1] with derivatives
*/
export function calcBSplineDerivatives(
p: number,
U: readonly number[],
P: readonly Vector4[],
u: number,
nd: number,
): Vector4[];

/**
* Calculate "K over I"
* @returns k!/(i!(k-i)!
*/
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[];

/**
* Calculate derivatives (0-nd) of rational curve. See The NURBS Book, page 127, algorithm A4.2.
* @param Pders result of function calcBSplineDerivatives
* @returns array with derivatives for rational curve.
*/
export function calcRationalCurveDerivatives(Pders: readonly Vector4[]): Vector3[];

/**
* Calculate NURBS curve derivatives. See The NURBS Book, page 127, algorithm A4.2.
* @param p degree
* @param U knot vector
* @param P control points in homogeneous space
* @param u parametric points
* @param nd number of derivatives
* @returns array with derivatives
*/
export function calcNURBSDerivatives(
p: number,
U: readonly number[],
P: readonly Vector4[],
u: number,
nd: number,
): Vector3[];

/**
* Calculate rational B-Spline surface point. See The NURBS Book, page 134, algorithm A4.3.
* @param p degree of B-Spline surface
* @param q degree of B-Spline surface
* @param U knot vector
* @param V knot vector
* @param P control points (x, y, z, w)
* @param u parametric value
* @param v parametric value
* @param target
* @returns point for given (u, v)
*/
export function calcSurfacePoint(
p: number,
q: number,
U: number[],
V: number[],
P: Vector4[],
U: readonly number[],
V: readonly number[],
P: readonly (readonly Vector4[])[],
u: number,
v: number,
target: Vector3,
): Vector3;

/**
* Calculate rational B-Spline volume point. See The NURBS Book, page 134, algorithm A4.3.
* @param p degree of B-Spline volume
* @param q degree of B-Spline volume
* @param r degree of B-Spline volume
* @param U knot vector
* @param V knot vector
* @param W knot vector
* @param P control points (x, y, z, w)
* @param u parametric value
* @param v parametric value
* @param w parametric value
* @param target
* @returns point for given (u, v, w)
*/
export function calcVolumePoint(
p: number,
q: number,
r: number,
U: readonly number[],
V: readonly number[],
W: readonly number[],
P: readonly (readonly (readonly Vector4[])[])[],
u: number,
v: number,
w: number,
target: Vector3,
): Vector3;
23 changes: 23 additions & 0 deletions types/three/examples/jsm/curves/NURBSVolume.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Vector3, Vector4 } from '../../../src/Three.js';

export class NURBSVolume {
degree1: number;
degree2: number;
degree3: number;
knots1: readonly number[];
knots2: readonly number[];
knots3: readonly number[];
controlsPoints: Vector4[][][];

constructor(
degree1: number,
degree2: number,
degree3: number,
knots1: readonly number[],
knots2: readonly number[],
knots3: readonly number[],
controlsPoints: Vector4[][][],
);

getPoint(t1: number, t2: number, t3: number, target: Vector3): void;
}