Home Technical Talk

Max7 script help! View align and bones addition

grand marshal polycounter
Offline / Send Message
pior grand marshal polycounter
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 laugh.gif

Would someone know how to fix that up? Thanks in advance!

Replies

  • FatAssasin
    Offline / Send Message
    FatAssasin polycounter lvl 18
    Unfortunately, there's no "press the View Align" button command. I ran into something similar a while ago. I don't have time right now to give you tha exact code, but I can tell you which two pieces of info you need.

    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.
  • pior
    Offline / Send Message
    pior grand marshal polycounter
    Thanks Fat! So far I found this:

    <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 laugh.gif

    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?
  • Eric Chadwick
    Not sure if this will help or hinder, but... you might be able to get some code from Skin Or Die, which has a bone-adding function. Andre just updated the script and got it back online.
    http://www.scriptspot.com/andrehotz/
  • FatAssasin
    Offline / Send Message
    FatAssasin polycounter lvl 18
    A couple quick questions. What version of Max? Why do you need the bones loaded in a particular order? I'll have a go at this over the weekend.
  • pior
    Offline / Send Message
    pior grand marshal polycounter
    Alright, couple of flash answers :

    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!
  • vahl
    Offline / Send Message
    vahl polycounter lvl 18
    as I said to pior, the bones are added the way maya handles hierarchy (so in maya you just add the skeleton with the origin selected and you are set) but max hadles the hierarchy a bit differently.
    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.
  • FatAssasin
    Offline / Send Message
    FatAssasin polycounter lvl 18
    The bone part is pretty easy. You need to set up an array before hand of all the bones, in the order you want them loaded. So, something like this:

    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.
  • FatAssasin
    Offline / Send Message
    FatAssasin polycounter lvl 18
    For the planar mapping part of your question, this should do if for you:

    <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.
  • pior
    Offline / Send Message
    pior grand marshal polycounter
    this is getting awesomer smile.gif

    I was moving places and had no chance to test all that. I'll do it tonight... Thanks a ton FatA!
  • pior
    Offline / Send Message
    pior grand marshal polycounter
    okay, just tried them both and I think I'm doing something wrong... I can't get either to work :O

    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 smile.gif
  • FatAssasin
    Offline / Send Message
    FatAssasin polycounter lvl 18
    Your _uvviewalign.mcr file is missing a closing parenthesis at the very bottom. Actually, I'll post a more user friendly version of the script with a rollout so that you can set the gizmo size without having to manually edit the file. Plus, I have a new version that uses a function similar to the "Best Align" button in Max 8 so that you don't even have to rotate the view around to get the uv gizmo lined up properly with the selected faces.

    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 />
  • FatAssasin
    Offline / Send Message
    FatAssasin polycounter lvl 18
    Okay, here's the new and improved uv mapping tool. It should save a lot of time for you. You don't even have to rotate the view around while you're mapping, it will align the uv gizmo to the average normal of the selected faces automatically. Use the "Gizmo Size" spinner to set the size you want for the gizmo. Then just keep selecting faces and clicking the "DO IT!" button.

    <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 />
  • pior
    Offline / Send Message
    pior grand marshal polycounter
    Haha thats awesome! The previous version worked like a charm but hell, thanks a ton, I'll test that new version NOW!

    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
  • FatAssasin
    Offline / Send Message
    FatAssasin polycounter lvl 18
    Do you have the character mesh selected when you run the script? The "$" sign means to operate on the selected object, so if nothing is selected it returns "undefined".
  • pior
    Offline / Send Message
    pior grand marshal polycounter
    Haha nevermind! I was trying to use it on a model without the skin modifier on it. It works wonders now!

    Awesome help man! I'll recontact you if anything else is needed wink.gif Cheers
  • diZzyWalnut
    Offline / Send Message
    diZzyWalnut polycounter lvl 18
    What do You cooking Pior ?
    (q4 export ? ....yes please poly106.gif )

    good luck
Sign In or Register to comment.