Move a face using maya.cmds xform

408 views
Skip to first unread message

Lidia Martinez

unread,
Feb 23, 2015, 3:03:07 PM2/23/15
to python_in...@googlegroups.com

I'm creating some poly figures and calculating the "Frenet" matrix (normal + binormal + tangent + position) of the curve. All of them are queried using curves functions. The binormal as a cross product between tangent and normal. That's ok and the pieces are placed in the correct places along the curve.

But if i try to extrude a figure, and select the new face, and position it in each point of the curve using the same matrix (i know, i could use the automatic recipe, but i need to do it by hand) the face selected to be moved along the curve to the next position is not moved, but it's vertices moved all to the curve, collapsing the face. 

I thought i could move it using xform, but it doesn't work at all. I tried many ways to do it. Creating a cluster with the vertices and moving it would be the last option (and i don't think i could rotate it...). 

It's funny, if i try to just rotate with the rotation part of the matrix, it works but accumulates the rotations (each time rotates a little more) , and doesn't collapse it. If i move it, it works too, but collapses the face.


Weird stuff i'll have to do if i just want to move a face using a transformation matrix... just that...

--
Lidia

Lidia Martinez

unread,
Feb 28, 2015, 12:59:55 PM2/28/15
to python_in...@googlegroups.com
Hi people. 

I found this post i wrote some time ago. The question was quite mathematical.  I 've rewritten it so it's more comprehensible and with updated solutions. I really need help with this.

-------------------

How can i modify a polygonal face with xform command, using a transformation matrix, without making it collapse all its vertices to the position i tell it ?

IT makes every vertex to be positioned in the same place. I just want to move it after an extrude, but extrude command doesn't allow to pass a transform matrix to move it, so i first extrude, then i move it with xform...

One solution is to extract the rotation and position from the matrix and apply it to the extrude action ( i wonder which local or global transform or what should i use, and how to extract rotation in every axis from there... i should search for that ).

Other solution is ... to move... every vertex and calculate locally the offset from the center of the face to each corner... wow. That sounds really annoying, considering you can move a face and rotate it on Maya. Why could't i just position all face vertices the same way moving the face itself (i know the face is formed by those vertices, and it has no pivot... theoretically).

How would you solve this?


--
Lidia

Marcus Ottosson

unread,
Feb 28, 2015, 1:23:52 PM2/28/15
to python_in...@googlegroups.com

It almost sounds like you’d be better off not using maya.cmds but rather the Python API; it’ll probably give you an easier time with matrices and arbitrary transformations of vertices. I’m not terribly acquainted with it however, and won’t be able to give you much practical advice.​ :S

Maybe this would help?

Otherwise, maybe there’s someone else on the list with more experience in this area. Good luck!

Best,
Marcus

Lidia Martinez

unread,
Mar 1, 2015, 2:44:05 PM3/1/15
to python_in...@googlegroups.com
Yeah. I understood Maya.Cmds has a lot of caveats.

Oh, and i found a huge bug on maya.cmds . Well, i found several ones, including that crossProduct or dotProduct (don't remember which one) in MEL casts to INT any value passed if you pass the value itself, not a variable..., funny thing. The workaround,set a variable, pass it instead. LOL). 

The big bug is this one: XFORM command works on component space instead of world Space, ignoring completely worldSpace flag. worldSpace gets ignored several times. In this case, if you use xform on any component or group of components, it ignores the flag.And it is surprising, could be easier this way, but what i had to do is generate an inverse matrix (using normal python, not numPy (i have my reasons)) from the last step of the extrude position, and apply it to the new transformation matrix, so it converts the tranfsormation matrix (world space) itself into a relative transf. matrix, just for this step in the curve. So it contains JUST the transformation between the step before extruding, and the new position. 

Sucks...

But now it works. I can see the elements following the path of the curve. So xform works. Doesn't collapse things, but i can't give it worlspace transformations... which sucks anyway...



Oh! And something else. As i am using the normal vector given by pointOnCurve to construct the Frenet matrix (NBTP) from the bezier curve, it swaps sometimes, so it makes huge twists on the tube i generate. This is related to the also known f** Gimbal Lock for animators. Those twists are related to the fact that it is constructed using euler maths, not quaternions. This sucks too, bezier allways gives those problems. A workaround for this is to use the up vector of the world, projected into the plane generated by the tangent vector, which is always correct.This way, the normal is always perpendicular to tangent, and is allways pointing to the same direction or near it. This removes those twists and works perfectly. :-)


Thanks everybody, hope this is useful for somebody!




--
Lidia

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCo2quq-ib%3DtUR-X2UKz5d31VDETfV%2BvczmqVP1Xw%2BO3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Mar 1, 2015, 4:33:28 PM3/1/15
to python_in...@googlegroups.com
Well, maya.cmds is really nothing more than packaged-up scripts that perform some quite targeted actions; mainly those performed by the GUI which is (I think) it's prime purpose for being. Like creating a few nodes, hooking them up in the correct order and setting some initial values.

For more custom/low-level things, it's probably always a better idea to use what the scripts in maya.cmds is built out of; which is the API.
Reply all
Reply to author
Forward
0 new messages