Home Technical Talk

Maxscript - Mirroring and offseting uvs

Hey Guys,

A thing I do manualy when i have objects that will be symmetrical (mirrored uvs) is delete half of it and uv it.

After is just a matter of mirroring the object and offseting the uvs to the right in the unwrap window.

I wanted to automate this, so i made this script:
(
macros.run "Modifiers" "Mirror"
subobjectLevel = 1
modPanel.setCurrentObject $.modifiers[#Mirror]
$.modifiers[#Mirror].copy = on
macros.run "Modifiers" "EditPolyMod"
subobjectLevel = 5
modPanel.addModToSelection (UVW_Xform ()) ui:on
$.modifiers[#UVW_Xform].U_Offset = 1
macros.run "Modifiers" "EditPolyMod"
subobjectLevel = 1
actionMan.executeAction 0 "40021"
max select all
macros.run "Ribbon - Modeling" "EPoly_WeldOptions"
$.modifiers[#Edit_Poly].weldVertexThreshold = 0.01
$.modifiers[#Edit_Poly].Commit ()
)

and behaves like this

https://dl.dropboxusercontent.com/u/93793/Screenshots/2015-09-23_02-25-18.mp4


But, it's a bit hacky.

I was wondering if anyone can comeup with a better way for this?

Cheers!
Pedro

Replies

  • riklopes
    Options
    Offline / Send Message
    riklopes polycounter lvl 12
    what is a symmetrical? is this a cooking forum? im sorry for noob, i will learn fastly!

    Looks great what is your MSN nick for add? Do you have nice photo?
  • kurt_hectic
    Options
    Offline / Send Message
    kurt_hectic polycounter lvl 10
    woot?


    ( ͡° ͜ʖ ͡°)
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Honestly, most of my personal use tool look like yours. But when packaging them for release I typically do a few things.

    1. Make sure they work on a selection objects.
    2. Make as few UI updates as possible.
    3. Add undo context.
    4. Try to get modeling tools to work on EPoly or EditablePoly.
    5. Look for bugs. In your tool if faces were selected before starting, they also become offset.
    6. Make a perf pass. For example, my code below runs in about 140ms. And yours runs in about 560 ms. Because of #2 above.
    (	
    	t = timeStamp()
    	
    	--SWITCH TO MODIFY PANEL AND DISABLE UI
    	max modify mode 
    	windows.sendmessage (windows.getmaxhwnd()) 0x000B 0 1
    				
    	undo "Mirror and Weld" on
    	(
    		try
    		(
    			selObjs = getCurrentSelection()
    			
    			for obj in selObjs do
    			(
    				--CLEAR FACE SELECTION
    				select obj
    				if classof obj == Editable_Poly do PolyOp.setFaceSelection obj #{}
    				if classof obj == PolyMeshObject do EditPolyMod.SetSelection obj.modifiers[1] #Face #{}
    				
    				--MIRROR THE GEO
    				mMod = mirror()
    				mMod.copy = true
    				addModifier obj mMod
    				
    				--ADJUST UVs
    				uvMod = UVW_Xform()
    				uvMod.U_Offset = 1
    				addModifier obj uvMod
    				
    				--WELD
    				vMod = vertexWeld()
    				addModifier obj vMod
    				vMod.threshold = 0.01
    			)
    			
    			select selObjs
    		)
    		catch
    		(
    			format "%\n" getCurrentException()
    		)
    	)
    	
    	--ENABLE UI
    	windows.sendmessage (windows.getmaxhwnd()) 0x000B 1 1
    		
    	format "% ms\n" (timeStamp()-t)
    )
    
  • Pedro Amorim
    Options
    Offline / Send Message
    Dude! Juan! This is TNT!

    Works super fast and on multiple objs and they can even have preselected faces, because it won't matter. It will work nicely as well :)

    Thank you so much!
  • tynew
    Options
    Offline / Send Message
    tynew polycounter lvl 9
    Wait, I thought mirroring the object will cause flipped normals once normal map is applied?
  • Pedro Amorim
    Options
    Offline / Send Message
    In this case, mirroring is just copying the half of the mesh that is uvmaped to the other side. Basically like applying a symmetry to the mesh.
    Plus, you always have to offset the uvs to the side on the mirrored parts or else you will have overlaped uvs and it will cause issues when baking. :)

    For reals. this script is bomb!
  • monster
    Options
    Offline / Send Message
    monster polycounter
    tynew wrote: »
    Wait, I thought mirroring the object will cause flipped normals once normal map is applied?

    The Mirror Tool applies a negative scale to flip your model. This is bad.

    The Mirror Modifier and Symmetry Modifier rebuild the geometry mirrored, this is acceptable.
Sign In or Register to comment.