PDA

View Full Version : vertex_set_point


Dennis
15th July 2004, 02:34 AM
Hi all,

I have a plugin that moves a selection "toward" a 3D point (mainly for moving a selection with higher precision than manual editing allows along a non-axis-aligned plane/edge). I perform moves at the vertex level using vertex_set_point().

The plugin works almost perfectly, but the selection bb doesn't update in the view window. Here's an example of what happens - you can see in the "Left" view where the vertices used to be, and how the selection bb didn't change:

http://bellsouthpwp.net/a/t/atomicd/movetoward_sel.jpg

I'm calling redraw_all() at the end of the function. What am I missing? Is vertex_set_point() the preferred method of moving vertices?

Thanks,
Dennis

Andy
15th July 2004, 03:50 AM
You need to call a couple of other functions. Normals should be recalculated and the bounding box should be remade.

Here's the actual code used for Vertex->Align-to-axis.

Prototype void selected_vertices_align_to_axis(int axis)
{
List *vl = ac_selection_get_vertices_all();
add_undoable_vertex_positions("align vertices", vl);

for (List *p = vl; p != NULL; p = p->next)
{
Vertex *v = (Vertex *)p->data;

switch (axis)
{
case 0: // x
v->x= 0.0;
break;
case 1: // y
v->y = 0.0;
break;
case 2: // z
v->z = 0.0;
break;
}
}

selected_calc_normals();
find_bounding_box();
display_message("%d vertices aligned to axis", list_count(vl));
list_free(&vl);
redraw_all();
}

Whilst vertex_set_point will move the vertex, you really need to make it undoable like above. add_undoable_vertex_positions will record the origional positions of the given vertices and restore them after an undo (and put them back for a redo).

Note that selected_calc_normals will also recalculate any subdivisions too.

Andy

Dennis
15th July 2004, 11:20 AM
I could not seem to find "find_bounding_box()" in the AC3D header file, and, of course, the compiler threw up on it.

However, adding this line to ac_plugin.h fixed it:

Prototype void find_bounding_box();

Let me know if that's the accepted workaround for now.

Based on your comments and code, it looks like I had everything else right (although I used vertex_set_point() instead of directly setting the xyz vals). The Undoable code is *very* handy and easy-to-use once you see an example or two. Excellent work on the Undo system in AC3D!

Thanks,
Dennis

Andy
15th July 2004, 12:01 PM
>Prototype void find_bounding_box();

Oops - how did that get missed out? :?

I've put it in now...

Andy