Home Technical Talk

Real grid snapping in 3Ds Max?

polycounter
Offline / Send Message
Davision3D polycounter
Basically I want grid snapping that every decent level editor has in 3Ds Max.

I need to build a lot of assets perfectly grid based currently and the grid snapping options in 3Ds Max are just clunky. There it is like it only snaps the mouse position to the grid and not the actual vertices or object. In the perspective view it only works with the ground plane.

Is there any plugin/script that does it right or am I just missing something? Additionally it would be great if there is also something that allows me to select the vertices that should move to their nearest grid point.

Replies

  • monster
    Options
    Offline / Send Message
    monster polycounter
    [ame]https://www.youtube.com/watch?v=ewg1prguQE0[/ame]

    Maybe look for CAD scripts for 3ds max like the one in this YouTube link.
  • Steppenwolf
    Options
    Offline / Send Message
    Steppenwolf polycounter lvl 15
    Max grid snapping is horrible. Coming from a level design background this has annoyed me since forever. Unfortunately i know of no solution for the perspective viewport.
  • Thane-
    Options
    Offline / Send Message
    Thane- polycounter lvl 3
    I don't know if Arrimus goes over everything you need in this particular video of his, but he might have some info for you. I know he shows how to snap a set of selected vertexes to a specific point. Which is simply selecting them, turning on vertex and grid snap, then moving them by click-dragging over the vertex that will end up over the grid point you've chosen.

    [ame]https://www.youtube.com/watch?v=6--nQD1No-Y&list=PLxt9ZAGPLIpeB8TcHrpzxvEI4Ve3SfZBC&index=140[/ame]
  • Davision3D
    Options
    Offline / Send Message
    Davision3D polycounter
    To clarify: it should be like increment movement with the gizmo. That means when I drag on the gizmo for the movement of a vertice and the snap settings is set to 5 I can then move to position 13.4354 for instance and the vertice snaps to 15. Which then also works in all directions in the perspective view. That is the simple way of how it normally works in level editors but not in 3Ds Max.
    monster wrote: »
    https://www.youtube.com/watch?v=ewg1prguQE0

    Maybe look for CAD scripts for 3ds max like the one in this YouTube link.

    That seems to be not much of a improvement.
    Thane- wrote: »
    I don't know if Arrimus goes over everything you need in this particular video of his, but he might have some info for you. I know he shows how to snap a set of selected vertexes to a specific point. Which is simply selecting them, turning on vertex and grid snap, then moving them by click-dragging over the vertex that will end up over the grid point you've chosen.

    https://www.youtube.com/watch?v=6--nQD1No-Y&list=PLxt9ZAGPLIpeB8TcHrpzxvEI4Ve3SfZBC&index=140
    That shows just the inconvenient way of the snapping.
  • DEElekgolo
    Options
    Offline / Send Message
    DEElekgolo interpolator
    You can make your own "grid object" in 3ds max and activate it so that your grid-snap points will snap to it rather than the usual orthographic or ground-grid.
    Just create a grid object somewhere.
    x9px303.gif
    Right click to activate it, and
    And you can set the size and planes and color and so on.
    Right click again and click "activate home grid" to go back to the other grid.
    kaFHsiz.gif

    Also you can control what it snaps to and what it snaps by right clicking the snap button.

    JGtdVZE.gif

    There is also a snaps toolbar you can unhide that let you quickly set it to snap to vertices or pivots or to the grid or the surface of polygons and such.
    zIoXhL9.gif

    Davision3D wrote: »
    To clarify: it should be like increment movement with the gizmo. That means when I drag on the gizmo for the movement of a vertice and the snap settings is set to 5 I can then move to position 13.4354 for instance and the vertice snaps to 15. Which then also works in all directions in the perspective view. That is the simple way of how it normally works in level editors but not in 3Ds Max.

    You can set the grid spacing of the home grid and user grids, and use the ortho graphic views to get the non-ground-grid snapping or the user-gid and set the xy-zy-etc planes when you need it. Honestly I would just use the orthographic grid. The only tool I know that has all the xyz planes set up to have a grid in the viewport is modo.
    cNcnc29.gif
    YRXIQG3.gif

    Also you should be able to snap edges and vertices to the grid just fine.
    7Y4AdtN.gif
  • Davision3D
    Options
    Offline / Send Message
    Davision3D polycounter
    @ DEElekgolo
    Thanks for the gifs! But that grid object doesn't really help and rest I know already.

    Main problems are:
    - When a vertice ,etc is not already in the grid it will not be moved in the grid: a vertice at position 1.3443 with the grid spacing being 10 will be moved to 11.3443.
    - There can only be 1 grid object be active at a time so you can always only use a grid in 1 direction x, y or z.
    - I mostly work just in the perspective view and switching between all the views for each orientation is just not feasible. Basically most of my modeling will have to be in the grid. Basically I want do do normal modeling but not allowing values like 12.3434 and insteaad 10,20,30 etc..
  • SonicBlue
    Options
    Offline / Send Message
    SonicBlue polycounter lvl 10
    And I've always thought that Cinema 4D snap to grid was bad.


    Have you tried to snap it to a Plane subdivided to the size you need?

    I think it's possible to set a mesh to be not selectable but visible in wireframe mode, so that you can use it as a guide and enable Edge or Vertex snap.
  • DEElekgolo
    Options
    Offline / Send Message
    DEElekgolo interpolator
    Davision3D wrote: »
    Main problems are:
    - When a vertice ,etc is not already in the grid it will not be moved in the grid: a vertice at position 1.3443 with the grid spacing being 10 will be moved to 11.3443.
    Davision3D wrote: »
    To clarify: it should be like increment movement with the gizmo. That means when I drag on the gizmo for the movement of a vertice and the snap settings is set to 5 I can then move to position 13.4354 for instance and the vertice snaps to 15. Which then also works in all directions in the perspective view. That is the simple way of how it normally works in level editors but not in 3Ds Max.
    Maybe I don't get what you mean. Max does this by default. A non-aligned vertex moved with grid snap enabled will move say a 4.2 vertex to 5.0.

    fGachBc.gif

    Or do you mean you want a 5.0 offset?

    Like you have a vertex at 4.2 and want it to offset by exactly 5.0 so it's 9.2? Or such that all movement of the gizmo at all is only by these 5.0 or 10.0 increments? Do you have a level editor in mind of what you mean?

    If what I think you mean is correct, setting the Snap radius to a high amount should be what you mean, this would make any movement made with the gizmo snap to the active grid and disallow any of the intermediate positions.
    iKrwrr4.png

    I don't know anything about having the xz and yz planes visible and snap-able in the 3ds max viewport though
  • SonicBlue
    Options
    Offline / Send Message
    SonicBlue polycounter lvl 10
    Analysing this better, I see what the problem is, the inability of 3ds Max to snap to the grid while on perspective view, I don't think he wanted to drag a point and snap it, but he want to select some stuff and while moving it around, snap it to the grid.

    In Maya and XSI this is possible, while holding X in Maya and CTRL in XSI, it will automatically snap to the nearest grid position if you drag one of the gizmo handles.
  • Davision3D
    Options
    Offline / Send Message
    Davision3D polycounter
    SonicBlue wrote: »
    And I've always thought that Cinema 4D snap to grid was bad.


    Have you tried to snap it to a Plane subdivided to the size you need?

    I think it's possible to set a mesh to be not selectable but visible in wireframe mode, so that you can use it as a guide and enable Edge or Vertex snap.

    Yea, theoretically I could make a 3 dimensional grid as a mesh or with splines and then snap to that. Allowing snapping to a freezed object should also work. But the problem is that it will then also snap to grid points in depth, so you could just snap to points that are far away or very close in depth. So it probably gets also messy.
    DEElekgolo wrote: »
    Maybe I don't get what you mean. Max does this by default. A non-aligned vertex moved with grid snap enabled will move say a 4.2 vertex to 5.0.

    fGachBc.gif

    Or do you mean you want a 5.0 offset?

    Like you have a vertex at 4.2 and want it to offset by exactly 5.0 so it's 9.2? Or such that all movement of the gizmo at all is only by these 5.0 or 10.0 increments? Do you have a level editor in mind of what you mean?

    If what I think you mean is correct, setting the Snap radius to a high amount should be what you mean, this would make any movement made with the gizmo snap to the active grid and disallow any of the intermediate positions.
    iKrwrr4.png

    I don't know anything about having the xz and yz planes visible and snap-able in the 3ds max viewport though

    No it does it not by default, atleast not for me and that was a problem. But I found the option for it now, this is how it was for me: poKWZQP.gif
    This is tickbox I had to set on for it to work like it does for you:
    Ij6fpwj.gif
    When you have vertex snapping on it also snaps your starting point vertex so you don't have offset with that even though the tickbox is off.
    Looking at your pic it looks like they stripped that option from newer versions of max.

    That makes it better but not having a 3 dimensional grid is still a huge point.
  • SonicBlue
    Options
    Offline / Send Message
    SonicBlue polycounter lvl 10
    At this point, you can select the vertices that needs to be aligned to a round number and input the desired value in your coordinates manager.
  • Fwap
    Options
    Offline / Send Message
    Fwap polycounter lvl 13
    Tick the other constrain to axis checkbox.
    Having used a bunch of different modelling programs i still think max's although not as good still stacks up against say Modo or Maya, its just missing some intuitive hotkeys for quickly changing the snapping type.

    But basically without the constrain to axis check box on, its useless in the perspective viewport, why its not enabled by default is beyond me.
  • Davision3D
    Options
    Offline / Send Message
    Davision3D polycounter
    SonicBlue wrote: »
    At this point, you can select the vertices that needs to be aligned to a round number and input the desired value in your coordinates manager.
    That is even less feasible. I need to do modeling with it. With that I'm getting close to modeling in a spreadsheet! ;)

    Fwap wrote: »
    Tick the other constrain to axis checkbox.
    Having used a bunch of different modelling programs i still think max's although not as good still stacks up against say Modo or Maya, its just missing some intuitive hotkeys for quickly changing the snapping type.

    But basically without the constrain to axis check box on, its useless in the perspective viewport, why its not enabled by default is beyond me.
    That just constraints it to the selected axis on the gizmo but it is still bound to the grid plan. So with the floor grid plane on I still have no up and down snapping active. When I then use the Z only axis on the gizmo nothing happens. Makes it more comfortable to use though.
  • Mark Dygert
    Options
    Offline / Send Message
    Davision3D wrote: »
    No it does it not by default, atleast not for me and that was a problem. But I found the option for it now, this is how it was for me: poKWZQP.gif
    What version of 3dsmax are you using? They've made some improvements in more recent versions, like the addition of the center gizmo. Instead of clicking on the axis handles you click on the center of the gizmo and move it around. Its a whole lot better now. Still, even in older versions it was a lot more manual but you could achieve similar results.
    http://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/3DSMax/files/GUID-66F42B65-7EA5-4CF8-BBF1-46EBC0845C75-htm.html
    Snap Handle When Moving an Object
    When both the Snap tool (any mode) and the Move tool are active and Enable Axis Constraints is on, the Move gizmo shows a circle at its center.

    GUID-9213B478-1EEB-483B-8383-505C89A29CD7.png
    A circle at the center of the Move gizmo shows that snapping is active.

    Not only does the circular handle indicate that snapping is active, it helps increase the accuracy of snapping. You can use the gizmo controls as before, or drag the handle itself: In either case, 3ds Max shows the original position of the object, and by default a rubber-band line stretches from the original position to the new destination. When you drag the snap handle or the Move gizmo, the axis center is the start snap point.

  • monster
    Options
    Offline / Send Message
    monster polycounter
    I took a look at Maya's Grid snapping and it's very similar to 3ds Max's, and has the same limitations. HOWEVER, I notice that Maya's move tool has a discrete move option that allows you to move on objects in increments of the given value.

    It's not hard to make a script that does this at the object level. Sub-Objects might be tricky.

    I make lots of tools, if you like I can develop this further.

    DiscreteMove.gif
  • Davision3D
    Options
    Offline / Send Message
    Davision3D polycounter
    monster wrote: »
    I took a look at Maya's Grid snapping and it's very similar to 3ds Max's, and has the same limitations. HOWEVER, I notice that Maya's move tool has a discrete move option that allows you to move on objects in increments of the given value.

    It's not hard to make a script that does this at the object level. Sub-Objects might be tricky.

    I make lots of tools, if you like I can develop this further.

    DiscreteMove.gif

    So that is what you already made as a script or is that in Maya? Looks exactly like in UE4! But I assume it is then offset moving, like 12.343 becomes with a increment of 10 then 22.343. Would be still great though. Would be really awesome to have that also working in sub-level with vertices and stuff.
    Yesterday I tried modeling in a grid with the existing grid snapping and it was often frustrating and slow. When I then put something in UE4 everything simple snapped in place which makes me really wonder why Autodesk never did something like it.
    What version of 3dsmax are you using? They've made some improvements in more recent versions, like the addition of the center gizmo. Instead of clicking on the axis handles you click on the center of the gizmo and move it around. Its a whole lot better now. Still, even in older versions it was a lot more manual but you could achieve similar results.
    My newest is only 2009, I know it is really old but when you have to buy it on your own and you see that huge price tag every year you rather say: nope, those new features are not that exiting.
    I'm also not so sure that that handle makes it much better, I guess it just replaces that option I changed there before.
  • Eric Chadwick
    Options
    Offline / Send Message
    Not sure if this was mentioned already, but have you tried turning off the transform gizmo when moving/snapping your vertices? The hotkey for this used to be X.

    With the gizmo out of the way, the start snap point is on the vertex itself, not where ever you happen to click on the gizmo.

    And you can change the axes faster with hotkeys... X, Y, XY, XZ, etc... than by mousing around to find the right yellow overlay.

    Worth a try.
  • monster
    Options
    Offline / Send Message
    monster polycounter
    So that is what you already made as a script or is that in Maya? Looks exactly like in UE4!

    It's in 3ds Max, but the script was super buggy at the time so I didn't want to post it yet.
    Not sure if this was mentioned already, but have you tried turning off the transform gizmo when moving/snapping your vertices? The hotkey for this used to be X.

    With the gizmo out of the way, the start snap point is on the vertex itself, not where ever you happen to click on the gizmo.

    In newer versions of Max this is no longer necessary if you have vertex snap turned on. But I used to do that all the time back in the day. :)
  • Eric Chadwick
    Options
    Offline / Send Message
    Yeah, he's using 2009.
  • monster
    Options
    Offline / Send Message
    monster polycounter
    So this only works on Object level right now, not subObject.

    Features:
    • When enabled it snaps any object by it's pivot to the grid.
    • It uses the Grid Spacing in your snap settings.
    • It can snap vertically in the perspective viewport.

    Known issues:
    • Doesn't work on subObjects yet.
    • You should turn off the built in snapping tool.

    To install or update drag and drop the script into your 3ds Max viewport. Then look in the monsterBlues category to put on a toolbar.


    Download
    For Max 2009 please read this.

    Martinez_Macro_GridBasedMovement.gif

    Martinez_Macro_GridBasedMovement2.gif
  • Davision3D
    Options
    Offline / Send Message
    Davision3D polycounter
    monster wrote: »
    So this only works on Object level right now, not subObject.

    Features:
    • When enabled it snaps any object by it's pivot to the grid.
    • It uses the Grid Spacing in your snap settings.
    • It can snap vertically in the perspective viewport.

    Known issues:
    • Doesn't work on subObjects yet.
    • Negative quadrents act a little funny, but it still works.
    • Passing from positive to negative quadrents has a hitch.

    To install or update drag and drop the script into your 3ds Max viewport. Then look in the monsterBlues category to put on a toolbar.


    Download

    Martinez_Macro_GridBasedMovement.gif

    Martinez_Macro_GridBasedMovement2.gif

    Thanks! But it looks like there are some problems with my version of 3Ds Max, when I drop it in I get this error: Sfyab5F.jpg
    I just get rid of that error by getting rid of that autoundo.

    When I then click on the GridMove button I get his error:
    ju6NLtT.jpg
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Okay try again. Download again and drag and drop it into the viewport to update.

    I got rid of references to "this". And commented out the AutoUndoEnabled parameter. I don't have Max 2009 to test. But let me know if this works and if you think it would be worth developing further.


    Slight rant:
    Typically in Max 2009, you could define a struct like so:

    struct
    (
    this,
    otherVariables
    )

    You could self reference items in the struct with "this". In 2010 you no longer needed to declare "this" as it's auto declared. But in Max 2014 they disabled duplicate declarations which means all the old scripts with "this" don't work anymore. I'm annoyed.
  • Davision3D
    Options
    Offline / Send Message
    Davision3D polycounter
    monster wrote: »
    Okay try again. Download again and drag and drop it into the viewport to update.

    I got rid of references to "this". And commented out the AutoUndoEnabled parameter. I don't have Max 2009 to test. But let me know if this works and if you think it would be worth developing further.


    Slight rant:
    Typically in Max 2009, you could define a struct like so:

    struct
    (
    this,
    otherVariables
    )

    You could self reference items in the struct with "this". In 2010 you no longer needed to declare "this" as it's auto declared. But in Max 2014 they disabled duplicate declarations which means all the old scripts with "this" don't work anymore. I'm annoyed.

    That fixed the first error but the issue with this "this" is still there, it is still the same line it marks: gbm.this = gbm
    When I simply delete that I get the error with the next line. :(
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Hey Davision3D,

    Can you try changing this:
    	struct gridBasedMovement
    	(
    		enabled = false,
    

    to this:
    	struct gridBasedMovement
    	(
    		this,
    		enabled = false,
    

    If that doesn't work, I'll need to hunt down a copy of 2009 to fix it.
  • Synaesthesia
    Options
    Offline / Send Message
    Synaesthesia polycounter
    While we're at it, did anyone figure this out yet? :)
  • monster
  • Davision3D
    Options
    Offline / Send Message
    Davision3D polycounter
    monster wrote: »
    Hey Davision3D,

    Can you try changing this:
    	struct gridBasedMovement
    	(
    		enabled = false,
    

    to this:
    	struct gridBasedMovement
    	(
    		this,
    		enabled = false,
    

    If that doesn't work, I'll need to hunt down a copy of 2009 to fix it.

    That makes it work but only in x. Snapping in y and z does not work no matter how I try it. It works nicely while i move it in x though.
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Lame! We'll I'll see if I can find a copy of 2009 to work with. Maybe a couple of days.
  • Davision3D
    Options
    Offline / Send Message
    Davision3D polycounter
    monster wrote: »
    Lame! We'll I'll see if I can find a copy of 2009 to work with. Maybe a couple of days.

    Thanks! I noticed now that it works for y and z for the first pixel of the drag and that always seems to snap to the next increment of that direction even though the starting grid point is closer. The next pixels then drag it normally like without snapping so it isn't useful. For x it works all right.
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Davision3D, Good new, bad news for Max 2009.

    Bad news:
    I'm going to chalk it up to a bug in the default max position controller. It seems to be an internal hard coded optimization is preventing the controller from being updated rapidly.

    Good news:
    There are a couple of workarounds.

    1) If you change all your objects to TCB or Linear position controllers everything works perfectly. You can even set the default position controller in the Preferences > Animation. If your not an animator, it shouldn't matter too much. You can change all the selected objects to TCB controllers with this script:
    for obj in selection do obj.position.controller = TCB_Position()
    

    2) You can change the following line in the code. It will force the script to update when you are done moving the object. The only issue is that it won't snap interactively, only when you are done moving.
    			when transform objects changes id:#DiscreteMove obj do
    
    			when transform objects changes id:#DiscreteMove handleAt:#redrawViews obj do
    

    Sorry I couldn't fix it properly.
  • Davision3D
    Options
    Offline / Send Message
    Davision3D polycounter
    monster wrote: »
    Davision3D, Good new, bad news for Max 2009.

    Bad news:
    I'm going to chalk it up to a bug in the default max position controller. It seems to be an internal hard coded optimization is preventing the controller from being updated rapidly.

    Good news:
    There are a couple of workarounds.

    1) If you change all your objects to TCB or Linear position controllers everything works perfectly. You can even set the default position controller in the Preferences > Animation. If your not an animator, it shouldn't matter too much. You can change all the selected objects to TCB controllers with this script:
    for obj in selection do obj.position.controller = TCB_Position()
    

    2) You can change the following line in the code. It will force the script to update when you are done moving the object. The only issue is that it won't snap interactively, only when you are done moving.
    			when transform objects changes id:#DiscreteMove obj do
    
    			when transform objects changes id:#DiscreteMove handleAt:#redrawViews obj do
    

    Sorry I couldn't fix it properly.

    Thanks, the script already helps a lot this way! I'm sure there are also many level designers that will find it very useful.

    Interestingly it has no problem updating it to TCB_Position rapidly. Is there a place in the script where TCB_Position would be set once to the objects I currently move or just when I start the movement?
    Using TCB_Position instead is otherwise no problem for me, just keeping in mind that I have to set it for each new object first.
  • Servus
    Options
    Offline / Send Message
    Servus polycounter lvl 4
    This feature is still non-existent in 3DS Max 2018 it seems. Do the swathes of people working on modular items or projects where things must be standardised sizes use scripts or do they just avoid 3DS Max I wonder.
  • ActionDawg
    Options
    Offline / Send Message
    ActionDawg greentooth
    Servus said:
    This feature is still non-existent in 3DS Max 2018 it seems. Do the swathes of people working on modular items or projects where things must be standardised sizes use scripts or do they just avoid 3DS Max I wonder.
    what exactly do you feel does not exist in Max 2018? i have been able to do everything discussed in this thread.

    there are extensive examples of modular work within Max.
  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    Max snapping is brilliant these days (far superior to maya) ,  chances are you're missing something if it doesn't accommodate your needs.

    Can you explain exactly what's missing?   
  • Bletzkarn
    Options
    Offline / Send Message
    Bletzkarn polycounter lvl 6
    Has anyone found a good solution to this? 

    I still find max snapping to be pretty terrible. Ideally I would like 3DSMAX to snap every 10cm IN ALL DIRECTIONS. Complete orthographic snapping without difficult grid setups. 

    Essentially how UE4 is by default. 

  • xvampire
    Options
    Offline / Send Message
    xvampire polycounter lvl 14
    found solution made by   Vojtěch Čada  or   Swordslayer
    original link and script is here : 
    https://forums.autodesk.com/t5/3ds-max-forum/auto-snap-verts-to-whole-numbers-on-object-move-or-dragging/td-p/5452916

    I merged his  both object and vertex snapping in one tool for convenience  ( pardon if the script is a bit Frankenstein-ish ) 


    try destroyDialog positionSnap catch()
    rollout positionSnap "Position Snap" width:125
    (
    	group "object"(
    	spinner spnSnapMult "Unit: " range:[0,1e6,100] fieldWidth:65 type:#worldUnits align:#left
    	checkButton chbSnap "SNAP Object" width:100 height:25 align:#left
    	)
    	group "vertex"(
    	spinner spnSnapMultVert "Unit: " range:[0,1e6,100] fieldWidth:65 type:#worldUnits align:#left
    	checkButton chbSnapVert "SNAP Vertex" width:100 height:25 align:#left
    )
    	
    --  Object Snap
    	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
    	
    	)
    	
    	
    -- Vertex Snap	
    	
    	local getPolyVert = polyOp.getVert
    	local setPolyVert = polyOp.setVert
    	local getPolyVertSel = polyOp.getVertSelection
    	local getPolyEdgeSel = polyOp.getEdgeSelection
    	local getPolyFaceSel = polyOp.getFaceSelection
    	local getVertsByEdge = polyOp.getVertsUsingEdge
    	local getVertsByFace = polyOp.getVertsUsingFace
    	
    	
    	fn roundVert vert val =
    	(
    		vert.x = roundNearest vert.x val
    		vert.y = roundNearest vert.y val
    		vert.z = roundNearest vert.z val
    		vert
    	)
    
    	fn setRoundedVerts obj =
    	(
    		local snapVal = spnSnapMultVert.value
    		local verts = case subObjectLevel of
    		(
    			1 : getPolyVertSel obj
    			2 : getVertsByEdge obj (getPolyEdgeSel obj)
    			3 : getVertsByEdge obj (getPolyEdgeSel obj)
    			4 : getVertsByFace obj (getPolyFaceSel obj)
    			5 : getVertsByFace obj (getPolyFaceSel obj)
    			default : #{}
    		)
    		setPolyVert obj verts (for v in verts collect roundVert (getPolyVert obj v) snapVal)
    		setNeedsRedraw()
    	)
    
    	fn redefineGeometryHandlers sel =
    	(
    		deleteAllChangeHandlers id:#autoSnapGeometry
    		when geometry sel changes id:#autoSnapGeometry handleAt:#redrawViews obj do setRoundedVerts obj
    	)
    	
    		fn removeHandlers =
    		deleteAllChangeHandlers id:#autoSnapGeometry
    	
    	-- interface
    
    	on positionSnap open do
    	(	removeHandlersAndCallbacks()
    	removeHandlers()
    	)
    	on chbSnap changed state do
    		if state then initCallbacks()
    		else removeHandlersAndCallbacks()
    	
    	on chbSnapVert changed state do
    	if state then redefineGeometryHandlers (selection[1])
    		else removeHandlers()
    	
    
    	on positionSnap close do
    			(	removeHandlersAndCallbacks()
    	removeHandlers()
    	)
    )
    createDialog positionSnap

Sign In or Register to comment.