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
This code below will move/rotate/scale the verts. There is comments in the code. Let me know if you have any questions.
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
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:
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.
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.
Maybe try ResetXforms as described above.