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:
      
     
    function f_ZeroToOne num =
    (
     a = floor num
     b = num - a
    )
     if (classof $ == editable_Mesh) do
    (
     local mapChan
     local obj = $
     
     /*  You can change the 1 to the desired UV map channel. */
     local numTverts = meshop.getNumMapVerts obj 1
     
     for t = 1 to numTverts do
     (
      local Tvert = meshop.getMapVert obj 1 t
      
      local newTvert = [(f_ZeroToOne Tvert.x),( f_ZeroToOne Tvert.y),0]
      
      meshop.setMapVert obj 1 t newTvert
     )
     update obj
    )
     
     
    
    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
    -- move uv's
    fn F_moveUV movePos = (
    	if selection.count == 1 do
    	(
    		obj = selection[1]
    		if obj.modifiers.count > 0 do
    		(
    			if classof obj.modifiers[1] == Unwrap_UVW do
    			(
    				objMod = obj.modifiers[1]
    				objMod.faceToVertSelect() 
    				vArray = objMod.getSelectedVertices()
    				for vVar in vArray do
    				(
    					if movePos == "C" do
    					(
    						local oldSub = subobjectlevel
    						subobjectlevel = 3
    						midPos = objMod.getSelCenter()
    						print midPos
    						movePos = [-(floor midPos.x), -(floor midPos.y), 0]
    						subobjectlevel = oldSub
    					)
    					
    					oldPos = objMod.getVertexPosition 0 vVar
    					objMod.setVertexPosition 0 vVar (oldPos + movePos)
    				)
    			)
    		)
    	)
    )
    
    fn F_scaleUV scaleFactor divideBool = (
    	if selection.count == 1 do
    	(
    		obj = selection[1]
    		if obj.modifiers.count > 0 do
    		(
    			if classof obj.modifiers[1] == Unwrap_UVW do
    			(
    				objMod = obj.modifiers[1]
    				objMod.faceToVertSelect() 
    				vArray = objMod.getSelectedVertices()
    				for vVar in vArray do
    				(
    					updPos = objMod.getVertexPosition 0 vVar
    					
    					if divideBool then
    					(
    						updPos.x = updPos.x / scaleFactor.x
    						updPos.y = updPos.y / scaleFactor.y
    					)
    					else
    					(
    						updPos.x = updPos.x * scaleFactor.x
    						updPos.y = updPos.y * scaleFactor.y
    					)
    					
    					objMod.setVertexPosition 0 vVar updPos
    				)
    			)
    		)
    	)
    )
    
    
    rollout moveUVRollout "UV"
    (
    	button btnUp "U" width:30 height:30 pos:[35,5]
    	button btnLeft "L" width:30 height:30 pos:[5,35]
    	button btnRight "R" width:30 height:30 pos:[65,35]
    	button btnDown "D" width:30 height:30 pos:[35,65]
    	button btnCenter "C" width:30 height:30 pos:[35,35]
    	
    	button btnScale12H "1/2 H" width:42 height:25 pos:[5,105]
    	button btnScale13H "1/3 H" width:42 height:25 pos:[5,135]
    	button btnScale15H "1/5 H" width:42 height:25 pos:[5,165]
    	button btnScale12V "1/2 V" width:43 height:25 pos:[52,105]
    	button btnScale13V "1/3 V" width:43 height:25 pos:[52,135]
    	button btnScale15V "1/5 V" width:43 height:25 pos:[52,165]
    	
    	button btnScale2H "2 H" width:42 height:25 pos:[5,195]
    	button btnScale3H "3 H" width:42 height:25 pos:[5,225]
    	button btnScale5H "5 H" width:42 height:25 pos:[5,255]
    	button btnScale2V "2 V" width:43 height:25 pos:[52,195]
    	button btnScale3V "3 V" width:43 height:25 pos:[52,225]
    	button btnScale5V "5 V" width:43 height:25 pos:[52,255]
    	
    	on btnUp pressed do ( F_moveUV [0,1,0] )
    	on btnLeft pressed do ( F_moveUV [-1,0,0] )
    	on btnRight pressed do ( F_moveUV [1,0,0] )
    	on btnDown pressed do ( F_moveUV [0,-1,0] )
    	
    	on btnCenter pressed do ( F_moveUV "C" )
    	
    	on btnScale12H pressed do ( F_scaleUV [2,1] true)
    	on btnScale13H pressed do ( F_scaleUV [3,1] true )
    	on btnScale15H pressed do ( F_scaleUV [5,1] true )
    	on btnScale12V pressed do ( F_scaleUV [1,2] true )
    	on btnScale13V pressed do ( F_scaleUV [1,3] true )
    	on btnScale15V pressed do ( F_scaleUV [1,5] true )
    	
    	on btnScale2H pressed do ( F_scaleUV [2,1] false )
    	on btnScale3H pressed do ( F_scaleUV [3,1] false  )
    	on btnScale5H pressed do ( F_scaleUV [5,1] false  )
    	on btnScale2V pressed do ( F_scaleUV [1,2] false  )
    	on btnScale3V pressed do ( F_scaleUV [1,3] false  )
    	on btnScale5V pressed do ( F_scaleUV [1,5] false  )
    	
    )
    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.