使用 mel/python 在 Maya 中创建简单的层次结构
因此,我想在 Maya 中使用组和定位器节点创建一个非常简单的结构,然后将其导出以在我的游戏关卡中使用。
例如
Group_Root
group_parent
- group1
- locator1
- group2
- locator2
- group3
文件中只有一个Group_Root,有很多group_parent(每个都有唯一的名称) 但是,所有 group_parent 都具有相同的三个子组名称(“group1”、“group2”、“group3”),并且所有 group1 都有一个名为 locator1 的定位器
到目前为止我所拥有的是:
group_parent = c.group( em=True, name="group_parent", parent="Group_Root")
modes = ["group1", "group2", "group3"]
for mode in modes:
mode_group = c.group( em=True, n=mode, parent=group_parent )
if mode == "group1":
s = c.spaceLocator(name="locator1")
c.parent( mode_group )
elif mode == "group3":
s = c.spaceLocator(name="locator2")
c.parent( mode_group )
但是我在“c.parent( mode_group)"
# 错误:对象 group1 无效
大概是因为有多个名为“group1”的节点,所以它不知道应该将哪个节点作为父节点。
知道如何使用完整路径来做到这一点吗?例如“Group_Root | group_parent | group1”
So I want to create a very simple structure out of group and locator nodes in Maya which will then be exported for use in my game level.
e.g.
Group_Root
group_parent
- group1
- locator1
- group2
- locator2
- group3
There is only one Group_Root in the file, there are many group_parents ( each uniquely named )
However all group_parent's have the same three sub-group names( "group1", "group2", "group3" ) and all group1 have a locator called locator1
What I have so far is:
group_parent = c.group( em=True, name="group_parent", parent="Group_Root")
modes = ["group1", "group2", "group3"]
for mode in modes:
mode_group = c.group( em=True, n=mode, parent=group_parent )
if mode == "group1":
s = c.spaceLocator(name="locator1")
c.parent( mode_group )
elif mode == "group3":
s = c.spaceLocator(name="locator2")
c.parent( mode_group )
However I get this error at "c.parent(mode_group)"
# Error: Object group1 is invalid
Presumably because there are more than one node called "group1" so it doesn't know which one to parent.
Any idea how I do this with full paths? e.g. "Group_Root|group_parent|group1"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您见过VFX 溢出吗?这是关于视觉效果的问答,所以我希望许多观看者对 Maya/MEL 和 Python 非常熟悉。也就是说,它是相当新的,所以用户群仍然很小......
Have you seen VFX Overflow? It's Q&A for visual effects, so I'd expect a number of the watchers to be quite familiar with Maya/MEL and Python. That said, it is fairly new so the user base is still small...
对于 MEL 来说,名字可能有点烦人。一般来说,最好永远不要相信您所指定的名称。
这是一个很好的例子,说明了如何*不做某事:
..因为这决不能保证会产生名为“group1”的东西。更好的方法是运行命令并将结果捕获到字符串变量中,例如:
然后,使用 $result 引用结果组。即使该组最终被称为“myGroup23”,这仍然有效。
我不确定上面的内容在 Python 中看起来如何,因为我主要熟悉直接 MEL,但应该应用相同的原则。
另一件需要注意的事情是命名空间功能(命名空间和命名空间信息),它可用于为手头的唯一顶级组定义新的命名空间。
希望有帮助
Names can be a bit annoying with MEL. In general, it's good practice to never trust a name to be what you're specifying.
This is a good example of how *not to do things:
..because that is in no way guaranteed to result in something named "group1". The better way to do it is to run your command and capture the result in a string variable, such as:
Then, use $result to refer to the resulting group. That will still work, even if the group ended up being called 'myGroup23'.
I'm not sure how the above looks in Python, as I'm mainly familiar with straight MEL, but the same principles should apply.
Another thing to look at is the namespace functionality (namespace and namespaceInfo), which could be used to define a new namespace for the unique, top-leve group at hand.
Hope that helps
我猜已经两年多了,你现在已经弄清楚了这个问题..但是对于后代来说,有两个问题 - 首先,你清楚需要绝对路径,但也有一点您应用 maya.cmds.parent() 调用的方式存在错误。我刚刚做了一些简单的重写来说明 - 主要是您可以使用这样一个事实:当您创建事物时,它们会默认被选中,并且 maya.cmds.ls() 足够智能,可以返回您需要的内容。因此:
I'm guessing that it being over two years, you've figured this one out by now.. but for posterity, there were two issues - firstly, you were spot on with the need for absolute paths, but there was also a slight bug in the way you were applying the maya.cmds.parent() call. I've just done some light rewriting to illustrate - mainly you could use the fact that when you create things they become selected by default, and maya.cmds.ls() is smart enough to return you what you need.. Ergo: