使用python从选定对象创建nCloth?

2024-09-27 21:29:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚开始学习python/MEL脚本,想知道是否有一种方法可以在python中将选定的项目转换为nCloth。我知道在软件中,您只需选择所需的对象,然后单击“创建nCloth”。当我这样做时,我会在终端中获得以下MEL脚本-

CreateCloth 0

有没有一种方法只在python中实现这一点?或者这必须是Mel/Python的混合


Tags: 项目对象方法脚本终端软件中将我会
2条回答

@itypewithmyhands为您提供了查找MEL程序内部内容的方法

请注意,控制用户选择需要进行大量检查,主要是:

# 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")

因此,这些是复制基本cloth网络的必要步骤。请注意,您还必须创建nucleus,可能需要检查基础网格是否变形,您可能需要将输入网格设置为中间形状。。。等

如果在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>)程序希望选择网格,而不允许将对象作为参数传递

相关问题 更多 >

    热门问题