Unit CastleNormals

DescriptionUsesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

Calculating normal vectors for various 3D objects, with appropriate smoothing.

This is developed for VRML/X3D geometric primitives, although some parts are not coupled with VRML/X3D stuff. So it can be used in other situations too.

Uses

Overview

Functions and Procedures

function CreateNormals(CoordIndex: TLongintList; Vertices: TVector3SingleList; CreaseAngleRad: Single; const FromCCW, Convex: boolean): TVector3SingleList;
function CreateFlatNormals(coordIndex: TLongintList; vertices: TVector3SingleList; const FromCCW, Convex: boolean): TVector3SingleList;
function CreateSmoothNormalsCoordinateNode( Node: TAbstractGeometryNode; State: TX3DGraphTraverseState; const FromCCW: boolean): TVector3SingleList;

Description

Functions and Procedures

function CreateNormals(CoordIndex: TLongintList; Vertices: TVector3SingleList; CreaseAngleRad: Single; const FromCCW, Convex: boolean): TVector3SingleList;

Calculate normal vectors for indexed faces, smoothing them according to CreaseAngleRad.

CoordIndex are indexes to Vertices. Indexes < 0 are used to separate faces. So this works just like VRML/X3D IndexedFaceSet.coordIndex.

It's smart and ignores incorrect indexes (outside Vertices range), and incorrect triangles in the face (see IndexedPolygonNormal).

Returns a list of normalized vectors. This has the same Count as CoordIndex, and should be accessed in the same way. This way you (may) have different normal vector values for each vertex on each face, so it's most flexible. (For negative indexes in CoordIndex, corresponding value in result is undefined.)

Remember it's your responsibility to free result of this function at some point.

Parameters
FromCCW
Specifies whether we should generate normals pointing from CCW (counter-clockwise) or CW.
CreaseAngleRad
Specifies in radians what is the acceptable angle for smoothing adjacent faces. More precisely, we calculate for each vertex it's neighbor faces normals. Then we divide these faces into groups, such that each group has faces that have normals within CreaseAngleRad range, and this group results in one smoothed normal. For example, it's possible for a vertex shared by 4 faces to be smoothed on first two faces and last two faces separately.

Note that when creaseAngleRad >= Pi, you wil be better off using CreateSmoothNormals. This will work faster, and return shorter normals array (so it's also more memory-efficient).

Convex
Set this to True if you know the faces are convex. This makes calculation faster (but may yield incorrect results for concave polygons).
function CreateFlatNormals(coordIndex: TLongintList; vertices: TVector3SingleList; const FromCCW, Convex: boolean): TVector3SingleList;

Calculate flat per-face normals for indexed faces.

Note that the result is not a compatible replacement for CreateNormals, as it's Count is the number of faces. For each face, a single normal is stored, as this is most sensible compact representation. Using something larger would be a waste of memory and time.

function CreateSmoothNormalsCoordinateNode( Node: TAbstractGeometryNode; State: TX3DGraphTraverseState; const FromCCW: boolean): TVector3SingleList;

Calculate always smooth normals per-vertex, for VRML/X3D coordinate-based node. We use TAbstractGeometryNode.CoordPolygons for this, so the node class must implement it.

Note that the result is not a compatible replacement for CreateNormals, as this generates Coordinates.Count normal vectors in result. You should access these normal vectors just like Node.Coordinates, i.e. they are indexed by Node.CoordIndex if Node.CoordIndex <> nil.

If Node.Coordinates is Nil (which means that node is coordinate-based, but "coord" field is not present), we return Nil.


Generated by PasDoc 0.13.0 on 2014-08-30 12:10:37