Is there a way to snap joint anchors together?

General discussion about the R.U.B.E editor
Post Reply
frizzlefry
Posts: 3
Joined: Fri Apr 11, 2014 3:00 pm

Is there a way to snap joint anchors together?

Post by frizzlefry »

Whenever I move a body that has a joint attached to it, the two joint anchors wind up separated by that red dashed line. I understand why they separate; there's no way to know if I'd rather keep the joint at the original location or the new location. I can 't seem find any simple way of re-aligning the joint anchors though, so I wind up having to manually re-position all of them by zooming in really close and trying to line them up with each other. It's especially bad if I just want to tweak the positions for a bunch of bodies on one of my models. I spend most of my time just trying to re-align the joints.

Is there any way to have one anchor snap to the other? Using something like cursor->selection and then selection->cursor would work, although at the moment neither one of those actually works with joint anchors. This is by far the biggest workflow hiccup. I'm a big fan of R.U.B.E. BTW, it's just this one thing that's really slowing me down.

Thanks!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Is there a way to snap joint anchors together?

Post by iforce2d »

There was a thread a while ago offering a couple of script snippets to move one joint anchor to match the other:
viewtopic.php?f=9&t=177

Here is a more generalized version that will work for multiple joints. You need to select the joints to adjust, and a body (most likely, you will have the body selected from just having moved it). Change the boolean value at the beginning of the script to change it from keeping the joints where they were, to moving them along with the moved body:

Code: Select all

//Name: Adjust joint anchors after body move

//set this to false to make the joints move with the body that moved
bool keepJointsWhereTheyWere = false;

body b = sb()[0];
joint[] js = sj();
for (uint i = 0; i < js.length; i++) {
	joint j = js[i];
	if ( keepJointsWhereTheyWere ) {
		if ( j.getBodyA() == b )
			j.setLocalAnchorA( j.getBodyA().getLocalPoint( j.getWorldAnchorB() ));
		else if ( j.getBodyB() == b )
			j.setLocalAnchorB( j.getBodyB().getLocalPoint( j.getWorldAnchorA() ));
	}
	else {
		if ( j.getBodyB() == b )
			j.setLocalAnchorA( j.getBodyA().getLocalPoint( j.getWorldAnchorB() ));
		else if ( j.getBodyA() == b )
			j.setLocalAnchorB( j.getBodyB().getLocalPoint( j.getWorldAnchorA() ));
	}
}
frizzlefry
Posts: 3
Joined: Fri Apr 11, 2014 3:00 pm

Re: Is there a way to snap joint anchors together?

Post by frizzlefry »

Oh awesome, that's perfect. Thanks so much. Any chance something like this would become an actual feature in a future version? This is really going to save me a ton of time, and I would think that my workflow is pretty typical of most users.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Is there a way to snap joint anchors together?

Post by iforce2d »

When it comes to a scriptable feature like this I would probably just add it to the action menu, which is easy enough for you to do anytime. The action menu is fully customizable by placing script files in the right place and editing a "layout.json" file that defines the menu layout. If you don't care much about the details, you can just take the zip file below and unzip it into the "config/actionMenu" folder where your RUBE lives.
extramenu.zip
(702 Bytes) Downloaded 923 times
If you want to know a bit more about setting up menus like this you can watch this YouTube video, I think it covers everything: https://www.youtube.com/watch?v=ZVmBrebebEY
frizzlefry
Posts: 3
Joined: Fri Apr 11, 2014 3:00 pm

Re: Is there a way to snap joint anchors together?

Post by frizzlefry »

Oh wow, that's fantastic. Now I really wish I had dug into the scripting features a long time ago. That's going to work out perfectly for me.

Thanks for the responses and for all the excellent help. I wish more developers had your level of support.
Post Reply