PDA

View Full Version : Getting vertex index


PerFnurt
15th June 2005, 05:30 AM
Hiya!

Is there an easy way to get/display the index of a selected vertex?

By index I mean what I'd get if I'd do something like


Vertex* selVertex = getSelectedVertex();
if (selVertex!=NULL)
{
ACObject* ob = getObjectThatOwnsVertex(selVertex);
int index=0;
List * vertices = ac_object_get_vertexlist(ob);
for (List *vp = vertices; vp != NULL; vp = vp->next;++index)
{
if (vp == selVertex)
break;
}

// Should always be true, else something
// is wrong in getObjectThatOwnsVertex
if (vp!=NULL)
{
// index holds the "vertex index"
display(index);
}
}


Is there some nifty tcl hack that can accomplish this?

Or would I have to write a complete plugin?
If so, would getObjectThatOwnsVertex actually require traversing every object and their vertices until a match is found or is there some more efficient way?


Thanks

Andy
15th June 2005, 06:08 AM
Prototype ACObject *object_of_vertex(Vertex *pt);

will give the object that owns the vertex.

Vertices are stored in a linked list but do actually have an index property but it it not maintained. This means that you must call one function before you can then read them back. AFAIK this is internal at the moment but should work if you add the prototypes to the plugin header.

This is used to speed things up internally sometimes. e.g. file exporters.
call this:

Prototype int ac_object_vertexlist_set_indexes(ACObject *ob)

Then immediately after, you can call this to find what position in the list a vertex lies.

Prototype int ac_vertex_get_index(Vertex *v)

Note that any changes to the vertex list WILL affect these indexes and you will need to call the set indexes function again.

Andy

PerFnurt
15th June 2005, 06:21 AM
Great, thanks!

PerFnurt
15th June 2005, 03:21 PM
Works like a charm.

Btw, all mentioned functions are already present in the header.

Thanks