Skip to content
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
7 changes: 5 additions & 2 deletions examples/js/curves/NURBSCurve.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
* NURBS curve
**************************************************************/

THREE.NURBSCurve = function ( degree, knots /* array of reals */, controlPoints /* array of Vector(2|3|4) */ ) {
THREE.NURBSCurve = function ( degree, knots /* array of reals */, controlPoints /* array of Vector(2|3|4) */, startKnot /* index in knots */, endKnot /* index in knots */ ) {

this.degree = degree;
this.knots = knots;
this.controlPoints = [];
// Used by periodic NURBS to remove hidden spans
this.startKnot = startKnot || 0;
this.endKnot = endKnot || ( this.knots.length - 1 );
for ( var i = 0; i < controlPoints.length; ++ i ) {

// ensure Vector4 for control points
Expand All @@ -35,7 +38,7 @@ THREE.NURBSCurve.prototype.constructor = THREE.NURBSCurve;

THREE.NURBSCurve.prototype.getPoint = function ( t ) {

var u = this.knots[ 0 ] + t * ( this.knots[ this.knots.length - 1 ] - this.knots[ 0 ] ); // linear mapping t->u
var u = this.knots[ this.startKnot ] + t * ( this.knots[ this.endKnot ] - this.knots[ this.startKnot ] ); // linear mapping t->u

// following results in (wx, wy, wz, w) homogeneous point
var hpoint = THREE.NURBSUtils.calcBSplinePoint( this.degree, this.knots, this.controlPoints, u );
Expand Down
20 changes: 17 additions & 3 deletions examples/js/loaders/FBXLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* - normal / uv
* - material (Multi-Material too)
* - textures (Must be in same directory)
* - nurbs
* - nurbs (Open, Closed and Periodic forms)
*
* No Support
* - morph
Expand Down Expand Up @@ -377,6 +377,7 @@

}

var degree = order - 1;
var knots = this.parseFloatList( nurbsInfo.subNodes.KnotVector.properties.a );

var controlPoints = [];
Expand All @@ -389,17 +390,30 @@

}

var startKnot, endKnot;

if ( nurbsInfo.properties.Form == "Closed" ) {

controlPoints.push( controlPoints[ 0 ] );

} else if ( nurbsInfo.properties.Form === 'Periodic' ) {

startKnot = degree;
endKnot = knots.length - 1 - startKnot;

for ( var i = 0; i < degree; ++ i ) {

controlPoints.push( controlPoints[ i ] );

}

}

var curve = new THREE.NURBSCurve( order - 1, knots, controlPoints );
var curve = new THREE.NURBSCurve( degree, knots, controlPoints, startKnot, endKnot );

// Pre-generate a geometry
var geometry = new THREE.Geometry();
geometry.vertices = curve.getPoints( controlPoints.length * 1.5 );
geometry.vertices = curve.getPoints( controlPoints.length * 7 );

var mesh = new THREE.Line( geometry );
// Store the THREE.NURBSCurve class so the user can recreate a new geometry with a different number of points
Expand Down
28 changes: 17 additions & 11 deletions examples/js/loaders/FBXLoader2.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Animation
* - Separated Animations based on stacks.
* - Skeletal & Non-Skeletal Animations
* NURBS (Open, Closed and Periodic forms)
*
* Needs Support:
* Indexed Buffers
Expand Down Expand Up @@ -1010,15 +1011,7 @@

}

if ( geometryNode.properties.Form === 'Periodic' ) {

console.error( "FBXLoader: Currently no support for Periodic Nurbs Curves for geometry ID: " + geometryNode.id + ", using empty geometry buffer." );
return new THREE.BufferGeometry();

//TODO: Support Periodic NURBS curves.
//Info Link: https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/Maya/files/NURBS-overview-Periodic-closed-and-open-geometry-htm.html

}
var degree = order - 1;

var knots = parseFloatArray( geometryNode.subNodes.KnotVector.properties.a );
var controlPoints = [];
Expand All @@ -1030,14 +1023,27 @@

}

var startKnot, endKnot;

if ( geometryNode.properties.Form === 'Closed' ) {

controlPoints.push( controlPoints[ 0 ] );

} else if ( geometryNode.properties.Form === 'Periodic' ) {

startKnot = degree;
endKnot = knots.length - 1 - startKnot;

for ( var i = 0; i < degree; ++ i ) {

controlPoints.push( controlPoints[ i ] );

}

}

var curve = new THREE.NURBSCurve( order - 1, knots, controlPoints );
var vertices = curve.getPoints( controlPoints.length * 1.5 );
var curve = new THREE.NURBSCurve( degree, knots, controlPoints, startKnot, endKnot );
var vertices = curve.getPoints( controlPoints.length * 7 );

var vertexBuffer = [];
for ( var verticesIndex = 0, verticesLength = vertices.length; verticesIndex < verticesLength; ++ verticesIndex ) {
Expand Down
Loading