问题描述
我刚刚开始使用python / MEL脚本,并且想知道是否有一种方法可以将选定的项目转换为python中的nCloths。我知道在软件中,您只需选择所需的对象,然后单击“创建nCloth”。当我这样做时,我在终端中得到以下MEL脚本-
createNCloth 0;
是否只有在python中可以做到这一点?还是必须是Mel / Python混合体?
解决方法
如果在Maya脚本编辑器的MEL
标签中运行此命令,则会得到:
whatIs createNCloth;
// Result: Script found in: C:/Program Files/Autodesk/Maya2018/scripts/others/createNCloth.mel //
简要浏览createNCloth.mel
脚本,看起来有些复杂。您可以通过maya.mel
模块从python自己调用此脚本,不幸的是,这通常是某些专门的Maya集成的工作方式。
请记住,createNCloth(<worldSpace>)
proc期望您的网格被选中,并且不允许您将对象作为参数传递。
@itypewithmyhands为您提供了一种查找MEL proc内部内容的方法。
请注意,控制用户选择有很多检查,而主要是这样做:
# create a cloth node
cmds.createNode("nCloth")
# connect time node
cmds.connectAttr("time1.outTime",nCloth + ".currentTime")
# connect your mesh to the ncloth
cmds.connectAttr(mesh + ".worldMesh",nCloth + ".inputMesh")
# create an output shape that will be the simulation mesh
outMesh = cmds.createNode("mesh",parent=tform,name=outMeshName)
cmds.connectAttr(nCloth + ".outputMesh",outMesh + ".inMesh")
# connect the startframe
cmds.connectAttr(nucleus + ".startFrame",nCloth + ".startFrame")
# Connect the cloth node to the nucleus with an available ID
cmds.connectAttr(nCloth + ".currentState",nucleus +".inputActive[{}]".format(nindex),f=1)
cmds.connectAttr(nCloth + ".startState",nucleus + ".inputActiveStart[{}]",f=1)
# force the refresh when used in batch
cmds.getAttr(cloth + ".forceDynamics")
因此,这些是复制基本布料网络的强制性步骤。请注意,您还必须创建核,也许要检查基础网格是否变形,您可能希望将输入网格设置为中间形状...等等