THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 31/07/2011 at 07:17, xxxxxxxx wrote:
This is how you to create a NormalTag in pre R12. For simplicity I create random normals for each point normal. There are 12 WORDs for each polygon presenting the 12 vector components (x,y,z) of the four points of an polygon, each multiplied by 32000.0.
Bool MenuTest::Execute(BaseDocument *doc)
{
StopAllThreads();
BaseObject *op = doc->GetActiveObject();
if (!op) return FALSE;
if (op->GetType() != Opolygon) return FALSE;
LONG polycnt = ToPoly(op)->GetPolygonCount();
VariableTag *ntag = VariableTag::Alloc(Tnormal, polycnt*12);
if (!ntag) return FALSE;
// elements are of type WORD (unsigned short)
unsigned short *nadr = (unsigned short* )ntag->GetDataAddressW();
Random rnd;
rnd.Init(56337);
Vector n;
for (LONG i=0; i<polycnt; i++)
{
// normal for point A
n = !Vector(rnd.Get11(), rnd.Get11(), rnd.Get11());
nadr[i*12] = 32000.0 * n.x;
nadr[i*12+1] = 32000.0 * n.y;
nadr[i*12+2] = 32000.0 * n.z;
// normal for point B
n = !Vector(rnd.Get11(), rnd.Get11(), rnd.Get11());
nadr[i*12+3] = 32000.0 * n.x;
nadr[i*12+4] = 32000.0 * n.y;
nadr[i*12+5] = 32000.0 * n.z;
// normal for point C
n = !Vector(rnd.Get11(), rnd.Get11(), rnd.Get11());
nadr[i*12+6] = 32000.0 * n.x;
nadr[i*12+7] = 32000.0 * n.y;
nadr[i*12+8] = 32000.0 * n.z;
// normal for point D
n = !Vector(rnd.Get11(), rnd.Get11(), rnd.Get11());
nadr[i*12+9] = 32000.0 * n.x;
nadr[i*12+10] = 32000.0 * n.y;
nadr[i*12+11] = 32000.0 * n.z;
}
op->InsertTag(ntag, NULL);
op->Message(MSG_UPDATE);
EventAdd();
return TRUE;
}
Since R12 it's much easier to use an the docs should explain it quite well.
cheers,
Matthias