Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

3ds max UV Vert Snap selected to nearest grid intersection script?

polycounter lvl 20
Offline / Send Message
TorQue[MoD] polycounter lvl 20
Hey all. So I'm currently working on lightmap UVs for a brick wall (where each brick is modeled) and there's a lot of verts for me to snap manually. Was wondering if anyone knows a faster way to, or a script that will snap all of the selected verts to their closest grid intersection?
 

Replies

  • hazard668
    Offline / Send Message
    hazard668 polycounter lvl 7
    1. MacroScript CrankshaftTools_UVSnapper_snapX_macro buttonText:"UV snap X" category:"Crankshaft Tools" tooltip:"UV snap X" autoUndoEnabled:true icon:#("standard", 1) -- use first icon in standard<br>(<br> fn round_to val n =<br> (<br> local mult = 10.0 ^ n<br> (floor ((val * mult) + 0.5)) / mult<br> )<br> <br> on execute do<br> (<br> mod_unwrap = $.modifiers[#Unwrap_UVW]<br> if(mod_unwrap!=undefined)then <br> (<br> local gridSize = mod_unwrap.unwrap2.getGridSize()<br> if(mod_unwrap.getTVSubObjectMode() == 3) then<br> (<br> mod_unwrap.faceToVertSelect()<br> )<br> else if(mod_unwrap.getTVSubObjectMode() == 2) then<br> (<br> mod_unwrap.edgeToVertSelect()<br> )<br> <br> vArray = mod_unwrap.getSelectedVertices()<br> for vVar in vArray do<br> (<br> oldPos = mod_unwrap.getVertexPosition 0 vVar<br> --print oldPos.x<br> snappedX = (round_to (oldPos.x / gridSize) 0 ) * gridSize<br> --print snappedX<br> mod_unwrap.setVertexPosition 0 vVar [snappedX, oldPos.y, 0]<br> )<br> )<br> redrawViews()<br> )<br>)<br><br><br>MacroScript CrankshaftTools_UVSnapper_snapY_macro buttonText:"UV snap Y" category:"Crankshaft Tools" tooltip:"UV snap Y" autoUndoEnabled:true icon:#("standard", 1) -- use first icon in standard<br>(<br> fn round_to val n =<br> (<br> local mult = 10.0 ^ n<br> (floor ((val * mult) + 0.5)) / mult<br> )<br> <br> on execute do<br> (<br> mod_unwrap = $.modifiers[#Unwrap_UVW]<br> if(mod_unwrap!=undefined)then <br> (<br> local gridSize = mod_unwrap.unwrap2.getGridSize()<br> if(mod_unwrap.getTVSubObjectMode() == 3) then<br> (<br> mod_unwrap.faceToVertSelect()<br> )<br> else if(mod_unwrap.getTVSubObjectMode() == 2) then<br> (<br> mod_unwrap.edgeToVertSelect()<br> )<br> <br> vArray = mod_unwrap.getSelectedVertices()<br> for vVar in vArray do<br> (<br> oldPos = mod_unwrap.getVertexPosition 0 vVar<br> --print oldPos.y<br> snappedY = (round_to (oldPos.y / gridSize) 0 ) * gridSize<br> --print snappedX<br> mod_unwrap.setVertexPosition 0 vVar [oldPos.x, snappedY, 0]<br> )<br> )<br> redrawViews()<br> )<br>)

    Try this macroscript. It's help to snap selected vertices to nearest vertical or horizontal grid lines.


  • TorQue[MoD]
    Offline / Send Message
    TorQue[MoD] polycounter lvl 20
    You are awesome! But I have no idea how to use it. I copied the script to notepad, saved it as UVSnapper.ms and tried to run it from Max (2014) but it didn't do anything. Also how does one run a script on an unwrap cause it closes the UV editor when you hit run script.

    Your help is super appreciated but I don't know what I'm doing :P   
  • musashidan
    Offline / Send Message
    musashidan high dynamic range
    It's a macroscript. When you run it it adds the script ro the usermacros folder and then you need to set it to a hotkey or toolbar in the customise ui dialogue.
  • hazard668
    Offline / Send Message
    hazard668 polycounter lvl 7
    It's a macroscript. When you run it it adds the script ro the usermacros folder and then you need to set it to a hotkey or toolbar in the customise ui dialogue.

    Exactly. Also I find it handy to have such commands in quad menu.

  • TorQue[MoD]
    Offline / Send Message
    TorQue[MoD] polycounter lvl 20
    Oh awesome! Seriously thanks a million for this. That's a huge time saver.
  • musashidan
    Offline / Send Message
    musashidan high dynamic range
    @hazard668 forgot to say thanks for sharing this, mate. Very useful script.
  • fu_films
    Offline / Send Message
    fu_films triangle
    Thanks heaps for this script as well! Total time and lifesaver.
Sign In or Register to comment.