On 17/04/2017 at 10:24, xxxxxxxx wrote:
Cinema 4D Version: R13
Platform: Windows ;
Language(s) : C++ ;
I'm having trouble creating a proper NormalTag on my polygon objects.
When I add the new tag. The object is filled with tiny little lines. It looks like OpenGL is freaking out or something.
I think this is happening because I have not set the tag data. But I'm having trouble figuring out use the Set() function.
Can someone please post a working example?
On 18/04/2017 at 02:43, xxxxxxxx wrote:
please check out the NormalTag manual, I think it should contain everything you need.
On 18/04/2017 at 07:49, xxxxxxxx wrote:
Thanks Andreas. That helped me out a lot.
This is the code version I added to my notes:
//This is how to create a new normals tag on a polygon object
PolygonObject *pobj = (PolygonObject* )doc->GetActiveObject();
if (!pobj || pobj->GetType() != Opolygon) return false;
CPolygon *polys = pobj->GetPolygonW();
LONG polyCount = pobj->GetPolygonCount();
//Get the NormalTag on the object
NormalTag *normalTag = static_cast<NormalTag*>(pobj->GetTag(Tnormal));
//If the object doesn't already have a normals tag on it...we add a new tag
//NOTE: At this point the object will look very bad...filled with tiny openGL lines!!
normalTag = NormalTag::Alloc(pobj->GetPolygonCount());
//To fix this uglyness
//We need to get the normal vectors of the object and store them in the new NormalTag
//First make sure there is a phong tag on the object
if (!pobj->GetTag(Tphong)) pobj->MakeTag(Tphong);
//Get and store the polygon vectors in the new NormalTag so it doesn't look ugly anymore
NormalHandle handle = normalTag->GetDataAddressW();
for (LONG i = 0; i < polyCount; ++i)
const CPolygon polygon = polys[i];
//Calculate the default face normals
Vector normal = CalcFaceNormal(pobj->GetPointR(), polygon);
//Save the normals data in the NormalTag
normals.a = normal;
normals.b = normal;
normals.c = normal;
normals.d = normal;
NormalTag::Set(handle, i, normals);