THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/03/2006 at 04:02, xxxxxxxx wrote:
I did a search and could find no use of BuildNgonFromPolys in any CINEMA core source, it looks like an unused function. Reason is probably that is easier to use BuildNgon since you don't need to pass a list of polygons, just the outer edges or internal edges (in your case outer is easier to find). Both functions are actually just helpers, you could also just use the Create function and build the ngon edges yourself; however this means adding in the correct marked bits but in your case this is much easier since you have no holes.
Generally it is much easier to use the modeling library and leave it to deal with the internal ngon data, however, in some case (like import when you have the polygons already) or generators (where you need speed) you have to use the direct ngon library itself which is more complicated.
First thing to get right is to build your edge outline as I mentioned, once you have this then you have options on how to build/create an ngon. If you only need to keep your vertex order then you can use the CreateNgon of the modeling library, this will not change your vertex order. The modeling library always tries to keep the order of anything it can, even on deleting vertices it will only remap those that it needs to in order to fit the new point count. If you need to keep your polygons and vertices then you'll have to build the ngon manually from the edges.
Here is a small cut of source that uses BuildNgon for import:
LONG ngon_start=0,ngon_end=0,eind=0,lastface=NOTOK;
LONG *edges = (LONG* )GeAlloc(sizeof(LONG)*4*polyanz);
PolygonObject *pObj = obj;
pObj->GetNgon(); // necessary to build variables
NgonBase *pNgons=pObj->GetNgonBase();
if (pNgons && edges)
{
pObj->Message(MSG_UPDATE);
LONG i=0;
for (t=0; t<=fmax;)
{
if (t<fmax)
{
f=(WFFace* )group->face.Get(t++); if (!f) { SetError(); break; }
anz = f->fnum;
}
else
anz = 3;
if (anz==3 || anz==4)
{
if (lastface==NOTOK) lastface = f->realface;
if (t==fmax || f->realface!=lastface)
{
if (ngon_end-ngon_start>1)
{
if (pNgons->BuildNgon(edges,NULL,eind,0,pObj->GetPolygon(),pObj->GetPoint())==NOTINDEX)
{
// error
}
}
if (t==fmax) break;
ngon_start=ngon_end=i;
lastface=f->realface;
eind=0;
}
if (f->bits&1)
edges[eind++] = 4*i+1;
if (f->bits&2)
edges[eind++] = 4*i+0;
if (f->bits&4)
edges[eind++] = 4*i+3;
ngon_end=i;
i++;
}
t += anz;
}
pNgons->InitMap();
pNgons->SetFlags(NGON_FLAG_NOVALIDATION);
pObj->Message(MSG_UPDATE);
}
GeFree(edges);
Note the NGON_FLAG_NOVALIDATION is set prior to a MSG_UPDATE to inform the ngon handler that it does not need to check any of the structural changes to the object since the ngons are known to be valid. When ngons are found and MSG_UPDATE is called without this flag set then the ngon handler must check all polygon changes have no invalidated the ngon structures, if they have the invalid ngons are removed. This overhead is costly so it should be avoided when possible, e.g. on import when you know the data is correct.