From BlenderWiki

Jump to: navigation, search

As part of work on the modifier system I need to rework how curves/surfaces were handled. The code for Curves is pretty ancient and nasty, probably one of the worst parts of Blender. I thought it would be worthwhile to jot down some notes for future reference as I figured stuff out.

curve_to_displist(ListBase *nubase, ListBase *dispbase)

This one is pretty simple, just tesselates each struct Nurb in the given list into a displist (either a DL_POLY or DL_SEGM). DL_POLY is a line loop, DL_SEGM is a line strip.

makeBevelList(Object *ob)

This function tesselates the curve itself into a list of BevList objects, storing them in cu->bev. Each item in the list is actually a BevList object followed (in memory) by an array of BevPoint objects. Hence the code "bevp = (BevPoint) (&bl + 1)". The array has length "BevList.nr". BevPoints have a position ("x,y,z"), a flag ("f1") for if the BevPoint should be split (every point in a poly curve, or points in a bezier curve with sharp corners), and extra information to calculate bevel orientation (for 2d curves this is two angles ("cosa", "sina"), for 3d curves it is a rotation matrix ("mat")). There is an "alfa" field which copies the "alfa" field from the curve BPoint/BezTriple's but I don't know what it is supposed to be (I think it is time parametrization of curve). Generally (except for curves with 1 point) there is a BevList entry for each struct Nurb element in the Curve.

The routine also does things like removing double points and some other things relating to holes that I haven't bothered to understand.

makebevelcurve(Object *ob, ListBase *dispbase)

This function builds a list of DispList objects that represent the bevel outline. This outline can either be just a line (ext1>0, ext2==0, bevelobj==0), or a simple bevel (ext1=0,ext2=0,bevelobj==0) which is a line with half circle at each end, or a complex curve (bevelobj=0) which can be anything. For the bevelobj case the displist is copied of the bevelobj itself (which was made by curve_to_displist). The input curve is expected to live in the XY plane.

The function shuffles the coordinates of the returned displist so that the X coordinate is 0, and the curve XY become YZ in the displist respectively.

curve_to_filledpoly(Curve *cu, ListBase *nurb, ListBase *dispbase)

This function handles creating a filled polygon for either a single simple filled curve or the filled top/bottom of a bevelled curve.

-- DanielDunbar - 13 Aug 2005