View Full Version : Snap only to specified objects?
03-18-2009, 06:41 PM
I'm writing some code for standard UI widgets. Everything is working fine, but one option I'd like to add is snapping that'd allow the user to get a sense of magnetic snapping to either the origin of the widget or to ticks on a slider bar, all of which are just either mesh or curve objects.
So is it possible to set the snapMode to a state that'd allow me to have the currently selected object snap to an array of objects?
Also, what's the likelihood of being able to activate this stuff on the fly? So, for instance, I toggle the snapMode state when specific objects are selected?
03-18-2009, 07:21 PM
...magnetic snapping to either the origin of the widget or to ticks on a slider bar, all of which are just either mesh or curve objects
I've read your post several times, but I can't really figure out what you are trying to do. What do you mean by "widget", is it a dialog? a control? a scene object? You're talking about "mesh or curve objects", how would these snap to "ticks on a slider bar". I'm probably completely misreading your post, so please elaborate :)
03-19-2009, 05:18 PM
Yeah, not as clear as I could have been.
So I'm making widgets for a faceUI, including standard joystick and slider controls.
I'm making the widgets out of curves and planes. All of the widgets look and behave fine, but I'd like to add a little spice to the mix by having snap points for the widgets.
For instance, for a joystick widget, I'd like snap points at the top, bottom, left, right and, most importantly, center. For a standard horizontal or vertical slider, I'd like to have at minimum, a center-point snap and possibly on the tick marks of the slider.
I hope that makes it a little clearer. Basically, snapping curve or geometry to a pre-defined list of other curves or geometry.
03-19-2009, 06:54 PM
You could possibly use a script controller somewhere. See the attached file for reference.
The box has a script controller on its Width Segments track (not using it). That script controller contains 1 variable (widget) that has the box itself assigned to it.
In the script itself...
snapObjs = $GeoSphere*
closestDist = 1e6
closestObj = undefined
for o in snapObjs do (
curDist = distance widget o
if (curDist < closestDist) do (
closestDist = curDist
closestObj = o
if ( closestDist < 20 ) do ( widget.pos = closestObj.pos )
It first gets an array of the objects to snap to - in this case, any objects named "GeoSphere<something>".
It then loops over all of those objects, finding the closest one.
If the box is within 20 units of that closest object, it snaps to that object's (pivot) position. Otherwise, the box's position is left 'as is'.
At the end, a value of '1' is returned (so that the width segments track doesn't complain about getting some value other than a number).
Not sure how well that applies with the objects you use, though
04-15-2009, 10:43 PM
I'm curious - how did this end up? :o
04-15-2009, 10:43 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2014, Jelsoft Enterprises Ltd.