Hi
I've been trying to put together a small bit of maxscript but ran into a wall.
I want to automate a simple process. Once some faces are selected, I need too :
>add a UVmap modifier
>apply Planar Map
>perform a view align
>set the UV plane size to a defined number
>convert back to epoly
>go to faces submode
>hide the previously selected faces
I like to UV things this way for complex shape that wont behave well if relaxed/pelt mapped : I simply planarmap a bit vith viewalign, rotate, planarmap the next bit and stitch everything later on. Really handy in some cases.
The issue is, the listener dosen't seem to be able to record the 'view align' bit. Yet I'm sure the viewer perspective info is stored somewhere... I just don't know how/where to find it, and don't know how to link that info to the UV gizmo.
Here is where I am at :
<font class="small">Code:</font><hr /><pre>
macroScript UVplanarhide category:"Piorscripts"
(
modPanel.addModToSelection (Uvwmap ()) ui:on
$.modifiers[#UVW_Mapping].maptype = 0
$.modifiers[#UVW_Mapping].length = 39.3701
$.modifiers[#UVW_Mapping].width = 39.3701
-- UV VIEW ALIGN SHOULD BE HERE
modPanel.addModToSelection (Unwrap_UVW ()) ui:on
macros.run "Modifier Stack" "Convert_to_Poly"
subobjectLevel = 4
$.EditablePoly.Hide
#Face
)
</pre><hr />
I guess one workaround would be to create a camera aligned from the pers viewport (there is an option for that right?), then make the PlanarUV Gizmo look at it, and go from here... But that's a bit dirty
Would someone know how to fix that up? Thanks in advance!
Replies
1) Look up "How do I align the UVW_Modifier's Gizmo to a selected face?" in the FAQ. Bobo wrote this in response to a question I had a couple years ago.
2) Look up "viewport" in the index and scroll down to the "getViewDirectionRay" function example.
These two pieces of info should get you where you want to go. What you need to do is the the transform matrix of the current view (from item 2), and use that for the gizmo (in item 1).
Hope that helps. If you need, and I get some time, I'll script it up for you.
<Uvwmap.Gizmo>.rotation Quat default: (quat 0 0 -1 0) -- animatable
The rotation of the UVWmap gizmo.
Which I guess should allow to enter a quaternion angle value as a angle transformation for the UVWmap gizmo.
And also this:
viewport.getTM()
Which outputs the viewport angle in the form that follows:
(matrix3 [0.707107,0.353553,-0.612372] [-0.707107,0.353553,-0.612372] [0,0.866025,0.5] [0,0,-250])
Now if I ever could link those together... I'm sure there is a simple way to do so (inverting some of the viewport matrix components and inputting that as a gizmo transform rotation to make it point at the view normal), but just don't know how to do that... :O
I'd really appreciate any input on how to add this to the code.
- - - - - - - - - - - -
I have yet another question. I was adding bones to a mesh with a skin modifier on it. The bones (q4 ones!) are to be added in a precise order and there are 65 of them. I was wondering how to do that automatically.
Looking a the listener I put this together :
<font class="small">Code:</font><hr /><pre>
modPanel.addModToSelection (Skin ())
skinOps.addBone $.modifiers[#Skin] $origin 1
skinOps.addBone $.modifiers[#Skin] $body 1
skinOps.addBone $.modifiers[#Skin] $SPINNER 1
</pre><hr />
And the list goes on
If I input one line and hit enter, it works just fine. But if have have more than two at a time only the last one is executed. I know this is a very trivial problem to solve but I just don't know what separator to put between two lines I want both to be executed. I'm a complete noob at this yet begin to understand the use of these little homemade scripts.
Any help?
http://www.scriptspot.com/andrehotz/
I'm running max7 / and the reason why I need the bones in such an order is because of the resulting exported MD5 might be wrong if not done that way... Stupid thing is that the bone order is very close to the actual hierarchy order, but not exactly :O
Hope that helps, thanks in advance!
the md5 assigns numbers to bones function of their position in the hierarchy, these numbers are used to assign vertex but also to put anims on them, so if one number is wrong, the animation will be assigned to another bone, which ends with heavy distortions and such.
hopefully, parts of the hierarchy are in the right order, so in fact you have to add the bones by group of correct hierarchy, which can take some time.
boneArr = #($boneName01,$boneName02,$boneName03,etc...)
If the bone's name has spaces in it use $'bone name'. Note the single quote marks. And make sure to always put the dollar sign before the name. Then:
for b in boneArr do (skinOps.addBone $.modifiers[#Skin] b 1)
If your bones are always named the same, you can reuse the same code in every scene.
<font class="small">Code:</font><hr /><pre>gizmoSize = 39.3701
obj = selection[1]
if obj != undefined then (
uvMod = uvwmap()
modPanel.addModToSelection uvMod
uvMod.length = gizmoSize
uvMod.width = gizmoSize
uvTM = uvMod.gizmo.transform
uvPos = uvMod.gizmo.position
viewTM = inverse(getViewTM())
uvTM.row1 = -viewTM.row1
uvTM.row2 = -viewTM.row2
uvTM.row3 = viewTM.row3
uvMod.gizmo.transform = uvTM * inverse(obj.transform)
uvMod.gizmo.position = uvPos
collapseStack obj
subObjectLevel = 4
if classOf obj == editable_poly then obj.editablePoly.hide #face
if classOf obj == editable_mesh then meshops.hide obj
)</pre><hr />
Change the "gizmoSize" parameter to whatever you need it to be.
I was moving places and had no chance to test all that. I'll do it tonight... Thanks a ton FatA!
Here is a zip with the temp scripts and max7 files to test em with :
www.pioroberson.com/files/pior_fat_scripttests.zip
Thanks in advance
And for the _q4bonesorder.mcr file, you have " 1" after each of the bone names, so it can't find the objects.
Try this:
<font class="small">Code:</font><hr /><pre>macroScript Q4BonesOrder category:"PiorFatA"
(
boneArr = #($'origin',$'body',$'SPINNER',$'waist',$'chest',$'shoulder.s',$'l_clavicle',$'l_up_arm',$'l_elbo',$'l_elbo_tweak',$'l_forarm',$'l_wrist',$'l_index_01',$'l_index_02',$'l_index_03',$'l_ring_01',$'l_ring_02',$'l_ring_03',$'l_thumb_00',$'l_thumb_01',$'l_thumb_02',$'l_thumb_03',$'l_forarm_mp',$'neckcontrol',$'legs_channel',$'head_channel',$'r_clavicle',$'r_up_arm',$'r_elbo',$'r_elbo_tweak',$'r_forarm',$'r_wrist',$'DMG_ATTACHER',$'GNT_ATTACHER',$'GN_ATTACHER',$'HB_ATTACHER',$'LG_ATTACHER',$'MG_ATTACHER',$'NG_ATTACHER',$'PST_ATTACHER',$'RG_ATTACHER',$'RKT_ATTACHER',$'SG_ATTACHER',$'r_index_01',$'r_index_02',$'r_index_03',$'r_ring_01',$'r_ring_02',$'r_ring_03',$'r_thumb_00',$'r_thumb_01',$'r_thumb_02',$'r_thumb_03',$'r_forarm_mp',$'hips',$'l_upleg',$'l_loleg',$'l_ankle',$'l_ball',$'l_toe',$'r_upleg',$'r_loleg',$'r_ankle',$'r_ball',$'r_toe')
for b in boneArr do (skinOps.addBone $.modifiers[#Skin] b 1)
)</pre><hr />
<font class="small">Code:</font><hr /><pre>macroScript autoPlanarMap
category:"HaywoodTools"
toolTip:"Auto Planar Map"
buttonText:"autoPlanarMap"
(
rollout autoPlanarRLT "Auto Planar Map" (
spinner gizmoSizeSPNR "Gizmo Size:" range:[0,9999999,1]
button doTheMapBTN "DO IT!" width:125 height:35
on doTheMapBTN pressed do (
local gizmoSize = gizmoSizeSPNR.value
local obj = selection[1]
local faceArr = getFaceSelection obj
if obj != undefined and faceArr.numberSet > 0 do (
-- create matrix to use for uv gizmo transform
local n = [0,0,0]
for i in faceArr do (n += (getFaceNormal obj.mesh i))
local avgNormal = normalize n
local worldUpVector = (inverse(obj.transform)).row3
local rightVector = normalize (cross worldUpVector avgNormal)
local upVector = normalize (cross rightVector avgNormal)
local theMatrix = matrix3 -rightVector upVector avgNormal [0,0,0]
-- add the uv map modifier and apply the new transform matrix to the gizmo
local uvMod = uvwmap()
modPanel.addModToSelection uvMod
uvMod.length = gizmoSize
uvMod.width = gizmoSize
uvMod.gizmo.transform = theMatrix
-- finish up
collapseStack obj
subObjectLevel = 4
if classOf obj == editable_poly then obj.editablePoly.hide #face
if classOf obj == editable_mesh then meshops.hide obj
)
) -- end button
) -- end rollout
createDialog autoPlanarRLT width:150 pos:[40,80]
)-- end macroscript</pre><hr />
As for the Q4bones I'm still getting an error :
-- Unable to convert: undefined to type: Modifier
Any idea? I'm such a noob!
http://www.pioroberson.com/files/_q4bonesorder.mcr
Awesome help man! I'll recontact you if anything else is needed Cheers
(q4 export ? ....yes please )
good luck