示例#1
0
def setWeigths(skinNode, geo, inf, weigth):
    #获得一个组件列表
    cmp_list = [universal.intoComponents(i) for i in universal.translateToName(geo)]
    #检查组件列表的数量
    if len(cmp_list)<1:
        raise EOFError('geo没有任何对象')
    #建立一个组件选择列表
    sel_list = om.MSelectionList()
    [sel_list.add(i) for i in cmp_list]
    if int(sel_list.length())>1:
        raise EOFError('%s 不在一个mesh或者其他对象上'%geo)
        return 1
    path,comp = sel_list.getComponent(0)
    sel_list.add(skinNode)
    skinNode = sel_list.getDependNode(1)


    fn_skin = oma.MFnSkinCluster(skinNode)

    m_inf = om.MIntArray(inf)
    m_weigth = om.MDoubleArray(weigth)
    #撤销的权重
    unWeights = fn_skin.getWeights(path,comp,m_inf)

    doIt = functools.partial(fn_skin.setWeights,path,comp,m_inf,m_weigth)
    undoIt = functools.partial(fn_skin.setWeights,path,comp,m_inf,unWeights)
    return cmcore.addCommand(doIt, undoIt)
示例#2
0
 def setBlendWeights(self,weigth):
     #执行的权重
     m_weigth = om.MDoubleArray(weigth)
     #撤销的权重
     unWeights = self.fn_skin.getBlendWeights(self.path,self.comp)
     doIt = functools.partial(self.fn_skin.setBlendWeights,self.path,self.comp,m_weigth)
     undoIt = functools.partial(self.fn_skin.setBlendWeights,self.path,self.comp,unWeights)
     return cmcore.addCommand(doIt, undoIt)
示例#3
0
    def setWeigths(self,inf,weigth):
        m_inf = om.MIntArray(inf)
        #执行的权重
        m_weigth = om.MDoubleArray(weigth)
        #撤销的权重
        unWeights = self.fn_skin.getWeights(self.path,self.comp,m_inf)

        doIt = functools.partial(self.fn_skin.setWeights,self.path,self.comp,m_inf,m_weigth)
        undoIt = functools.partial(self.fn_skin.setWeights,self.path,self.comp,m_inf,unWeights)
        return cmcore.addCommand(doIt, undoIt)
示例#4
0
    def setWeight(self,weights):
        float_array = om.MFloatArray()
        append = float_array.append
        try:
            [append(i) for i in weights]
        except:
            raise EOFError('输入权重列表错误')

        try:
            undoIt_float_array = om.MFloatArray()
            self.weightGeo.getWeights(self.path,self.comp,undoIt_float_array)
        except:
            raise EOFError('获得原始权重列表失败')
        doIt_def = functools.partial(self.weightGeo.setWeight,self.path,self.comp,float_array)
        undoIt_def = functools.partial(self.weightGeo.setWeight,self.path,self.comp,undoIt_float_array)
        return cmc.addCommand(doIt_def,undoIt_def)
示例#5
0
def setWeigths(skinNode, geo, weigth, inf = None): 
    if inf is None:
        unWeights = [t for i in skinNode.getWeights(geo) for t in i]
        inf = range(len(skinNode.getInfluence()))
    else:
        unWeights = [
            t for i in
            zip(*[
                [
                    t for t in skinNode.getWeights(geo, i)
                ] for i in inf
            ])
            for t in i
        ]
    doIt = functools.partial(skinNode.setWeights, geo, inf, weigth)
    undoIt = functools.partial(skinNode.setWeights, geo, inf, unWeights)
    return cmcore.addCommand(doIt, undoIt)
示例#6
0
def setDeformerWeigth(DeformerNode,geo,weights):
    #获得一个组件列表
    cmp_list = [universal.intoComponents(i) for i in universal.translateToName(geo)]
    #检查组件列表的数量
    if len(cmp_list)<1:
        raise EOFError('geo没有任何对象')
    #建立一个组件选择列表
    sel_list = om.MSelectionList()
    [sel_list.add(i) for i in cmp_list]
    if int(sel_list.length())>1:
        raise EOFError('%s 不在一个mesh或者其他对象上'%geo)
        return 1
    path = om.MDagPath()
    comp = om.MObject()
    sel_list.getDagPath(0,path,comp)

    #获得变形节点
    obj = om.MObject()
    sel_list.add(DeformerNode)
    sel_list.getDependNode(1,obj)

    try:
        weightGeo = oma.MFnWeightGeometryFilter(obj)
    except:
        raise EOFError('输入的变形节点不是正确的对象(簇,软变形...)')

    float_array = om.MFloatArray()
    append = float_array.append
    try:
        [append(i) for i in weights]
    except:
        raise EOFError('输入权重列表错误')

    try:
        undoIt_float_array = om.MFloatArray()
        weightGeo.getWeights(path,comp,undoIt_float_array)
    except:
        raise EOFError('获得原始权重列表失败')
    doIt_def = functools.partial(weightGeo.setWeight,path,comp,float_array)
    undoIt_def = functools.partial(weightGeo.setWeight,path,comp,undoIt_float_array)
    return cmc.addCommand(doIt_def,undoIt_def)
示例#7
0
[sel_list.add(i) for i in cmp_list]
if int(sel_list.length())>1:
    raise EOFError('%s 不在一个mesh或者其他对象上'%geo)
    return 1
