Script to Planar Map UVs of Each Poly in a Mesh
I'm trying to write a script that will take any random Editable Poly object, apply an Unwrap_UVW modifier, then Quick Planar Map every polygon in the object individually, normalize all these UV-islands relative to each other, and pack them inside a 1-unit UV space without overlap. I'm very close to getting what I want, but Max is throwing an exception in the following code:
print "*************************"; mybox = Box length:10 width:5 height:2; ConvertTo mybox Editable_Poly; polyCount = polyop.getNumFaces mybox; addModifier mybox (Unwrap_UVW()); mybox.Unwrap_UVW.unwrap2.setTVSubObjectMode 3; for i = 1 to polyCount do ( mybox.Unwrap_UVW.unwrap.selectPolygons #{i}; mybox.Unwrap_UVW.unwrap2.unfoldMap 0; ) mybox.Unwrap_UVW.unwrap.selectPolygons #{1..polyCount}; mybox.Unwrap_UVW.unwrap2.pack 1 0.02 true true true;
Can anyone help me out here? This script should run fine, but it's giving me a huge headache. Try running this in Max 2012 and tell me why it doesn't work. Or is Max just buggy with this?
Comments
I think you have to be inside
I think you have to be inside the "modify" panel and you also have to select the box when trying to work on its Unwrap_UVW modifier. So after you've added the modifier you can add this code:
and then it should work, at least it does for me.
Cheers
Never get low & slow & out of ideas
Thanks, that did the
Thanks, that did the trick!
Now all I need is to test for whether an object I'm selecting is a mesh object rather than a camera, spline, or other such object that shouldn't be unwrapped. I have no idea how to test for this. Any clues?
After unwrapping some more
After unwrapping some more models with my script, I notice that using Unfold Map on each face doesn't work well because some long polygons don't get scaled proportionally, resulting in an uneven checker pattern. From what I've tried, a Quick Planar Map on each face is the only technique that gets the perfectly straight results I need, but I cannot get Quick Planar Map to work with MaxScript. The documentation says that the following should work:
But the results are NOT the same as pressing the Quick Planar Map button in the UVW Unwrap modifier with the Mouse. How can I get Quick Planar Map working? Do I have to be in a special mode?
It looks like the
It looks like the "planarMap()" does not use the "Normalize Map" Option, although its checked. But thats just my guess, cause doing it by hand with "Normalize Map" not checked, it looks very similar to what you get with your script.
Have you tried flatten mapping? That might do what you want, if you pack the UVs after flattening:
Never get low & slow & out of ideas