Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

MaxScript Sub Object Rotation/Scale

Hello!
For the past 2 weeks, I have been trying to make a random tool for rotating and scaling my selection in the sub object level.

I manage do make it work for translation but I can't seem to figure out how the rotation or the scaling work for the sub objects.

To bad I can't just change the move to rotate or scale.

Ex: of the move
move $.selectedVerts [XRandom,YRandom,ZRandom]
to
rotate $.selectedVerts [XRandom,YRandom,ZRandom]

Anyone know how to do it?
I would really appreciate the help!

Replies

  • monster
    Offline / Send Message
    monster polycounter
    The rotate and scale command don't work on vertices. If you think about it, verts don't have a rotation/scale property, only a position property. So instead of rotating you need to calculate the rotation/scale and then set the position based on that.

    This code below will move/rotate/scale the verts. There is comments in the code. Let me know if you have any questions.
    1. (
    2. fn transformSubObject obj vertlist subMove:[0,0,0] subRotate:[0,0,0] subScale:[0,0,0] =
    3. (
    4. --Cache poly commands
    5. getVertex = polyOp.getVert
    6. setVertex = polyOp.setVert
    7. --Create a transform matrix from the parameters
    8. translateMatrix = transMatrix subMove * ((eulerAngles subRotate.x subRotate.y subRotate.z) as matrix3) * scaleMatrix subScale
    9. --Move the transform matrix to the object's transform
    10. translateMatrix *= obj.transform
    11. --Move each vertex according to the transform matrix
    12. for v in vertlist do
    13. (
    14. setVertex obj v ((in coordsys obj (getVertex obj v)) * translateMatrix)
    15. )
    16.  
    17. --Update the viewport
    18. redrawViews()
    19. )
    20.  
    21.  
    22. transformSubObject $ (polyOp.getVertSelection $) subScale:[1.1,1.1,1.1]
    23. )
  • teckcloud
    Sorry for the late response.
    First I want to thank you for this code. It is really helping me a lot.
    The move and rotate are working very well.
    I am still havin't issue witht the scale.

    I have look at the code you wrote and there are some lines that I don't exactly know what they do.

    Here are the line:

    translateMatrix = transMatrix subMove * ((eulerAngles subRotate.x subRotate.y subRotate.z) as matrix3) * scaleMatrix subScale

    translateMatrix *= obj.transform

    setVertex obj v ((in coordsys obj (getVertex obj v)) * translateMatrix)

    If you have the time I would really appreciate more detail explaination on those line please.

    Thanks again for the help :)
  • monster
    Offline / Send Message
    monster polycounter
    1. translateMatrix = transMatrix subMove * ((eulerAngles subRotate.x subRotate.y subRotate.z) as matrix3) * scaleMatrix subScale

    This line builds the target transformation matrix from the input parameters. I do it all in one line to minimize code, and maximize confusion. :)

    A transfrom matrix is built from these components: position * rotation * scale

    In order to multiply them together I have to build a matrix from each component. Position and scale are easy.

    transMatrix subMove
    scaleMatrix subScale

    Rotation is a little tricky because I need to pipe the parameter though an eulerAngle before converting to a matrix.

    ((eulerAngles subRotate.x subRotate.y subRotate.z) as matrix3)

    A more readable version of this code would be:
    1. --NEW DEFAULT MATRIX3
    2. translateMatrix = matrix3 1
    3.  
    4. --MOVE THE MATRIX
    5. translateMatrix *= transMatrix subMove
    6.  
    7. --SCALE THE MATRIX
    8. translateMatrix *= scaleMatrix subScale
    9.  
    10. --ROTATE THE MATRIX, I DON'T KNOW WHY rotateMatrix DOESN'T EXIST
    11. translateMatrix *= ((eulerAngles subRotate.x subRotate.y subRotate.z) as matrix3)

    1. translateMatrix *= obj.transform
    This code is simple. It just translates the matrix above to the objects current position/rotation/scale. If you didn't do this your sub objects would rotate/scale from the world origin. This isn't ideal because they use the object's pivot to rotate and scale from. So if your pivot is not centered or you haven't ResetXforms then you may get weird behavior. But it works well enough once you know what's going on.

    More ideal would be to get the center of the sub-object selection, and use the world axis for rotation / scale.
    1. setVertex obj v ((in coordsys obj (getVertex obj v)) * translateMatrix)

    This line of code gets a vertex position relative to the current object (not the world). Then it translates the position of the vertex by the matrix we build above.
    1. I am still havin't issue witht the scale.

    Maybe try ResetXforms as described above.
Sign In or Register to comment.