使用 mel/python 在 Maya 中创建简单的层次结构

发布于 2024-08-18 14:25:26 字数 984 浏览 15 评论 0原文

因此,我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

べ繥欢鉨o。 2024-08-25 14:25:26

您见过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...

银河中√捞星星 2024-08-25 14:25:26

对于 MEL 来说,名字可能有点烦人。一般来说,最好永远不要相信您所指定的名称。

这是一个很好的例子,说明了如何*不做某事:

group -n myGroup1 circle1 sphere1;

..因为这决不能保证会产生名为“group1”的东西。更好的方法是运行命令并将结果捕获到字符串变量中,例如:

string $result = `group -n myGroup circle1 sphere1`;

然后,使用 $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:

group -n myGroup1 circle1 sphere1;

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

string $result = `group -n myGroup circle1 sphere1`;

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

忘东忘西忘不掉你 2024-08-25 14:25:26

我猜已经两年多了,你现在已经弄清楚了这个问题..但是对于后代来说,有两个问题 - 首先,你清楚需要绝对路径,但也有一点您应用 maya.cmds.parent() 调用的方式存在错误。我刚刚做了一些简单的重写来说明 - 主要是您可以使用这样一个事实:当您创建事物时,它们会默认被选中,并且 maya.cmds.ls() 足够智能,可以返回您需要的内容。因此:

c.group( em=True, name="group_parent", parent="Group_Root")
group_parent = c.ls(sl=True)[0]

modes =  ["group1" , "group2", "group3"]
for mode in modes:
    c.group( em=True, n=mode, parent=group_parent )
    mode_group = c.ls(sl=True)[0]
    if mode == "group1":
            c.spaceLocator(name="locator1")
            s = c.ls(sl=True)[0]
            # maya.cmds.parent() with something selected will actually
            # parent the specified object to the selected object. 
            # You don't want that.


            # We might as well use the explicit syntax to be sure 
            # (parent everything specified to the last item in the list)
            c.parent( s, mode_group ) 
    elif mode == "group3":
            c.spaceLocator(name="locator2")
            s = c.ls(sl=True)[0]
            c.parent( s, mode_group )

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:

c.group( em=True, name="group_parent", parent="Group_Root")
group_parent = c.ls(sl=True)[0]

modes =  ["group1" , "group2", "group3"]
for mode in modes:
    c.group( em=True, n=mode, parent=group_parent )
    mode_group = c.ls(sl=True)[0]
    if mode == "group1":
            c.spaceLocator(name="locator1")
            s = c.ls(sl=True)[0]
            # maya.cmds.parent() with something selected will actually
            # parent the specified object to the selected object. 
            # You don't want that.


            # We might as well use the explicit syntax to be sure 
            # (parent everything specified to the last item in the list)
            c.parent( s, mode_group ) 
    elif mode == "group3":
            c.spaceLocator(name="locator2")
            s = c.ls(sl=True)[0]
            c.parent( s, mode_group )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文