Home Technical Talk

Moving uv's to 0-1 space in 3DS Max

Currently have a problem with uvs inside 3ds Max when importing models made and textured inside google sketchup.

The problem with sketchup is that it does not keep uv position centered to the o-1 tile space. This places uvs in any random tile which makes it very hard to manage. Unity3D also has a problem where any uvs placed very far from 0-1 tile produce uv artifacts when the mesh statically batched.

I need a tool that moves the uvs to the 0-1 uv tile but still retain their relative positions.

Someone already posted about a tool which does exactly what I need but it only works for maya.
http://www.polycount.com/forum/showthread.php?t=70380

Replies

  • wes.sau
    Easy, here's a quick bare-bones maxscript I whipped up in 15 mins to do that, but I currently have no time to support it - it has no error catching like if you forgot to select the mesh or automatic poly to mesh conversion, etc.

    Make sure your mesh is an editable mesh (not editable poly), and select just the single mesh, then copy paste this below into a new maxscript in the Maxscript Editor and press control+E to run:
    1. function f_ZeroToOne num =
    2. (
    3. a = floor num
    4. b = num - a
    5. )
    6. if (classof $ == editable_Mesh) do
    7. (
    8. local mapChan
    9. local obj = $
    10. /* You can change the 1 to the desired UV map channel. */
    11. local numTverts = meshop.getNumMapVerts obj 1
    12. for t = 1 to numTverts do
    13. (
    14. local Tvert = meshop.getMapVert obj 1 t
    15. local newTvert = [(f_ZeroToOne Tvert.x),( f_ZeroToOne Tvert.y),0]
    16. meshop.setMapVert obj 1 t newTvert
    17. )
    18. update obj
    19. )
    Also be sure to save the max script somewhere.
  • Rycon
    Thank you very much for your support but unfortunately when I run the script, the uv's get messed up.

    Below is a screenshot showing what happens before and after the script was run:

    gY5n6dV.png

    Would it be possible to center the UVs without scaling them? If they are larger then the 0-1 UV island, just center to it without scaling them down to fit.


    I am also willing to buy any plugins or scripts available that would support this functionality.
  • Ojah
    Offline / Send Message
    Ojah polycounter lvl 12
    Made this some time ago, not exactly what you want as the movement needs to be done by hand, but perhaps it helps. It requires a face selection in an unwrap modifier.

    edit: added a center button to move the selection by whole units to have its midpoint in the 0-1 range
    1. -- move uv's
    2. fn F_moveUV movePos = (
    3. if selection.count == 1 do
    4. (
    5. obj = selection[1]
    6. if obj.modifiers.count > 0 do
    7. (
    8. if classof obj.modifiers[1] == Unwrap_UVW do
    9. (
    10. objMod = obj.modifiers[1]
    11. objMod.faceToVertSelect()
    12. vArray = objMod.getSelectedVertices()
    13. for vVar in vArray do
    14. (
    15. if movePos == "C" do
    16. (
    17. local oldSub = subobjectlevel
    18. subobjectlevel = 3
    19. midPos = objMod.getSelCenter()
    20. print midPos
    21. movePos = [-(floor midPos.x), -(floor midPos.y), 0]
    22. subobjectlevel = oldSub
    23. )
    24. oldPos = objMod.getVertexPosition 0 vVar
    25. objMod.setVertexPosition 0 vVar (oldPos + movePos)
    26. )
    27. )
    28. )
    29. )
    30. )
    31.  
    32. fn F_scaleUV scaleFactor divideBool = (
    33. if selection.count == 1 do
    34. (
    35. obj = selection[1]
    36. if obj.modifiers.count > 0 do
    37. (
    38. if classof obj.modifiers[1] == Unwrap_UVW do
    39. (
    40. objMod = obj.modifiers[1]
    41. objMod.faceToVertSelect()
    42. vArray = objMod.getSelectedVertices()
    43. for vVar in vArray do
    44. (
    45. updPos = objMod.getVertexPosition 0 vVar
    46. if divideBool then
    47. (
    48. updPos.x = updPos.x / scaleFactor.x
    49. updPos.y = updPos.y / scaleFactor.y
    50. )
    51. else
    52. (
    53. updPos.x = updPos.x * scaleFactor.x
    54. updPos.y = updPos.y * scaleFactor.y
    55. )
    56. objMod.setVertexPosition 0 vVar updPos
    57. )
    58. )
    59. )
    60. )
    61. )
    62.  
    63.  
    64. rollout moveUVRollout "UV"
    65. (
    66. button btnUp "U" width:30 height:30 pos:[35,5]
    67. button btnLeft "L" width:30 height:30 pos:[5,35]
    68. button btnRight "R" width:30 height:30 pos:[65,35]
    69. button btnDown "D" width:30 height:30 pos:[35,65]
    70. button btnCenter "C" width:30 height:30 pos:[35,35]
    71. button btnScale12H "1/2 H" width:42 height:25 pos:[5,105]
    72. button btnScale13H "1/3 H" width:42 height:25 pos:[5,135]
    73. button btnScale15H "1/5 H" width:42 height:25 pos:[5,165]
    74. button btnScale12V "1/2 V" width:43 height:25 pos:[52,105]
    75. button btnScale13V "1/3 V" width:43 height:25 pos:[52,135]
    76. button btnScale15V "1/5 V" width:43 height:25 pos:[52,165]
    77. button btnScale2H "2 H" width:42 height:25 pos:[5,195]
    78. button btnScale3H "3 H" width:42 height:25 pos:[5,225]
    79. button btnScale5H "5 H" width:42 height:25 pos:[5,255]
    80. button btnScale2V "2 V" width:43 height:25 pos:[52,195]
    81. button btnScale3V "3 V" width:43 height:25 pos:[52,225]
    82. button btnScale5V "5 V" width:43 height:25 pos:[52,255]
    83. on btnUp pressed do ( F_moveUV [0,1,0] )
    84. on btnLeft pressed do ( F_moveUV [-1,0,0] )
    85. on btnRight pressed do ( F_moveUV [1,0,0] )
    86. on btnDown pressed do ( F_moveUV [0,-1,0] )
    87. on btnCenter pressed do ( F_moveUV "C" )
    88. on btnScale12H pressed do ( F_scaleUV [2,1] true)
    89. on btnScale13H pressed do ( F_scaleUV [3,1] true )
    90. on btnScale15H pressed do ( F_scaleUV [5,1] true )
    91. on btnScale12V pressed do ( F_scaleUV [1,2] true )
    92. on btnScale13V pressed do ( F_scaleUV [1,3] true )
    93. on btnScale15V pressed do ( F_scaleUV [1,5] true )
    94. on btnScale2H pressed do ( F_scaleUV [2,1] false )
    95. on btnScale3H pressed do ( F_scaleUV [3,1] false )
    96. on btnScale5H pressed do ( F_scaleUV [5,1] false )
    97. on btnScale2V pressed do ( F_scaleUV [1,2] false )
    98. on btnScale3V pressed do ( F_scaleUV [1,3] false )
    99. on btnScale5V pressed do ( F_scaleUV [1,5] false )
    100. )
    101. createdialog moveUVRollout 100 285
  • Joost
    Offline / Send Message
    Joost polycount sponsor
    The crop tool in TexTools might be what you're after. http://www.renderhjs.net/textools/
  • wildrun

    the initial script works perfectly for me, it would be possible to add a material id to each udim, it would be perfect to have everything automatically in a multimaterial?

Sign In or Register to comment.