path,comp = sel_list.getComponent(0)
sel_list.add(skinNode)
skinNode = sel_list.getDependNode(1)

fn_skin = oma.MFnSkinCluster(skinNode)
m_inf = om.MIntArray(inf)
m_weigth = om.MDoubleArray(weigth)
unWeights = fn_skin.getWeights(path,comp,m_inf)

doIt = functools.partial(fn_skin.setWeights,path,comp,m_inf,m_weigth)
undoIt = functools.partial(fn_skin.setWeights,path,comp,m_inf,unWeights)
cmcore.addCommand(doIt, undoIt)

fl_array = fn_skin.getBlendWeights(path,comp)
fn_skin.setBlendWeights(path,comp,fl_array)



class SetWeights:
    '''
    操作蒙皮权重的类
    setWeigths(self,inf,weigth)#设置蒙皮权重
    getWeigths(self,inf)#获得蒙皮权重
    setBlendWeights(self,weigth)#设置DQ混合权重
    getBlendWeights(self)#获得DQ权重
    '''
    def __init__(self,skinNode, geo):
示例#8
0
def setDeformerWeigth(DeformerNode,weights,geo=None):
    #DeformerNode = 'softMod1'
    #geo = None
    #weights = [0 for i in pm.selected(fl = True)]

    if not pm.objExists(DeformerNode):
        om.MGlobal.displayError('错误输入的变形节点并不存在')
        return False
    if not isinstance(DeformerNode,basestring):
    	DeformerNode = DeformerNode.nodeName()
    if not geo is None:
        if not pm.objExists(geo):
            om.MGlobal.displayError('错误输入的对象并不存在')
            return False
        if not isinstance(geo,basestring):
            geo = ['%s'%i for i in pm.ls(geo)]
        else:
            geo = [geo]
    sel = om.MSelectionList()
    obj = om.MObject()
    path = om.MDagPath()
    comp = om.MObject()
    try:
        sel.add(DeformerNode)
    except:
        om.MGlobal.displayError('无法找到变形节点')
        return False
    sel.getDependNode(0,obj)
    
    try:
        weightGeo = oma.MFnWeightGeometryFilter(obj)
    except:
        om.MGlobal.displayError('输入的变形节点不是正确的对象(簇,软变形...)')
        return False
    float_array = om.MFloatArray()
    append = float_array.append
    try:
        [append(i) for i in weights]
    except:
        om.MGlobal.displayError('输入权重列表错误')
        return False
    sel = om.MSelectionList()
    if not geo is None:
        try:
            [sel.add(i) for i in geo]
        except:
            om.MGlobal.displayError('无法找到变形对象')
            return False

        sel.getDagPath(0,path,comp)
    
        try:
            undoIt_float_array = om.MFloatArray()
            weightGeo.getWeights(path,comp,undoIt_float_array)
            doIt_def = functools.partial(weightGeo.setWeight,path,comp,float_array)
            undoIt_def = functools.partial(weightGeo.setWeight,path,comp,undoIt_float_array)
            cmc.addCommand(doIt_def,undoIt_def)
        except:
            om.MGlobal.displayError('设置权重发生错误')
            return False
    else:
        comp_dict = {'mesh':'vtx','nurbsCurve':'cv','nurbsSurface':'cv','lattice':'pt'}
        for i in range(weightGeo.numOutputConnections()):
            weightGeo.getPathAtIndex(i,path)
            itGeo = om.MItGeometry(weightGeo.outputShapeAtIndex(i))
            length = itGeo.exactCount()
            shape = path.fullPathName()
            shape_type = mc.objectType(shape)
            comp_type = comp_dict[shape_type]
            for t in range(length):
                sel.add('%s.%s[%d]'%(shape,comp_type,itGeo.index()) )
                itGeo.next()
        if sel.length() == 1:
            sel.getDagPath(0,path,comp)
            try:
                undoIt_float_array = om.MFloatArray()
                weightGeo.getWeights(path,comp,undoIt_float_array)
                doIt_def = functools.partial(weightGeo.setWeight,path,0,comp,float_array)
                undoIt_def = functools.partial(weightGeo.setWeight,path,0,comp,undoIt_float_array)
                cmc.addCommand(doIt_def,undoIt_def)
            except:
                om.MGlobal.displayError('设置权重发生错误')
                return False
        crr_id = 0
        for i in range(sel.length()):
            sel.getDagPath(i,path,comp)
            obj_comp_size = om.MFnComponent(comp).elementCount()
            try:
                undoIt_float_array = om.MFloatArray()
                weightGeo.getWeights(path,comp,undoIt_float_array)
                
                doIt_float_array = float_array[crr_id:crr_id+obj_comp_size]
                
                doIt_def = functools.partial(weightGeo.setWeight,path,i,comp,doIt_float_array)
                undoIt_def = functools.partial(weightGeo.setWeight,path,i,comp,undoIt_float_array)
                cmc.addCommand(doIt_def,undoIt_def)
                
                #weightGeo.setWeight(path,i,obj,float_array[crr_id:crr_id+obj_comp_size])
            except:
                om.MGlobal.displayError('设置权重发生错误')
                return False
            crr_id += obj_comp_size
    return True