NormalTag Manual

About

A NormalTag stores normal vectors for a (polygon) object. For each polygon a set of four vectors is stored (NormalStruct). The class NormalTag is based on VariableTag so the typical workflows on handling tags apply, see BaseTag and VariableTag Manual.

NormalTag objects are an instance of Tnormal.

Allocation/Deallocation

NormalTag instances are created with the usual tools.

// This example checks if the given object hosts a Normal tag.
// If not, a Normal tag is created.
NormalTag* normalTag = static_cast<NormalTag*>(polyObject->GetTag(Tnormal));
if (normalTag == nullptr)
{
const Int32 polyCnt = polyObject->GetPolygonCount();
normalTag = NormalTag::Alloc(polyCnt);
if (normalTag == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
polyObject->InsertTag(normalTag);
}
Represents a Point Normal tag.
Definition: c4d_basetag.h:565
static NormalTag * Alloc(Int32 count)
maxon::Int32 Int32
Definition: ge_sys_math.h:60
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define Tnormal
Definition: ge_prepass.h:1422

Edit

The normal vectors stored in a NormalTag are accessed by obtaining data handles that are used with static functions:

// This example calculates normal vectors, changes them and stores them in the given Normal tag.
// make sure a Phong tag exists
if (polyObject->GetTag(Tphong) == nullptr)
{
BaseTag* phongTag = polyObject->MakeTag(Tphong);
if (phongTag == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
}
Random random;
NormalHandle handle = normalTag->GetDataAddressW();
for (Int32 i = 0; i < polygonCount; ++i)
{
const CPolygon polygon = polygons[i];
// calculate default face normal
Vector normal = CalcFaceNormal(points, polygon);
NormalStruct normals;
// add random variation
normal.x += ((random.Get01() * 0.2) - 0.1);
normal.y += ((random.Get01() * 0.2) - 0.1);
normal.z += ((random.Get01() * 0.2) - 0.1);
normal.Normalize();
// define polygon normals
normals.a = normal;
normals.b = normal;
normals.c = normal;
normals.d = normal;
NormalTag::Set(handle, i, normals);
}
polyObject->Message(MSG_UPDATE);
Py_ssize_t i
Definition: abstract.h:645
Vector CalcFaceNormal(const Vector *padr, const CPolygon &v)
Definition: c4d_baseobject.h:2218
Definition: c4d_basetag.h:48
NormalHandle GetDataAddressW()
static void Set(NormalHandle dataptr, Int32 i, const NormalStruct &s)
Definition: c4d_basetag.h:634
Definition: c4d_tools.h:812
Float Get01()
#define MSG_UPDATE
Must be sent if the bounding box has to be recalculated. (Otherwise use MSG_CHANGE....
Definition: c4d_baselist.h:358
#define Tphong
Phong.
Definition: ge_prepass.h:1390
void * NormalHandle
Handle for normal data. See also: NormalTag.
Definition: operatingsystem.h:463
Represents a polygon that can be either a triangle or a quadrangle.
Definition: c4d_baseobject.h:44
Definition: operatingsystem.h:601
Vector c
The vertex normal for the third point.
Definition: operatingsystem.h:633
Vector b
The vertex normal for the second point.
Definition: operatingsystem.h:632
Vector a
The vertex normal for the first point.
Definition: operatingsystem.h:631
Vector d
The vertex normal for the fourth point.
Definition: operatingsystem.h:634
T y
Definition: vec.h:40
T x
Definition: vec.h:39
T z
Definition: vec.h:41
void Normalize()
Normalizes this vector, so that GetLength()==1.0.
Definition: vec.h:486

Further Reading