def merge( directionAstart, directionAend, directionBstart, newStart ): '''merges two different locomotes together - for example N and E to give a NE locomote''' #determine which ctrl set to use length = directionAend-directionAstart ctrlSet = names.matchNames(['body_ctrls'],cmd.ls(type='objectSet')) if not ctrlSet: raise Exception('control set not found') ctrlSet = ctrlSet[0] ctrls = cmd.sets(ctrlSet,q=True) #deal with the assets for the new animation vx = exportManagerCore.ExportManager() assetA = vx.exists(start=directionAstart,end=directionAend)[0] assetB = vx.exists(start=directionBstart,end=directionBstart+length)[0] exportSet = assetA.obj assetC = vx.exists(start=newStart,end=newStart+length) if not assetC: assetC = vx.createAsset(exportSet) assetC.setAttr('start', newStart) assetC.setAttr('end', newStart+length) assetC.setAttr('name', assetA.name + assetB.name) assetC.setAttr('type', exportManagerCore.ExportComponent.kANIM) #now start building the animations animationA = Animation(ctrls,directionAstart,directionAend) animationB = Animation(ctrls,directionBstart,directionBstart+length) animationB.offset(-directionBstart+directionAstart) animationC = animationA+animationB animationC.offset(newStart) #grab the list of ctrls we need to actually transform toFind = ['upperBodyControl','legControl_L','legControl_R'] xformCtrls = [name for name in names.matchNames(toFind,ctrls,parity=True,threshold=0.8) if name != ''] for ctrl in xformCtrls: motionA = motionList(ctrl,directionAstart,directionAend) motionB = motionList(ctrl,directionBstart,directionBstart+length) #make the time zero based times = [int(time)-newStart for time in animationC[ctrl].get_times(channels=['translateX','translateZ'])] times.sort() print times,len(motionA),len(motionB) for time in times: print motionA[time],motionB[time] newPos = vectors.Vector(motionA[time]) + vectors.Vector(motionB[time]) newPos *= 0.70710678118654757 #= math.cos(45degrees) tx = animationC[ctrl].translateX[time] tz = animationC[ctrl].translateZ[time] if tx: tx.keys[0] = newPos.x if tz: tz.keys[0] = newPos.z animationC.applyToObjs() #end
def onFileOpenCB(): #make sure the file being loaded is under the current project - otherwise weird things can happen #with the export manager etc... import exportManagerCore if not exportManagerCore.isSceneUnderCurrentProject(): cmd.confirmDialog( m= "WARNING: the current scene isn't under the current project...\n\nthis will most likely cause problems. please exit maya and\nset your project correctly", t="project/scene mismatch", db="OK") #update export manager data... import exportManagerUI exportManager = exportManagerCore.ExportManager() exportManager.update() exportManagerUI.update() #check for the existence of various windows, and reopen them if cmd.window('modelCompiler', ex=True): cmd.deleteUI('modelCompiler') file = Path(cmd.file(q=True, sn=True)) if file.exists: statusDict = P4File(file).getStatus() msgs = [] staleDeps = listOutOfSyncDependencies() if staleDeps: msgs.append( "WARNING: the following files are used by this scene, but aren't up to date with the latest perforce revision:\n\n%s\n\nyou can sync all dependencies from the perforce menu in maya:\nPerforce -> Sync Maya Dependencies" % '\n'.join(staleDeps)) #check to see if the file is open for edit by someone else, and warn the user otherOpens = [] try: otherOpens = statusDict['otherOpen'] except KeyError: pass except TypeError: pass if otherOpens: msgs.append( "WARNING: this file is open for edit by:\n%s\n\nif you plan of making changes, make sure you check when them first before putting in too much work" % '\n'.join(otherOpens)) if msgs: cmd.confirmDialog( m='\n------------------------------\n\n'.join(msgs), b='OK', db='OK')
def commonApply(rig, rigNS, filename, nodes, mapping, postTraceSchemeFilepath=None, sortBySrcs=True): #apply the post trace scheme if applicable if postTraceSchemeFilepath is not None: loadPostTraceSchemeFilepath(postTraceSchemeFilepath) possibleSrcs = cmd.ls('%s*' % IMPORT_DATA_NS, typ='transform') possibleTgts = cmd.ls('%s*' % rigNS, typ='transform') #build the ctrl-bone mapping - and ensure proper namespaces are present... the mapping contains no namespaces srcs, tgts = [], [] idx = 0 if sortBySrcs else 1 toSort = [] for src, tgt in mapping.iteritems(): src = names.matchNames([src], possibleSrcs)[0] tgt = names.matchNames([tgt], possibleTgts)[0] srcOrTgt = src, tgt if cmd.objExists(srcOrTgt[idx]): numParents = len(list(api.iterParents(srcOrTgt[idx]))) toSort.append((numParents, src, tgt)) toSort.sort() for idx, src, tgt in toSort: srcs.append(src) tgts.append(tgt) print "rig namespace is:", rigNS print 'srcs are', srcs print 'tgts are', tgts #sort the items by hierarchy based on the src items - xferAnim does have the option of doing this, but it sorts using the tgt list, and its done in mel, so... I don't trust it srcsParentCount = [(len([p for p in api.iterParents(s)]), s, t) for s, t in zip(srcs, tgts) if cmd.objExists(s)] srcsParentCount.sort() srcs = [s[1] for s in srcsParentCount] tgts = [s[2] for s in srcsParentCount] #now turn any ik off - we'll restore it afterwards, but if ik is on, then fk controls don't get traced properly... coz maya is ghey! initIkBlendValues = {} for t in tgts: attrPath = "%s.ikBlend" % t if cmd.objExists(attrPath): initIkBlendValues[attrPath] = cmd.getAttr(attrPath) cmd.setAttr(attrPath, 0) #perform the trace api.melecho.zooXferTrace(srcs, tgts, True, True, False, True, False, -1000, 1000) #restore ik settings for attrPath, value in initIkBlendValues.iteritems(): cmd.setAttr(attrPath, value) #rename the file mayaFilepath = apps.getAssetRoot( rig, apps.MAYA) / 'maya/animation' / filename.name() mayaFilepath.up().create() cmd.file(rename=mayaFilepath) mayaFilepath = Path(cmd.file(q=True, sn=True)) #try to determine the info node to export exportNode = None for n in cmd.ls(typ='vstInfo'): if n.startswith(rigNS): exportNode = n break #setup the export manager data if we can... if exportNode is not None: xm = exportManagerCore.ExportManager() comp = xm.createExportComponent([exportNode]) comp.setAttr('name', mayaFilepath.name()) comp.setAttr('type', exportManagerCore.ExportComponent.kANIM) #save changes... cmd.file(save=True, f=True) return mayaFilepath
def generate( baseStart, baseEnd,\ rotations = PRIMARY_ROTATIONS,\ strideLengthMultipliers = PRIMARY_SPEEDS,\ starts = PRIMARY_START_FRAMES,\ directions = PRIMARY_NAMES ): #determine which ctrl set to use ctrlSet = names.matchNames(['body_ctrls'], cmd.ls(type='objectSet'), threshold=1) if not ctrlSet: raise Exception('control set not found') ctrlSet = ctrlSet[0] ctrls = cmd.sets(ctrlSet, q=True) length = baseEnd - baseStart num = len(rotations) #does the base locomote have an asset? vx = exportManagerCore.ExportManager() baseAsset = vx.exists(start=baseStart, end=baseEnd) infoNode = '' exportSet = '' if len(baseAsset): baseAsset = baseAsset[0] exportSet = baseAsset.obj else: #if it doesn't exist, try and create one infoNodes = cmd.ls(type='vstInfo') candidates = [] for node in infoNodes: if not cmd.referenceQuery(node, inr=True): continue if not cmd.listRelatives(node): continue candidates.append(node) infoNode = candidates[0] exportSet = exportManagerCore.ExportManager.CreateExportSet([infoNode]) #now build the actual asset asset = vx.createAsset(exportSet) asset.setAttr('start', baseStart) asset.setAttr('end', baseEnd) asset.setAttr('name', 'N') asset.setAttr('type', exportManagerCore.ExportComponent.kANIM) #grab the list of ctrls we need to actually transform toFind = ['upperBodyControl', 'legControl_L', 'legControl_R'] #, 'armControl_L', 'armControl_R' ] xformCtrls = [ name for name in names.matchNames(toFind, ctrls, parity=True, threshold=0.8) if name != '' ] animation = Animation(ctrls, baseStart, baseEnd) animation.getWorld(xformCtrls, ['translateX', 'translateZ']) #save the animation out - useful for doing deltas later on #write(animation,g_defaultKeyUtilsPickle) #build the rotation axis axis = vectors.Vector([0, 1, 0]) for n in xrange(num): offset = starts[n] - baseStart tmpAnim = animation.copy() tmpAnim.offset(offset) #convert angles to radians, and do other static calcs angle = rotations[n] angle = math.radians(angle) quat = vectors.Quaternion.AxisAngle(axis, angle) for ctrl in xformCtrls: clip = tmpAnim[ctrl] #do the actual rotation around Y mats = clip.world translateX = clip.translateX.keys = [] translateZ = clip.translateZ.keys = [] for mat in mats: pos = mat.get_position() pos = pos.rotate(quat) mat[3][:3] = pos translateX.append(Key(time=mat.time, value=pos.x)) translateZ.append(Key(time=mat.time, value=pos.z)) #now do stride length multiplication strideMult = strideLengthMultipliers[n] if strideMult is not None: def makeShorter(key): key.value *= strideMult return key clip.translateX.transform(makeShorter) clip.translateZ.transform(makeShorter) tmpAnim.applyToObjs(clearFirst=True) #finally create an asset for the new anim existing = vx.exists(start=starts[n], end=starts[n] + length, name=directions[n]) if not len(existing): asset = vx.createAsset(exportSet) asset.setAttr('start', starts[n]) asset.setAttr('end', starts[n] + length) asset.setAttr('name', directions[n]) asset.setAttr('type', exportManagerCore.ExportComponent.kANIM)
from maya import cmds as cmd from filesystem import * import api, exportManagerCore, skinCluster, modelCompiler mel = api.mel melecho = api.melecho kFWD_AXIS = 'x' exportManager = exportManagerCore.ExportManager() def rigProp(): curFile = cmd.file(q=True, sn=True) if curFile is None: api.melError('please save your scene first') curFile = Path(curFile) propName = curFile.name() #strip any model identifier propName = propName.replace('_reference', '').replace('_model', '') #make sure all items in the export set are parented under the info node - this makes exporting animation for the prop easier asset = modelCompiler.findComponent('model') for o in asset.getObjs(): try: cmd.parent(o, exportManager.node) except Exception, e: print 'failed to parent', e continue