在Maya中使用Python命令创建Wrap Deformer

问题描述:

在Maya中使用默认的编写器创建命令 cmds.deformer(type='wrap') 仅仅只能创建一个Wrap节点,并不能获得正确的节点关系。所以还需要建立起正确的节点连接关系。

解决方案:

这里将建立Wrap节点的过程封装成了一个函数。

def createWrap(*args, **kwargs):
    influence = args[0]
    surface = args[1]

    shapes = mc.listRelatives(influence, shapes=True)
    influenceShape = shapes[0]

    shapes = mc.listRelatives(surface, shapes=True)
    surfaceShape = shapes[0]

    weightThreshold = kwargs.get('weightThreshold', 0.0)
    maxDistance = kwargs.get('maxDistance', 1.0)
    exclusiveBind = kwargs.get('exclusiveBind', False)
    autoWeightThreshold = kwargs.get('autoWeightThreshold', True)
    falloffMode = kwargs.get('falloffMode', 0)

    wrapData = mc.deformer(surface, type='wrap')
    wrapNode = wrapData[0]

    mc.setAttr(wrapNode + '.weightThreshold', weightThreshold)
    mc.setAttr(wrapNode + '.maxDistance', maxDistance)
    mc.setAttr(wrapNode + '.exclusiveBind', exclusiveBind)
    mc.setAttr(wrapNode + '.autoWeightThreshold', autoWeightThreshold)
    mc.setAttr(wrapNode + '.falloffMode', falloffMode)

    mc.connectAttr(surface + '.worldMatrix[0]', wrapNode + '.geomMatrix')

    duplicateData = mc.duplicate(influence, name=influence + 'Base')
    base = duplicateData[0]
    shapes = mc.listRelatives(base, shapes=True)
    baseShape = shapes[0]
    mc.hide(base)

    if not mc.attributeQuery('dropoff', n=influence, exists=True):
        mc.addAttr(influence, sn='dr', ln='dropoff', dv=4.0, min=0.0, max=20.0)
        mc.setAttr(influence + '.dr', k=True)

    if mc.nodeType(influenceShape) == 'mesh':
        if not mc.attributeQuery('smoothness', n=influence, exists=True):
            mc.addAttr(influence, sn='smt', ln='smoothness', dv=0.0, min=0.0)
            mc.setAttr(influence + '.smt', k=True)

        if not mc.attributeQuery('inflType', n=influence, exists=True):
            mc.addAttr(influence, at='short', sn='ift', ln='inflType', dv=2, min=1, max=2)

        mc.connectAttr(influenceShape + '.worldMesh', wrapNode + '.driverPoints[0]')
        mc.connectAttr(baseShape + '.worldMesh', wrapNode + '.basePoints[0]')
        mc.connectAttr(influence + '.inflType', wrapNode + '.inflType[0]')
        mc.connectAttr(influence + '.smoothness', wrapNode + '.smoothness[0]')

    if mc.nodeType(influenceShape) == 'nurbsCurve' or mc.nodeType(influenceShape) == 'nurbsSurface':
        if not mc.attributeQuery('wrapSamples', n=influence, exists=True):
            mc.addAttr(influence, at='short', sn='wsm', ln='wrapSamples', dv=10, min=1)
            mc.setAttr(influence + '.wsm', k=True)

        mc.connectAttr(influenceShape + '.ws', wrapNode + '.driverPoints[0]')
        mc.connectAttr(baseShape + '.ws', wrapNode + '.basePoints[0]')
        mc.connectAttr(influence + '.wsm', wrapNode + '.nurbsSamples[0]')

    mc.connectAttr(influence + '.dropoff', wrapNode + '.dropoff[0]')
    return wrapNode

调用时直接传入用于变形的物体的Transform Node和被变形的物体的Transform Node即可。

用例

在这里插入图片描述


# 用于包裹变形的物体的Transform节点
wrap_deformer = cmds.polyPlane(sh=3, sw=3, name="p1")[0]
# 被变形的物体的Transform节点
org_plane = cmds.polyPlane(sh=10, sw=10, name="p2")[0]
# 创建Wrap Node
# weightThreshold, maxDistance, exclusiveBind, autoWeightTreshold 为Wrap节点的属性配置参数,具体意义可见官方帮助
createWrap(wrap_deformer, org_plane, weightThreshold=0, maxDistance=1, exclusiveBind=False, autoWeightThreshold=True, falloffMode=0)

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值