def apply( self, mapping, copyTangencyData=True ): if not isinstance( mapping, strUtils.Mapping ): mapping = strUtils.Mapping( *mapping ) targetNodeInitialRotateOrderDict = self._getTargetNodeInitialRotateOrderDict( mapping ) postCmdDict = {} if self._processPostCmds: for tgt in mapping.tgts: postCmdDict[ tgt ] = PostTraceNode( tgt ) if self._keysOnly: keyServer = NodeKeyServer( mapping.keys() ) else: keyServer = iterAtTimes( range( self._start, self._end, self._skip ) ) nodes = mapping.keys() keyServer.getNodes = lambda: nodes startTime = None for keyTime in keyServer: if startTime is None: startTime = keyTime nodesAtTime = set( keyServer.getNodes() ) for node, targetNode in mapping.iteritems(): if node not in nodesAtTime: continue pos = xform( node, q=True, ws=True, rp=True ) rot = xform( node, q=True, ws=True, ro=True ) move( pos[0], pos[1], pos[2], targetNode, ws=True, a=True, rpr=True ) rotateOrderMatches, storedRotateOrder, targetRotateOrderStr = targetNodeInitialRotateOrderDict[ targetNode ] #if the rotation order is different, we need to compensate - we check because its faster if we don't have to compensate if rotateOrderMatches: rotate( rot[0], rot[1], rot[2], targetNode, ws=True, a=True ) else: setAttr( '%s.ro' % targetNode, storedRotateOrder ) rotate( rot[0], rot[1], rot[2], targetNode, ws=True, a=True ) xform( targetNode, rotateOrder=targetRotateOrderStr, preserve=True ) if targetNode in postCmdDict: postCmdDict[targetNode].execute() if keyTime is not None: setKeyframe( targetNode, at=TransformClip._ATTRS ) endTime = keyTime if copyTangencyData: for src, tgt in mapping.iteritems(): srcCurves = cmd.listConnections( src, type='animCurve', d=False, c=True ) or [] iterSrcCurves = iter( srcCurves ) for srcAttrpath in iterSrcCurves: srcCurve = iterSrcCurves.next() attrname = '.'.join( srcAttrpath.split( '.' )[ 1: ] ) destAttrpath = '%s.%s' % (tgt, attrname) TangencyCopier( srcAttrpath, destAttrpath ).copy( startTime, endTime )
def testTracer(self): sphere = self.createAnimatedSphere() cube = self.createCube() tracer = animClip.Tracer() mapping = strUtils.Mapping([sphere], [cube]) tracer.apply(mapping) keyServer = animClip.NodeKeyServer([sphere, cube]) for keyTime in keyServer: if keyTime is None: continue nodes = keyServer.getNodes() assert sphere in nodes and cube in nodes #cast to vectors as the vector comparison test deals with floating point shinanigans posA = vectors.Vector(xform(sphere, q=True, ws=True, rp=True)) posB = vectors.Vector(xform(cube, q=True, ws=True, rp=True)) assert posA == posB
def matchNames(srcObjs, tgtObjs): namespaces = getNamespacesFromStrings(tgtObjs) tgtObjsSet = set(tgtObjs) mappedTgts = [] namespacesToTest = [] for namespace in namespaces: namespaceToks = [ tok for tok in namespace.split('|')[-1].split(':') if tok ] for n, tok in enumerate(namespaceToks): namespacesToTest.append(':'.join(namespaceToks[:n + 1])) for srcObj in srcObjs: #see if the exact source is in the target list if srcObj in tgtObjsSet: mappedTgts.append(srcObj) #if not see if we're able to prepend the given namespace else: sourceNodeToks = srcObj.split('|')[-1].split(':') nodeName = sourceNodeToks[-1] foundCandidate = False for candidateNamespace in namespacesToTest: candidate = '%s:%s' % (candidateNamespace, nodeName) if candidate in tgtObjsSet: mappedTgts.append(candidate) foundCandidate = True break if not foundCandidate: if nodeName in tgtObjsSet: mappedTgts.append(nodeName) else: mappedTgts.append('') return strUtils.Mapping(srcObjs, mappedTgts)