Go Back   AC3D Forums > Technical > AC3D Developers
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 15th July 2004, 01:34 AM   #1
Dennis
Senior Member
Professional user
 
Dennis's Avatar
 
Join Date: Jul 2003
Posts: 899
Default vertex_set_point

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:



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
Dennis is offline   Reply With Quote
Old 15th July 2004, 02:50 AM   #2
Andy
Administrator
Professional user
 
Andy's Avatar
 
Join Date: Jun 2003
Posts: 4,563
Default

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.

Code:
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
Andy is offline   Reply With Quote
Old 15th July 2004, 10:20 AM   #3
Dennis
Senior Member
Professional user
 
Dennis's Avatar
 
Join Date: Jul 2003
Posts: 899
Default

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:

Code:
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
Dennis is offline   Reply With Quote
Old 15th July 2004, 11:01 AM   #4
Andy
Administrator
Professional user
 
Andy's Avatar
 
Join Date: Jun 2003
Posts: 4,563
Default

>Prototype void find_bounding_box();

Oops - how did that get missed out? :?

I've put it in now...

Andy
Andy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -4. The time now is 01:44 PM.


AC3D Forum
(C) Inivis Limited 2020