chloelle
chloelle

Reputation: 342

How to correctly format NURBS curves for wavefront .OBJ file format?

I am trying to write a wavefront .OBJ file that contains 3D NURBS curves (not surfaces). I found the following link that describes how to correctly format curves and surfaces within .OBJ files: http://www.martinreddy.net/gfx/3d/OBJ.spec

There is no example for a rational b-spline curve, and it's not clear to me from the documentation how the knot vector is formatted within the parm u section. Any help would be appreciated.

Examples of related code follow. At the link above, there is a description of a rational b-spline surface:

v -1.3 -1.0  0.0
v  0.1 -1.0  0.4  7.6
v  1.4 -1.0  0.0  2.3
v -1.4  0.0  0.2
v  0.1  0.0  0.9  0.5
v  1.3  0.0  0.4  1.5
v -1.4  1.0  0.0  2.3
v  0.1  1.0  0.3  6.1
v  1.1  1.0  0.0  3.3
vt 0.0  0.0
vt 0.5  0.0
vt 1.0  0.0
vt 0.0  0.5
vt 0.5  0.5
vt 1.0  0.5
vt 0.0  1.0
vt 0.5  1.0
vt 1.0  1.0
cstype rat bspline
deg 2 2
surf 0.0 1.0 0.0 1.0 1/1 2/2 3/3 4/4 5/5 6/6 \
7/7 8/8 9/9
parm u 0.0 0.0 0.0 1.0 1.0 1.0
parm v 0.0 0.0 0.0 1.0 1.0 1.0
end

and another example for a bezier curve:

v -2.300000 1.950000 0.000000
v -2.200000 0.790000 0.000000
v -2.340000 -1.510000 0.000000
v -1.530000 -1.490000 0.000000
v -0.720000 -1.470000 0.000000
v -0.780000 0.230000 0.000000
v 0.070000 0.250000 0.000000
v 0.920000 0.270000 0.000000
v 0.800000 -1.610000 0.000000
v 1.620000 -1.590000 0.000000
v 2.440000 -1.570000 0.000000
v 2.690000 0.670000 0.000000
v 2.900000 1.980000 0.000000
# 13 vertices

cstype bezier
ctech cparm 1.000000
deg 3
curv 0.000000 4.000000 1 2 3 4 5 6 7 8 9 10 \
11 12 13
parm u 0.000000 1.000000 2.000000 3.000000  \
4.000000
end
# 1 element

Upvotes: 1

Views: 3160

Answers (1)

beecksche
beecksche

Reputation: 11

There are multiple ways to store the information of a NURBS curve in the wavefront .obj file.

Here is one example:

v -2.300000 1.950000 1.000000 1.000000 
v -2.200000 0.790000 2.000000 1.000000 
v -2.340000 -1.510000 0.000000 1.000000 
v -1.530000 -1.490000 0.000000 1.000000 
v -0.720000 -1.470000 0.000000 1.000000 
v -0.780000 0.230000 0.000000 1.000000 

cstype rat bspline
deg 2
curv 0.00 1.00 1 2 3 4 5 6 
parm u 0.00 0.00 0.00 0.25 0.50 0.75 1.00 1.00 1.00  
end

Now let's have a closer look. We have 6 vertices in cartesian coordinates with additional weight coordinate (x, y, z, w). To define a rational b-spline (NURBS) with a degree of 2 we have to set

cstype rat bspline
deg 2

The next values are defining the curv. The syntax is:

curv [u-start] [u-end] [first-cp] [second-cp] [...]

http://www.martinreddy.net/gfx/3d/OBJ.spec, line 788:

curv u0 u1 v1 v2 . . .

Element statement for free-form geometry.

Specifies a curve, its parameter range, and its control vertices. Although curves cannot be shaded or rendered, they are used by other Advanced Visualizer programs.

u0 is the starting parameter value for the curve. This is a floating point number.

u1 is the ending parameter value for the curve. This is a floating point number.

v is the vertex reference number for a control point. You can specify multiple control points. A minimum of two control points are required for a curve.

For a non-rational curve, the control points must be 3D. For a rational curve, the control points are 3D or 4D. The fourth coordinate (weight) defaults to 1.0 if omitted.

Now we define the u vector/sequence. The values are of course depending on your geometry.

parm u [knot1] [knot2] [...]

http://www.martinreddy.net/gfx/3d/OBJ.spec, line 1107:

parm u p1 p2 p3. . .

parm v p1 p2 p3 . . .

Body statement for free-form geometry.

Specifies global parameter values. For B-spline curves and surfaces, this specifies the knot vectors.

u is the u direction for the parameter values.

v is the v direction for the parameter values.

To set u and v values, use separate command lines.

p is the global parameter or knot value. You can specify multiple values. A minimum of two parameter values are required. Parameter values must increase monotonically. The type of surface and the degree dictate the number of values required.

I hope this helps!

Upvotes: 1

Related Questions