Announcement

Collapse
No announcement yet.

Helping a hopeless maxscripting guy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Helping a hopeless maxscripting guy

    Hello,
    I'll need some help with this from the experts out there. I was looking for a way to realign the bounding box of an object to his main "physical" axis (for example as it looks when rotating a primitive box, so the bbox stick together) and I found this thread on cgtalk:

    http://forums.cgsociety.org/showthre...ght=align+axis

    There is a couple of pieces of code but I don't know how to apply in my objects. Could be that code easily converted in "button like" or "run script" action?
    I must admit my ignorance here.

    Thanks!
    Manuel
    Attached Files
    Last edited by mmrender; 20-11-2008, 08:43 AM. Reason: edited: wrong link, sorry. Now work

  • #2
    Hi manuel,
    you can use reset XForm utility for this,
    or if you wanna to use script code, just open it in max script window, select all
    and simple drag text to your main toolbar, it creates button.
    hope it helps
    filip

    Comment


    • #3
      Thanks Filip for the info. Unfortunately I couldn't work it out.
      Draggin code tex to create a button is a killler tip, but when I try to execute the code I get a maxscrip error that I don't know how to rewrite.
      The Xform utility here doesn't work as far as I know, because the objects aren't primitives but detached elements from a big mesh.

      Comment


      • #4
        I wish this was around for none-poly models. I've got nPower and would like to keep them as bReps.
        Lots of times I have a door that comes in already open to an unspecified angle. It's pretty much rectangular so I wouldn't think it to be hard to have a script automatically align to the smallest fitting bounding box. That would make applying UV maps much easier to those objects. I've gotta always rotate those UV maps. I'd rather use the same UV maps for both doors and the body, assuming those are the same texture/material.
        Rotating the pivot/bounding box would allow me to do that.

        Anyone know if that script is reasonably possible from right within max? If so, maybe I'll go and try to create it. I think it might be far beyond my scripting skills though. It takes me forever because I usually don't even know what commands are possible and the help file isn't always helpful.

        Comment


        • #5
          Bobo's got a solution LOL, i guess you already saw that though...

          http://forums.cgsociety.org/showthre...ght=align+axis
          Last edited by jrandom; 24-11-2008, 01:14 PM.
          particle makes perfect

          Comment


          • #6
            hmm, I'm getting an error with that code.

            I just have to add, do [theFunctionName] at the end of all that to run it right?

            Comment


            • #7
              Evaluate the code...IE:example (you can either C/P this to a new script or C/P in the macrorecorder pane of the listener, select all the text from the top down and hit numpad+enter to run)
              Code:
              fn AlignBBoxToFirstNormal theObject = (
               theCurrentTM = theObject.transform
               theMesh = snapshotasmesh theObject
               theZ = normalize (getFaceNormal theMesh 1)
               theFace = getFace theMesh 1
               theY = normalize ((getVert theMesh theFace.y)-(getVert theMesh theFace.x))
               theX = normalize (cross theY theZ)
               theTM = matrix3 theX theY theZ theCurrentTM.row4
               theObject.transform *= inverse theTM
               resetXForm theObject
               convertToMesh theObject
               theObject.transform = theTM
                )
              then select object

              run the function in the listener "AlignBBoxToFirstNormal $" (without quotes)

              I tested with a box rotated 20 degrees on Z-axis then utilities reset X-form to align the bounding box back to world space. Then I ran the function and the bounding box realigns to the box.
              Last edited by jrandom; 24-11-2008, 12:21 PM.
              particle makes perfect

              Comment


              • #8
                Hi, I've also try that code without success. Could somebody more experience check it out and give us a tip?

                Edit: Sorry, I send my message at the same time that your example. I'll try it
                Last edited by mmrender; 24-11-2008, 12:18 PM.

                Comment


                • #9
                  ok, well, that Was simple in getting the script to run, only....it didn't move the pivot at all. All it seemed to do was convert my part to editable mesh, which is Totally not what I wanted.

                  I'm sure if that was a limitation it wouldn't be too hard just to have it duplicate to a new part, convert the new part to editable mesh, align that one, then use that information on the first part, and delete the new part. Terrible sentence. haha
                  But I can't get it to even move the pivot at all. And by move I really mean rotate. i don't care if it moves or not other than rotation, but itsn't that really suppose to rotate the pivot so the bounding box is rotated to what the part should really be? I think that's what we are all looking for.

                  I'm testing it on a cylindrical shape though, so maybe that's the problem, however it should probably work on most anything, right?

                  Comment


                  • #10
                    The reset xform should realign the pivot. that is strange. Did it realign the bounbing box?

                    As for it not working maybe try the first piece of code: (this one works with a cylinder as the first did not)
                    Code:
                    fn AlignBBoxToFirstNormal theObject = 
                      (
                      theCurrentTM = theObject.transform --this is the current transformation
                      theMesh = snapshotasmesh theObject --get the world space TriMesh
                      theTM = matrixFromNormal (getFaceNormal theMesh 1) --build a matrix from normal
                      delete theMesh --delete the TriMesh from memory
                       theTM.row4 = theCurrentTM.row4 --set the position of the new matrix to the old pos
                      theObject.transform *= inverse theTM --transform out of world space 
                      resetXForm theObject --reset the XForm
                      convertToMesh theObject --collapse the stack
                      theObject.transform = theTM --transform back into world space
                      )
                    I guess the bounding box alignment really depends on the topography of the node and how you want it to translate. As it is the pivot should be aligned with the bbox.
                    particle makes perfect

                    Comment


                    • #11
                      OK, yeah, that worked. Only, for odd shapes it doesn't really do what you would want it to do.

                      I'd still like something that chose the absolute smallest bounding box, not one based off of a certain face. I'm not exactly sure how this one works. The box Did get smaller, a little, but it could have been much smaller.

                      Comment


                      • #12
                        Is there a rogue vertex anywhere that may be keeping it from conforming tighter to the object? I speak for myself, I have done that more often than I care to admit

                        Otherwise it must just be the shape. The script, as far as I can tell, only reads the one face to get the transform matrix so it knows how to realign the bbox to world space.
                        particle makes perfect

                        Comment


                        • #13
                          yeah, I wanted to test it out so I used a bit of a squigly shape. I grabbed a hose from an engineering part that has 2 bends in it.
                          Even in rhino i have to do it manually by chosing 3 points to align through.
                          That works Really close though. Although, I can't translate that info to Max, so it doesn't help.

                          Comment


                          • #14
                            Hi Jrandom, I try the first piece of code that you sent, following your instructions and it is working for me perfectly. I was applying it to a cilinders with no problem. Only, I would need to apply to several objects at the same time, could you help me on that? I suposse it is a matter of add a line in the code but I'm very poor with this issue. Many thanks, you make my day.

                            Comment


                            • #15
                              Andrew, I don't exactly follow what you want but maybe the Soulburn scrips from Neil Blevins could help you. There is a tool included that is able to align the axis of the object in many pre-stablished (I think 27) positions with just one click. Maybe you know these already, anyway I put here the link
                              http://www.neilblevins.com/soulburns...urnscripts.htm

                              from his web: "putPivot. Places the pivot of the selected objects in one of 27 spots such as center, bottom, top, high left side, etc"

                              Regards

                              Comment

                              Working...