简体   繁体   English

Maya 2018,Python,移动和旋转提取的面部

[英]Maya 2018, python, move and rotate extracted face

Trying to write part of the python code in Maya to extract the face from object then move it and rotate it. 尝试在Maya中编写python代码的一部分,以从对象中提取面部,然后将其移动并旋转。 I tried parameters of polyChipOff itself, tried xform and move and rotate functions. 我尝试了polyChipOff本身的参数,尝试了xform以及移动和旋转功能。 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. 只需创建一个pCube并启动脚本。 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)

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): 我不确定要旋转面的中心,所以我刚刚指定了(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. 更新:如果您需要绕着自己的中心旋转面,那么您刚才提到的就是componentSpace = True。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM