def bindSpliceBetweenJoints(startJnt, endJnt, crv, startIndex, endIndex, targetCrv, skn, heightVec, intVec): ''' startJnt = upperBnds[0] endJnt = upperBnds[1] startIndex = upperBndTable[startJnt] endIndex = upperBndTable[endJnt] crv = drvCrv targetCrv = pm.PyNode('target_crv') ''' startHeight = lcrv.calcHeightFromCurve(startJnt, targetCrv, heightVec=heightVec, intVec=intVec) endHeight = lcrv.calcHeightFromCurve(endJnt, targetCrv, heightVec=heightVec, intVec=intVec) # figure out which splice to work on sectionBetween = crv.cv[min(startIndex, endIndex)+1:max(startIndex, endIndex)-1] sectionOutside = [cv for cv in crv.cv if cv not in sectionBetween and cv.index() not in (startIndex, endIndex)] # use the shorter section section = min((sectionBetween, sectionOutside), key=lambda sec: len(sec)) for eachCV in section: pos = eachCV.getPosition(space='world') height = lcrv.calcHeightFromCurve(pos, targetCrv) startSeg = height - startHeight endSeg = endHeight - height weight = startSeg / (startSeg + endSeg) pm.skinPercent(skn, eachCV, tv=((startJnt, 1-weight),(endJnt, weight)))
def bindSpliceBetweenJoints(startJnt, endJnt, crv, startIndex, endIndex, targetCrv, skn, heightVec, intVec): ''' startJnt = upperBnds[0] endJnt = upperBnds[1] startIndex = upperBndTable[startJnt] endIndex = upperBndTable[endJnt] crv = drvCrv targetCrv = pm.PyNode('target_crv') ''' startHeight = lcrv.calcHeightFromCurve(startJnt, targetCrv, heightVec=heightVec, intVec=intVec) endHeight = lcrv.calcHeightFromCurve(endJnt, targetCrv, heightVec=heightVec, intVec=intVec) # figure out which splice to work on sectionBetween = crv.cv[min(startIndex, endIndex) + 1:max(startIndex, endIndex) - 1] sectionOutside = [ cv for cv in crv.cv if cv not in sectionBetween and cv.index() not in (startIndex, endIndex) ] # use the shorter section section = min((sectionBetween, sectionOutside), key=lambda sec: len(sec)) for eachCV in section: pos = eachCV.getPosition(space='world') height = lcrv.calcHeightFromCurve(pos, targetCrv) startSeg = height - startHeight endSeg = endHeight - height weight = startSeg / (startSeg + endSeg) pm.skinPercent(skn, eachCV, tv=((startJnt, 1 - weight), (endJnt, weight)))
def setEyelidControlsWeights(prefix, upperBnds, lowerBnds, targetCrvs): # define all data - hard coded if not upperBnds: upperBnds = [nt.Joint(prefix+'_inner_eyelid_bnd'), nt.Joint(prefix+'_innerUpper_eyelid_bnd'), nt.Joint(prefix+'_upper_eyelid_bnd'), nt.Joint(prefix+'_outerUpper_eyelid_bnd'), nt.Joint(prefix+'_outer_eyelid_bnd')] if not lowerBnds: lowerBnds = [nt.Joint(prefix+'_inner_eyelid_bnd'), nt.Joint(prefix+'_innerLower_eyelid_bnd'), nt.Joint(prefix+'_lower_eyelid_bnd'), nt.Joint(prefix+'_outerLower_eyelid_bnd'), nt.Joint(prefix+'_outer_eyelid_bnd')] upperCtls = [pm.PyNode(node.name().replace('_bnd', '_ctrl')) for node in upperBnds] lowerCtls = [pm.PyNode(node.name().replace('_bnd', '_ctrl')) for node in lowerBnds] # weight ctls # UPPER controls # get vector from upper control heightVec = pm.dt.Vector(0,-1,0) * upperBnds[2].getMatrix(ws=True) intVec = pm.dt.Vector(0,0,-1) * upperBnds[2].getMatrix(ws=True) # get Y-height from lower curve upperHeight = lcrv.calcHeightFromCurve(upperBnds[2], targetCrvs['lower'], heightVec=heightVec, intVec=intVec) upperInnerHeight = lcrv.calcHeightFromCurve(upperBnds[1], targetCrvs['lower'], heightVec=heightVec, intVec=intVec) upperOuterHeight = lcrv.calcHeightFromCurve(upperBnds[3], targetCrvs['lower'], heightVec=heightVec, intVec=intVec) upperInnerWeight = upperInnerHeight / upperHeight upperOuterWeight = upperOuterHeight / upperHeight channels = ['tx','ty','tz','rx','ry','rz','sx','sy','sz'] upperPriCtl = upperCtls[2].name().replace('_ctrl', '_pri_ctrl') [upperBnds[1].attr(upperPriCtl+'_weight_'+channel).set(upperInnerWeight) for channel in channels] [upperBnds[3].attr(upperPriCtl+'_weight_'+channel).set(upperOuterWeight) for channel in channels] # LOWER controls # get vector from lower control heightVec = pm.dt.Vector(0,1,0) * lowerBnds[2].getMatrix(ws=True) intVec = pm.dt.Vector(0,0,-1) * lowerBnds[2].getMatrix(ws=True) # get y-height from upper crv lowerHeight = lcrv.calcHeightFromCurve(lowerBnds[2], targetCrvs['upper'], heightVec=heightVec, intVec=intVec) lowerInnerHeight = lcrv.calcHeightFromCurve(lowerBnds[1], targetCrvs['upper'], heightVec=heightVec, intVec=intVec) lowerOuterHeight = lcrv.calcHeightFromCurve(lowerBnds[3], targetCrvs['upper'], heightVec=heightVec, intVec=intVec) lowerInnerWeight = lowerInnerHeight / lowerHeight lowerOuterWeight = lowerOuterHeight / lowerHeight channels = ['tx','ty','tz','rx','ry','rz','sx','sy','sz'] lowerPriCtl = lowerCtls[2].name().replace('_ctrl', '_pri_ctrl') [lowerBnds[1].attr(lowerPriCtl+'_weight_'+channel).set(lowerInnerWeight) for channel in channels] [lowerBnds[3].attr(lowerPriCtl+'_weight_'+channel).set(lowerOuterWeight) for channel in channels]
def setEyelidControlsWeights(prefix, upperBnds, lowerBnds, targetCrvs): # define all data - hard coded if not upperBnds: upperBnds = [ nt.Joint(prefix + '_inner_eyelid_bnd'), nt.Joint(prefix + '_innerUpper_eyelid_bnd'), nt.Joint(prefix + '_upper_eyelid_bnd'), nt.Joint(prefix + '_outerUpper_eyelid_bnd'), nt.Joint(prefix + '_outer_eyelid_bnd') ] if not lowerBnds: lowerBnds = [ nt.Joint(prefix + '_inner_eyelid_bnd'), nt.Joint(prefix + '_innerLower_eyelid_bnd'), nt.Joint(prefix + '_lower_eyelid_bnd'), nt.Joint(prefix + '_outerLower_eyelid_bnd'), nt.Joint(prefix + '_outer_eyelid_bnd') ] upperCtls = [ pm.PyNode(node.name().replace('_bnd', '_ctrl')) for node in upperBnds ] lowerCtls = [ pm.PyNode(node.name().replace('_bnd', '_ctrl')) for node in lowerBnds ] # weight ctls # UPPER controls # get vector from upper control heightVec = pm.dt.Vector(0, -1, 0) * upperBnds[2].getMatrix(ws=True) intVec = pm.dt.Vector(0, 0, -1) * upperBnds[2].getMatrix(ws=True) # get Y-height from lower curve upperHeight = lcrv.calcHeightFromCurve(upperBnds[2], targetCrvs['lower'], heightVec=heightVec, intVec=intVec) upperInnerHeight = lcrv.calcHeightFromCurve(upperBnds[1], targetCrvs['lower'], heightVec=heightVec, intVec=intVec) upperOuterHeight = lcrv.calcHeightFromCurve(upperBnds[3], targetCrvs['lower'], heightVec=heightVec, intVec=intVec) upperInnerWeight = upperInnerHeight / upperHeight upperOuterWeight = upperOuterHeight / upperHeight channels = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'] upperPriCtl = upperCtls[2].name().replace('_ctrl', '_pri_ctrl') [ upperBnds[1].attr(upperPriCtl + '_weight_' + channel).set(upperInnerWeight) for channel in channels ] [ upperBnds[3].attr(upperPriCtl + '_weight_' + channel).set(upperOuterWeight) for channel in channels ] # LOWER controls # get vector from lower control heightVec = pm.dt.Vector(0, 1, 0) * lowerBnds[2].getMatrix(ws=True) intVec = pm.dt.Vector(0, 0, -1) * lowerBnds[2].getMatrix(ws=True) # get y-height from upper crv lowerHeight = lcrv.calcHeightFromCurve(lowerBnds[2], targetCrvs['upper'], heightVec=heightVec, intVec=intVec) lowerInnerHeight = lcrv.calcHeightFromCurve(lowerBnds[1], targetCrvs['upper'], heightVec=heightVec, intVec=intVec) lowerOuterHeight = lcrv.calcHeightFromCurve(lowerBnds[3], targetCrvs['upper'], heightVec=heightVec, intVec=intVec) lowerInnerWeight = lowerInnerHeight / lowerHeight lowerOuterWeight = lowerOuterHeight / lowerHeight channels = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'] lowerPriCtl = lowerCtls[2].name().replace('_ctrl', '_pri_ctrl') [ lowerBnds[1].attr(lowerPriCtl + '_weight_' + channel).set(lowerInnerWeight) for channel in channels ] [ lowerBnds[3].attr(lowerPriCtl + '_weight_' + channel).set(lowerOuterWeight) for channel in channels ]