Incremental translation of objects

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2013   #1
Incremental translation of objects

I've been using max for over a century but there's one thing that I've never been able to figure out how to do: Incremental translation snapping.

It's a standard practice in many game editors such as UDK or Unity.

To make the object snap to every Nth unit in space, like grid snapping except in all three dimensions.

Or like percent snapping but not only for scale, for translation too.

Any ideas?
__________________

Last edited by CGmonkey : 02 February 2013 at 07:30 PM.
 
Old 02 February 2013   #2
What about a simple script?

try destroyDialog positionSnap catch()
rollout positionSnap "Position Snap" width:125
(
	spinner spnSnapMult "Unit: " range:[0,1e6,100] fieldWidth:65 type:#worldUnits align:#left
	checkButton chbSnap "SNAP" width:100 height:25 align:#left

	fn roundNearest nr mult =
	(
		if nr < 0 do mult *= -1
		nr + mult/2 - 1 - mod (nr + mult/2 - 1) mult
	)

	mapped fn correctPos obj =
		obj.pos = [roundNearest obj.pos.x spnSnapMult.value,
				   roundNearest obj.pos.y spnSnapMult.value,
				   roundNearest obj.pos.z spnSnapMult.value]

	fn redefineTransformHandlers sel =
	(
		deleteAllChangeHandlers id:#autoSnapTransform
		when transform sel changes id:#autoSnapTransform obj do correctPos obj
	)

	fn initCallbacks =
	(
		callbacks.removeScripts id:#autoSnapTransform
		callbacks.addScript #selectionSetChanged "positionSnap.redefineTransformHandlers selection" id:#autoSnapTransform
		redefineTransformHandlers selection
	)

	fn removeHandlersAndCallbacks =
	(
		 callbacks.removeScripts id:#autoSnapTransform
		 deleteAllChangeHandlers id:#autoSnapTransform
	)

	on positionSnap open do
		removeHandlersAndCallbacks()

	on chbSnap changed state do
		if state then initCallbacks()
		else removeHandlersAndCallbacks()

	on positionSnap close do
		removeHandlersAndCallbacks()
)
createDialog positionSnap


Set the unit to whatever works best for you, once you turn the snap on and you try and move some objects, they should automatically "snap" to a multiple of your unit.
__________________
Scripts :: linkedin
 
Old 02 February 2013   #3
Thank you so much!

You've saved me a ton of frustration

If you're ever in Montreal, beers on me!
__________________
 
Old 02 February 2013   #4
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:09 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.