Besides polygons, OBJ can describe curves and surfaces mathematically. A free-form
element is written in three parts: state-setting statements that give its type and
degree, an element statement with its control points, and a body of statements closed
by end.
v 0 0 0
v 1 2 0
v 2 0 0
v 3 2 0
cstype bezier
deg 3
curv 0 1 1 2 3 4
parm u 0 1
end
Curve and surface attributes
These statements set the state for the elements that follow.
| Statement | Meaning |
|---|---|
cstype [rat] type | The curve or surface type: bmatrix (basis matrix), bezier, bspline, cardinal or taylor. rat makes it rational. There is no default. |
deg degu [degv] | The degree in each direction. There is no default for bezier, bspline, taylor and bmatrix. A cardinal is always degree 3, and other values are ignored. The largest degree is 20. |
bmat u matrix, bmat v matrix | The basis matrix for basis-matrix types. It must come after deg. A degree n matrix has (n+1)×(n+1) values, written with the column index varying fastest. There is no default. |
step stepu [stepv] | The step between segments of basis-matrix types: segment i uses the control points from i × step + 1. For Bézier the step equals the degree. There is no default. |
Elements
| Statement | Meaning |
|---|---|
curv u0 u1 v1 v2 … | A curve from parameter u0 to u1, with at least two geometric control points. |
curv2 vp1 vp2 … | A curve in a surface’s parameter space, used for trimming, special curves and connectivity. Control points are vp vertices. At least two are needed. |
surf s0 s1 t0 t1 v1[/vt1[/vn1]] … | A surface, with parameter range s0 to s1 across and t0 to t1 along. Control points are geometric vertices, each optionally with a texture vertex and a normal. |
Non-rational control points are 3D (x y z) on a curve or surface and 2D
on a curv2. Rational ones add a weight, defaulting to 1.0.
Control points of a surface are listed row by row: along the first direction first, then the next row. Surfaces of several patches are listed as one large patch.
Body statements
Between an element and its end, only these statements may appear.
Anything else in that span has unpredictable results.
| Statement | Meaning |
|---|---|
parm u p1 p2 …, parm v p1 p2 … | Global parameter values, or the knot vector of a B-spline. At least two values, in increasing order. Surfaces need both directions and curves only u. If repeated, the last applies. |
trim u0 u1 curv2d … | The outer trimming loop of a surface, built from curv2 curves: each is a start, an end and a curve number. |
hole u0 u1 curv2d … | An inner trimming loop, a hole, in the same form. |
scrv u0 u1 curv2d … | A special curve on the surface, guaranteed to appear as triangle edges. |
sp vp1 … | Special points: 1D for curves and trimming curves, 2D for surfaces. |
end | Closes the body. The checks of its control points and parameter values run here. |
How many control points
At end, the number of control points must fit the type, the degree and
the number of values given by parm. For a curve of degree n with
q parameter values:
| Type | Control points |
|---|---|
| B-spline | q − n − 1 |
| Bézier | (q − 1) × n + 1 |
| Cardinal | q + 2 (always degree 3) |
| Taylor | (q − 1) × (n + 1) |
For a surface, these rules apply in each direction, and the control points number the two results multiplied together. Basis-matrix elements also depend on the step.
con – Connectivity
con surf_1 q0_1 q1_1 curv2d_1 surf_2 q0_2 q1_2 curv2d_2 joins two
surfaces along their trimming curves, with each curve’s start and end parameters.
Connections across different merging groups are ignored. A join that crosses a point
where the curve has a sharp corner should be written as two con
statements.
Superseded statements
Older files may use these. Version 3.0 of the format could still read them but no longer wrote them.
| Statement | Meaning |
|---|---|
bsp v1 … v16 | A B-spline patch of sixteen vertices. |
bzp v1 … v16 | A Bézier patch of sixteen vertices. |
cdp v1 … v16 | A Cardinal patch of sixteen vertices. |
cdc v1 v2 v3 v4 … | A Cardinal curve of four or more vertices. |
res useg vseg | The segments of the patches that follow: each from 3 to 120, and 4 by default. |
In the explorer
Every statement here appears in the structure tree and is checked. The pictures draw Bézier and B-spline curves and surfaces, ignoring trimming and holes. Basis-matrix, Cardinal and Taylor elements and the superseded patches are listed but not drawn.