Home Technical Talk

Modo: Pixel Snapping UVs

polycounter lvl 11
Offline / Send Message
jocose polycounter lvl 11
Is there any way to pixel snap your uvs to either the center or corners of a pixel?

It doesn't seam like many people doing NexGen stuff care about this but I know its really important on lower resolution textures when you start editing individual pixels.

Replies

  • Ben Apuna
    Options
    Offline / Send Message
    To accomplish this I've set up a popup form that runs a set of scripts that:

    1. Set the Coordinate Rounding to "Fixed"

    2. Set the Fixed Increment to one of the following values:

    0.125 = My modeling snap setting, I switch to this when not UVing.

    0.03125 = 1 pixel on a 32 x 32 map

    0.015625 = 1 pixel on a 64 x 64 map

    0.0078125 = 1 pixel on a 128 x 128 map

    0.00390625 = 1 pixel on a 256 x 256 map

    0.001953125 = 1 pixel on a 512 x 512 map

    0.0009765625 = 1 pixel on a 1024 x 1024 map

    0.00048828125 = 1 pixel on a 2048 x 2048 map

    0.000244140625 = 1 pixel on a 4096 x 4096 map

    So the first script goes like this:
    #python
    
    lx.eval("pref.value opengl.gridSnap fixed")
    lx.eval("pref.value opengl.gridFixed 0.125")
    
    You can copy that text and paste it into notepad then save as a .py file. Just replace the "0.125" with each of the other values and save as a new script. I'm sure there's a more efficient way to condense this down to one script, but my Python skills aren't that far along yet :poly136:

    The problem is that you must run the script with nothing selected and your mouse pointer hovering over the maximized modeling viewport. For some strange reason it won't work when run in the UV viewport, or with anything selected.

    The main trick is to get one vert to be perfectly aligned with a pixel. To do this I usually just create a Unit Primitives -> Plane in the current mesh and do a Fit UVs on it. That way I have a vert in all four corners of 0-1 UV space. Then I just use Drag Snap Rigid to snap any particular shell to one of the corners. At this point you can use that first shell's vert as a snapping point and delete the Unit Plane or just move the Unit Plane over U - 1 to get it out of the way but keep it handy for snapping purposes.

    Hope that helps :)

    EDIT:

    (From a post over on the Luxology Forums)
    Ben Apuna wrote: »
    The method I posted on Polycount works great for pixel snapping.

    I've used it extensively in my personal work, especially for lightmap UVs for UDK which are typically between 32x32 and 128x128 so every pixel counts.

    Here are the scripts I made and use:

    http://dl.dropbox.com/u/1447878/Scripts/Modo/ModoGridSnapScripts.zip

    Just extract the files and place in your modo scripts directory.

    Then assign the form ba_GridSnap_1 to a hotkey.

    System -> Form Editor -> ba_CustomForms -> ba_GridSnap_1 -> (Right Click) -> Assign to Key...
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    Great thanks a bunch for posting this. I will try it out for my next project.
  • Smoluck
    Options
    Offline / Send Message
    Smoluck polycounter lvl 7
    Hello Ben, i contact you about your script that help defining UV grid to snap uv point to every pixel of our texture 128² to 4096².
    I've seen that if you open the "Snapping Options" and turned on the coordinate rounding to "force fixed" instead of "fixed" you can use the move tool to snap a point to a pixel center just by moving it a little.

    On my 1024² texture i use the 2048 grid to be sure that my uv point was at pixel center.

    so my message is about automatisation of the process to all athe point into a uv map:

    Imagine that you can parse the point indice of a mesh, select them one at a time and move eatch of them just around a defined value like U = V  = (1/1024)*0.8
    where 1/1024 define a pixel snap value for a 1024 texture.

    I'm not a programmer, so please be not offensed by this:

    #Enable the Grid Snap for a 1024² texture (1/1024) and enable coordinate rounding to "Force Fixed"
    #Query vertex indice list of the actualy selected mesh.
    #select vertex n° 1
    #move this UVpoint in UV space by (1/1024)*0.8 on U and V
    #select vertex n° 2
    #etc.... until every vertex (uvpoint) been moved a little to snap to the pixel.

    I hope you understand the purpose of this.





Sign In or Register to comment.