【问题标题】:Maya Python/MEL script to replace/swap out material用于替换/换出材料的 Maya Python/MEL 脚本
【发布时间】:2015-11-26 10:33:54
【问题描述】:

我在网上搜索了大约 6 个小时,但在这个问题上没有运气。

在 Autodesk maya (2016) 中,我想将材料从名为“dg_plastic”的标准 phong 材料换出/替换为另一种名为“plastic”的材料。

  • 标准 phong 材料将具有预定义的名称,如上例所示。
  • 我们有一个带有预定义名称的现成材料库可供选择。

有没有办法用 Python 或 MEL 编写脚本来解决这个问题?

谢谢!

【问题讨论】:

  • 您是否尝试将新材质应用于场景中已经分配了材质的东西?

标签: python maya mel


【解决方案1】:

CreativeCrash 上有一个旧线程处理这个问题。我在那里展示的脚本如下所示(有关更多信息,请参阅原始线程):

proc connectAndSet(string $original, string $target){
    $conn = `connectionInfo -sfd $original`;
    if ($conn != ""){
        connectAttr -force $conn $target;
    } else {
        connectAttr -force $original $target;
        disconnectAttr $original $target;
    }
}

proc convertPhongToMia(string $original){
    $target = `mrCreateCustomNode -asShader "" mia_material_x`;

    connectAndSet($original + ".color", $target + ".diffuse");
    // ... any other mapping you need comes here...
    // a bit weak test should work for simple materials,
    // not used in special context
    $sg = `connectionInfo -dfs ($target + ".message")`;
    $sgr = `match "[^.]*" ((string)$sg[0])`;
    $sg0 = `connectionInfo -dfs ($original + ".outColor")`;
    $sgr0=`match "[^.]*" ((string)$sg0[0])`;
    sets -e -forceElement $sgr `sets -q $sgr0`;
    delete $original;
    rename $sgr $sgr0;
    rename $target $original;
}

for ($item in `ls -et phong`)
    convertPhongToMia($item);

您应该可以根据自己的需要重新使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 2018-01-27
    相关资源
    最近更新 更多