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!!
if (!normalTag)
{
normalTag = NormalTag::Alloc(pobj->GetPolygonCount());
if(normalTag)
{
pobj->InsertTag(normalTag);
EventAdd();
}
}
/////////////////////////////////////////////////////////////////////////////////////
//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);
NormalStruct normals;
//Save the normals data in the NormalTag
normals.a = normal;
normals.b = normal;
normals.c = normal;
normals.d = normal;
NormalTag::Set(handle, i, normals);
}
pobj->Message(MSG_UPDATE);
-ScottA