【问题标题】:Center object pivot with world center after combine合并后以世界中心为中心对象枢轴
【发布时间】:2020-07-27 16:56:04
【问题描述】:

当我在 Maya 中取 2 个对象并组合它们时,组合对象的轴心是世界的中心,因此我使用 ModifyCenter Pivot选项。

但之后该对象与其他对象的中心不同,例如当我将其位置设置为 (0, 0, 0) 时,它不是世界的中心。

我知道我可以将组合对象移动到世界中心,然后使用修改中心轴,但它不准确。

我有什么遗漏吗?如何使对象的轴心居中并使其与世界保持相对?

这就是我的意思,因为您可以看到对象位于 (0,0,0) 位置,但不在世界中心:

【问题讨论】:

    标签: pivot maya centering


    【解决方案1】:

    发生的情况是,当您使用中心枢轴时,它不会影响对象的平移值,而是使用其枢轴偏移它(局部旋转枢轴属性)。因此,即使您的平移全部为零,来自枢轴的值也会导致您的对象偏离世界原点。

    尽管了解上述内容是有道理的,但 Maya 处理它的方式仍然很烦人。

    这是一个尝试解决此问题的脚本。它本质上做的是获取它的枢轴值,将其归零,并将其添加到它的翻译中:

    2018 年玛雅人

    import maya.cmds as cmds
    
    sel = cmds.ls(sl=True)[0]  # Get selection.
    
    cmds.xform(sel, cpc=True)  # Center its pivot. Comment this out if you don't want to force it to center and use the pivot as-is.
    pivots = cmds.xform(sel, q=True, piv=True)[:3]  # Get its pivot values.
    
    temp_nul = cmds.createNode("transform")  # Create a temporary transform.
    cmds.matchTransform(temp_nul, sel)  # Align the transform to our object.
    
    try:
        cmds.xform(sel, piv=[0, 0, 0])  # Zero-out object's pivot values.
        cmds.move(-pivots[0], -pivots[1], -pivots[2], "{}.vtx[*]".format(sel), os=True, r=True)  # Negate and move object via its old pivot values.
        cmds.matchTransform(sel, temp_nul)  # Align the object back to the temporary transform, to maintain its old position.
    finally:
        cmds.delete(temp_nul)  # Delete temporary transform.
        cmds.select(sel)  # Restore old selection.
    

    Maya 2016 和

    import maya.cmds as cmds
    import maya.mel as mel
    
    sel = cmds.ls(sl=True)[0]  # Get selection.
    
    mel.eval("CenterPivot;")  # Center its pivot. Comment this out if you don't want to force it to center and use the pivot as-is.
    pivots = cmds.xform(sel, q=True, piv=True)[:3]  # Get its pivot values.
    old_tm = cmds.xform(sel, q=True, ws=True, m=True) # Get its transform matrix.
    
    temp_nul = cmds.createNode("transform")  # Create a temporary transform.
    cmds.xform(temp_nul, ws=True, m=old_tm)  # Align it to the matrix.
    cmds.xform(temp_nul, os=True, r=True, t=pivots)  # Move it to include the pivot offsets.
    new_tm = cmds.xform(temp_nul, q=True, ws=True, m=True)  # Store it's transform matrix to align to later.
    
    try:
        cmds.xform(sel, piv=[0, 0, 0])  # Zero-out object's pivot values.
        cmds.move(-pivots[0], -pivots[1], -pivots[2], "{}.vtx[*]".format(sel), os=True, r=True)  # Negate and move object via its old pivot values.
        cmds.xform(sel, ws=True, m=new_tm)  # Align the object back to the temporary transform, to maintain its old position.
    finally:
        cmds.delete(temp_nul)  # Delete temporary transform.
        cmds.select(sel)  # Restore old selection.
    

    选择您的对象,然后执行脚本来运行它。我在具有随机旋转的组合对象上对其进行了测试,同时作为具有随机旋转的对象的父级。它似乎可以正常工作而不会弹出。

    您还可以通过使用polyMoveVertex 节点而不是脚本的节点组合来实现相同的效果。

    【讨论】:

    • 感谢您的回复,上面的代码是Python还是MEL?当我尝试将它作为 Python 运行时,出现此错误“# Error: line 1: TypeError: file line 5: Invalid flag 'cpc' #” 注意:我使用的是 Maya 2015
    • 啊,这是在 Maya 2018 上。后来的版本没有 matchTransform,而且看起来 2015 在 xform 上没有 cpc 标志
    • 它是 Python。我添加了一个应该对旧版本更友好的脚本。
    猜你喜欢
    • 2021-01-31
    • 1970-01-01
    • 2016-11-26
    • 1970-01-01
    • 2015-05-05
    • 2013-08-13
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    相关资源
    最近更新 更多