Page 1 of 1

Is there a way to snap joint anchors together?

Posted: Fri Apr 11, 2014 3:24 pm
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!

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

Posted: Sat Apr 12, 2014 12:40 am
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() ));
	}
}

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

Posted: Tue Apr 15, 2014 4:51 pm
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.

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

Posted: Wed Apr 16, 2014 3:01 am
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 775 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

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

Posted: Fri Apr 18, 2014 1:33 pm
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.