Maya 2018,Python,移动和旋转提取的面部 [英] Maya 2018, python, move and rotate extracted face

查看:189
本文介绍了Maya 2018,Python,移动和旋转提取的面部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Maya中编写python代码的一部分,以从对象中提取面部,然后将其移动并旋转.我尝试了polyChipOff本身的参数,尝试了xform以及移动和旋转功能.问题是一样的.如果旋转是在平移之后进行的,则旋转面将相对于先前位置而不是当前位置旋转.

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?

下面的代码显示了该问题.只需创建一个pCube并启动脚本.从我的角度来看,该代码应面朝下移动,然后围绕自身旋转很多次.取而代之的是,它以圆心旋转,中心是移动命令之前面部所在的中心.

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)

推荐答案

在您的示例中,面不围绕其先前位置旋转,而是围绕对象枢轴旋转(您可以在执行脚本之前尝试移动对象枢轴并查看旋转中心发生变化.)

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).

如果您想要另一个枢轴,则需要将其指定为参数.我不确定要旋转面的中心,所以我刚刚指定了(2,2,0):

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)

更新: 如果您需要绕着自己的中心旋转面,那么就像您提到的,它只是componentSpace = True.所以代码看起来像这样:

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)

这篇关于Maya 2018,Python,移动和旋转提取的面部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