NormalVertexCycles Class Reference

#include <tangentspacenormalhelper.h>

Detailed Description

A structure that stores all vertex cycles around a vertex. Since in the most common case, the data will not be disjoined (all polygons adjacent to a vertex will share the same vertex normal) a BufferedBaseArray with a size of 1 is used. In the cases where the normals are split, the structure will contain more than one vertex cycle.

Public Member Functions

Result< void > CopyFrom (const NormalVertexCycles &src)
 
Result< void > Init (Int32 vertex, const Block< const Int32 > &pointPolys, const Block< const Vector > &normals, const Block< const Int32 > &vertexIdxInPolygon)
 
Result< void > ConvertDataToTangentSpace (const Block< const Vector > &points, const Block< const SimplePolygon > &polygons, const Block< const Vector > &inNormals, Block< Vector > &outNormals) const
 
Result< void > ConvertDataToObjectSpace (const Block< const Vector > &points, const Block< const SimplePolygon > &polygons, const Block< const Vector > &inNormals, Block< Vector > &outNormals) const
 
Result< void > AverageOutVertexCycleNormals (Block< Vector > &normals) const
 

Public Attributes

BufferedBaseArray< NormalVertexCycle, 1 > _cycles
 
Int32 _vertex
 

Member Function Documentation

◆ CopyFrom()

Result<void> CopyFrom ( const NormalVertexCycles src)

◆ Init()

Result<void> Init ( Int32  vertex,
const Block< const Int32 > &  pointPolys,
const Block< const Vector > &  normals,
const Block< const Int32 > &  vertexIdxInPolygon 
)

Initializes the vertex cycles for this vertex. The vertex cycles are split if the difference between provided normals is greater than an Epsilon value. In the case that all custom normals are aligned, a single vertex cycle will be created.

Parameters
[in]vertexThe vertex which will own the vertex cycles.
[in]pointPolysThe list of polygons that are adjacent to the given vertex. The list should not contain duplicate entries.
[in]normalsFor each polygon, stores the vertex normals. The normals will usually be in object space. normals.GetCount() = 4 * polygonCount.
[in]vertexIdxInPolygonFor each polygon, specifies at which position in the outline is the given vertex located. Each value will be in range [0, 3]
Returns
OK on success, otherwise error.

◆ ConvertDataToTangentSpace()

Result<void> ConvertDataToTangentSpace ( const Block< const Vector > &  points,
const Block< const SimplePolygon > &  polygons,
const Block< const Vector > &  inNormals,
Block< Vector > &  outNormals 
) const

Converts the stored custom vertex normal for the vertex cycles from object space to tangent space representation This should be called after ::Init() was called. The points passed to this function should usually be the ones before any mesh modification occurred.

Parameters
[in]pointsThe 3D data for the points in the polygon object.
[in]polygonsThe list of polygons in the object. each polygon is represented by four vertex indices.
[in]inNormalsThe input normals in object space. inNormals.GetCount() = 4 * polygonCount
[out]outNormalsThe block that will hold the output normals (tangent space). outNormals.GetCount() = 4 * polygonCount. This should be stored and used later for conversion back to object space, once the mesh changes.
Returns
OK on success, otherwise error.

◆ ConvertDataToObjectSpace()

Result<void> ConvertDataToObjectSpace ( const Block< const Vector > &  points,
const Block< const SimplePolygon > &  polygons,
const Block< const Vector > &  inNormals,
Block< Vector > &  outNormals 
) const

Converts the stored custom vertex normal for the vertex cycles from tangent space to object space representation This should be called after ::ConvertDataToTangentSpace() was called. The points passed to this function should usually be the after all mesh modifications are finished This should not be called if the modification altered the topology of the mesh/polygon object. (ie the order of points in a polygon changed, the number of points/polygons changed etc). Note that after this is executed, the normals will not be averaged out, even if they belong to the same cycle. For that, call ::AverageOutVertexCycleNormals() afterwards.

Parameters
[in]pointsThe 3D data for the points in the polygon object.
[in]polygonsThe list of polygons in the object. each polygon is represented by four vertex indices.
[in]inNormalsThe normals in tangent space. inNormals.GetCount() = 4 * polygonCount
[out]outNormalsThe block that will hold the output normals (object space). outNormals.GetCount() = 4 * polygonCount. These should in general be written into the target object (eg. normal tag).
Returns
OK on success, otherwise error.

◆ AverageOutVertexCycleNormals()

Result<void> AverageOutVertexCycleNormals ( Block< Vector > &  normals) const

Iterates over the vertex cycles, and for each vertex cycle, ensures that every custom normal value is aligned. This will ensure that there will be no shading breaks at the positions where there was none to start with. This should be called after ::ConvertDataToObjectSpace() was called.

Parameters
[in,out]normalsFor each polygon, stores the vertex normals. The should be in object space. normals.GetCount() = 4 * polygonCount. This will average out the object space normals after conversion from tangent space to preserve smooths shading in vertex cycles.

Member Data Documentation

◆ _cycles

A list of vertex cycles around the vertex. Each entry contains the polygons, normal per polygon, and the index of the vertex in the outline of each polygon.

◆ _vertex

Int32 _vertex

the vertex that owns these vertex cycles.