Skip to content

Commit 02d41f8

Browse files
mmoelle1Mugen87
andauthored
Volumetric NURBS (#27601)
* Update Addons.js * Update NURBSUtils.js Fixed inconsistent naming of parameters in comment * Update NURBSUtils.js * Create NURBSVolume.js * Update webgl_geometry_nurbs.html Expanded NURBS example to NURBSVolume objects. * Update webgl_geometry_nurbs.html Added missing include * Update webgl_geometry_nurbs.html Improve example. * Updated E2E screenshot * Updated E2E screenshot --------- Co-authored-by: Michael Herzog <[email protected]>
1 parent 74aa7bd commit 02d41f8

File tree

5 files changed

+314
-49
lines changed

5 files changed

+314
-49
lines changed

examples/jsm/Addons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export * from './csm/CSMShader.js';
2525
export * as Curves from './curves/CurveExtras.js';
2626
export * from './curves/NURBSCurve.js';
2727
export * from './curves/NURBSSurface.js';
28+
export * from './curves/NURBSVolume.js';
2829
export * as NURBSUtils from './curves/NURBSUtils.js';
2930

3031
export * from './effects/AnaglyphEffect.js';

examples/jsm/curves/NURBSUtils.js

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,10 @@ function calcNURBSDerivatives( p, U, P, u, nd ) {
429429
/*
430430
Calculate rational B-Spline surface point. See The NURBS Book, page 134, algorithm A4.3.
431431
432-
p1, p2 : degrees of B-Spline surface
433-
U1, U2 : knot vectors
434-
P : control points (x, y, z, w)
435-
u, v : parametric values
432+
p, q : degrees of B-Spline surface
433+
U, V : knot vectors
434+
P : control points (x, y, z, w)
435+
u, v : parametric values
436436
437437
returns point for given (u, v)
438438
*/
@@ -472,6 +472,60 @@ function calcSurfacePoint( p, q, U, V, P, u, v, target ) {
472472

473473
}
474474

475+
/*
476+
Calculate rational B-Spline volume point. See The NURBS Book, page 134, algorithm A4.3.
477+
478+
p, q, r : degrees of B-Splinevolume
479+
U, V, W : knot vectors
480+
P : control points (x, y, z, w)
481+
u, v, w : parametric values
482+
483+
returns point for given (u, v, w)
484+
*/
485+
function calcVolumePoint( p, q, r, U, V, W, P, u, v, w, target ) {
486+
487+
const uspan = findSpan( p, u, U );
488+
const vspan = findSpan( q, v, V );
489+
const wspan = findSpan( r, w, W );
490+
const Nu = calcBasisFunctions( uspan, u, p, U );
491+
const Nv = calcBasisFunctions( vspan, v, q, V );
492+
const Nw = calcBasisFunctions( wspan, w, r, W );
493+
const temp = [];
494+
495+
for ( let m = 0; m <= r; ++ m ) {
496+
497+
temp[ m ] = [];
498+
499+
for ( let l = 0; l <= q; ++ l ) {
500+
501+
temp[ m ][ l ] = new Vector4( 0, 0, 0, 0 );
502+
for ( let k = 0; k <= p; ++ k ) {
503+
504+
const point = P[ uspan - p + k ][ vspan - q + l ][ wspan - r + m ].clone();
505+
const w = point.w;
506+
point.x *= w;
507+
point.y *= w;
508+
point.z *= w;
509+
temp[ m ][ l ].add( point.multiplyScalar( Nu[ k ] ) );
510+
511+
}
512+
513+
}
514+
515+
}
516+
const Sw = new Vector4( 0, 0, 0, 0 );
517+
for ( let m = 0; m <= r; ++ m ) {
518+
for ( let l = 0; l <= q; ++ l ) {
519+
520+
Sw.add( temp[ m ][ l ].multiplyScalar( Nw[ m ] ).multiplyScalar( Nv[ l ] ) );
521+
522+
}
523+
}
524+
525+
Sw.divideScalar( Sw.w );
526+
target.set( Sw.x, Sw.y, Sw.z );
527+
528+
}
475529

476530

477531
export {
@@ -484,4 +538,5 @@ export {
484538
calcRationalCurveDerivatives,
485539
calcNURBSDerivatives,
486540
calcSurfacePoint,
541+
calcVolumePoint,
487542
};

examples/jsm/curves/NURBSVolume.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {
2+
Vector4
3+
} from 'three';
4+
import * as NURBSUtils from '../curves/NURBSUtils.js';
5+
6+
/**
7+
* NURBS volume object
8+
*
9+
* Implementation is based on (x, y, z [, w=1]]) control points with w=weight.
10+
**/
11+
12+
class NURBSVolume {
13+
14+
constructor( degree1, degree2, degree3, knots1, knots2, knots3 /* arrays of reals */, controlPoints /* array^3 of Vector(2|3|4) */ ) {
15+
16+
this.degree1 = degree1;
17+
this.degree2 = degree2;
18+
this.degree3 = degree3;
19+
this.knots1 = knots1;
20+
this.knots2 = knots2;
21+
this.knots3 = knots3;
22+
this.controlPoints = [];
23+
24+
const len1 = knots1.length - degree1 - 1;
25+
const len2 = knots2.length - degree2 - 1;
26+
const len3 = knots3.length - degree3 - 1;
27+
28+
// ensure Vector4 for control points
29+
for ( let i = 0; i < len1; ++ i ) {
30+
31+
this.controlPoints[ i ] = [];
32+
33+
for ( let j = 0; j < len2; ++ j ) {
34+
35+
this.controlPoints[ i ][ j ] = [];
36+
37+
for ( let k = 0; k < len3; ++ k ) {
38+
39+
const point = controlPoints[ i ][ j ][ k ];
40+
this.controlPoints[ i ][ j ][ k ] = new Vector4( point.x, point.y, point.z, point.w );
41+
42+
}
43+
44+
}
45+
46+
}
47+
48+
}
49+
50+
getPoint( t1, t2, t3, target ) {
51+
52+
const u = this.knots1[ 0 ] + t1 * ( this.knots1[ this.knots1.length - 1 ] - this.knots1[ 0 ] ); // linear mapping t1->u
53+
const v = this.knots2[ 0 ] + t2 * ( this.knots2[ this.knots2.length - 1 ] - this.knots2[ 0 ] ); // linear mapping t2->v
54+
const w = this.knots3[ 0 ] + t3 * ( this.knots3[ this.knots3.length - 1 ] - this.knots3[ 0 ] ); // linear mapping t3->w
55+
56+
NURBSUtils.calcVolumePoint( this.degree1, this.degree2, this.degree3, this.knots1, this.knots2, this.knots3, this.controlPoints, u, v, w, target );
57+
58+
}
59+
60+
}
61+
62+
export { NURBSVolume };
5 KB
Loading

0 commit comments

Comments
 (0)