Maya 2018, python, move and rotate extracted face

限于喜欢 提交于 2019-12-25 01:32:43

问题


Trying to write part of the python code in Maya to extract the face from object then move it and rotate it. I tried parameters of polyChipOff itself, tried xform and move and rotate functions. Problem is the same. If rotation is after translation face rotates against the previous position not the current one.

Am I understand some concepts completely wrong?

Code below shows the problem. Simply create a pCube and start the script. From my perspective this code should move face away and then rotate around itself many times. Instead it rotates in a circle with a center in where the face was before move command.

from maya import cmds    

face1 = 'pCube1.f[1]'
cmds.select(face1)
cmds.polyChipOff(dup=True)
cmds.move(2, 2, 0, r=True, os=True, dph=True)
cmds.rotate(0,0,10, a=True, os=True, dph=True)
for i in range (35):
    cmds.polyChipOff(dup=True)
    cmds.rotate(0,0,10, a=True, os=True, dph=True)

回答1:


In your example, the face is rotated not around its previous position but around the object pivot (you can try to move the object pivot before executing your script and see the rotation center changes).

If you want another pivot you'll need to specify it as an argument. I am not sure what center you want to rotate the faces around so I've just specified (2, 2, 0):

from maya import cmds    

face1 = 'pCube1.f[1]'
cmds.select(face1)
cmds.polyChipOff(duplicate=True)
cmds.move(2, 2, 0, relative=True, objectSpace=True)
rotation_pivot = [2, 2, 0]
cmds.rotate(0, 0, 10, relative=True, pivot=rotation_pivot)
for i in range (35):
    cmds.polyChipOff(duplicate=True)
    cmds.rotate(0, 0, 10, relative=True, pivot=rotation_pivot)

Update: If you need to rotate faces around their own center then it's just componentSpace=True as you've mentioned. So the code looks like this:

from maya import cmds    

face1 = 'pCube1.f[1]'
cmds.select(face1)
cmds.polyChipOff(duplicate=True)
cmds.move(2, 2, 0, relative=True, objectSpace=True)
cmds.rotate(0, 0, 10, relative=True, componentSpace=True)
for i in range (35):
    cmds.polyChipOff(duplicate=True)
    cmds.rotate(0, 0, 10, relative=True, componentSpace=True)


来源:https://stackoverflow.com/questions/48268390/maya-2018-python-move-and-rotate-extracted-face

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!