コード例 #1
0
def transferRootJoint(src,dest):
    
    #This function is used to transfer the root joint
    #We don't have to convert this into another space.
    #we just copy the rotation and translation over
    
    
    
    
    firstFrame = pm.findKeyframe(src, which ='first')
    lastFrame = pm.findKeyframe(src, which = 'last')
    current = firstFrame
    pm.setCurrentTime(current)
    
    while current <= lastFrame:
        
        pm.setCurrentTime(current)
        
        dest.setTranslation(src.getTranslation())
        dest.setRotation(src.getRotation())   
        dest.rotate.setKey()
        dest.translate.setKey()
                    
        if current == lastFrame:
            break
    
        current = pm.findKeyframe(src , time = current, which='next')
コード例 #2
0
def bakeAnimFromOb(targetOb,bakeOb,startFrame,endFrame):
    f=startFrame
    while f<=endFrame:
        pm.setCurrentTime(f)
        alignOb(targetOb,bakeOb)
        pm.setKeyframe(bakeOb,at='translate')
        pm.setKeyframe(bakeOb,at='rotate')
        f+=1
コード例 #3
0
def bakeAnimTuple(tupleOb,startFrame,endFrame):
    f=startFrame
    while f<=endFrame:
        pm.setCurrentTime(f)
        for o in tupleOb:
            alignOb(o[0],o[1])
            pm.setKeyframe(o[1],at='translate')
            pm.setKeyframe(o[1],at='rotate')
        f+=1
コード例 #4
0
    def dist_curve_creator(self, from_zero):
        '''
        dist_curve_creator(self, from_zero)
        Create a distance curve that describes distance over time, either translation or rotation.
        Either set the beginning of the range or the end of the range to zero based on 'from_zero'
        '''
        # Ensure we have a Distance Curve
        self.target = pm.PyNode(self.target)
        maya_utils.anim_attr_utils.create_float_attr(self.target,
                                                     'DistanceCurve')

        # TRANSLATION
        if (self.use_translation(self.start_time, self.end_time)):
            if (from_zero == True):
                pm.setCurrentTime(self.start_time)
            else:
                pm.setCurrentTime(self.end_time)

            referencePos = self.target.getTranslation(space='world')
            for frame in xrange(self.start_time, self.end_time + 1):
                pm.setCurrentTime(frame)
                currPos = self.target.getTranslation(space='world')

                dist = currPos.distanceTo(referencePos)
                if (from_zero == True):
                    maya_utils.anim_attr_utils.set_attr_key(
                        self.target, 'DistanceCurve', dist)
                else:
                    maya_utils.anim_attr_utils.set_attr_key(
                        self.target, 'DistanceCurve', -dist)
        # ROTATION
        else:
            pm.setCurrentTime(self.end_time)
            referenceRot = pm.xform(self.target, q=True, ws=True, ro=True)

            for frame in range(self.start_time, self.end_time + 1):
                pm.setCurrentTime(frame)
                currRot = pm.xform(self.target, q=True, ws=True, ro=True)

                currX = abs(currRot[0] - referenceRot[0])
                currY = abs(currRot[1] - referenceRot[1])
                currZ = abs(currRot[2] - referenceRot[2])
                currAngle = maya_utils.anim_attr_utils.get_angle_from_euler(
                    currX, currY, currZ)

                maya_utils.anim_attr_utils.set_attr_key(
                    self.target, 'DistanceCurve', -currAngle)
コード例 #5
0
def SourceAnimation(keygiver):        
    ##Gets the first and last keyFrames
    first = pm.findKeyframe(keygiver, which='first')
    last = pm.findKeyframe(keygiver, which='last')
    
    for i in range(int(last+1)):
        pm.setCurrentTime(i)
        keygiver.translate.setKey()
        keygiver.rotate.setKey()
        keygiver.scale.setKey()
        
        for child in keygiver.getChildren():
            print child
            animation(child)
    
        ##Finds the next keyframe once the first keyframe has been set!
        i = pm.findKeyframe(keygiver, time=i, which='next')
コード例 #6
0
def SourceAnimation(keygiver):
    ##Gets the first and last keyFrames
    first = pm.findKeyframe(keygiver, which='first')
    last = pm.findKeyframe(keygiver, which='last')

    for i in range(int(last + 1)):
        pm.setCurrentTime(i)
        keygiver.translate.setKey()
        keygiver.rotate.setKey()
        keygiver.scale.setKey()

        for child in keygiver.getChildren():
            print child
            animation(child)

        ##Finds the next keyframe once the first keyframe has been set!
        i = pm.findKeyframe(keygiver, time=i, which='next')
コード例 #7
0
ファイル: Keyframes.py プロジェクト: Fanny94/Project_Erebus
def GetJointKeyframes(jointName):

    pm.select(jointName)

    curr = first = pm.findKeyframe(jointName, which='first')
    pm.setCurrentTime(first)

    last = pm.findKeyframe(jointName, which='last')
    kc = pm.keyframe(
        jointName, sl=False, q=True,
        keyframeCount=True) / 10  #THIS IS LOGICAL AND MAKES SENSE!

    #node.setKeyframe();

    print("\n")
    if (kc > 0):
        keyframeList = []

        while curr <= last:

            node = pm.PyNode(jointName)
            kf = Keyframe()
            kf.time = curr / 24

            kf.Scale = node.getScale()
            kf.rotation = node.getRotation()
            kf.translation = node.getTranslation()

            print kf.Scale[0]

            print("SCALE: " + str(kf.Scale))

            keyframeList.append(kf)
            if curr == last:
                return keyframeList

            curr = pm.findKeyframe(jointName, time=curr, which='next')
            pm.setCurrentTime(curr)

    else:
        print("No Keyframes in this animation layer")
コード例 #8
0
    def speed_curve_creator(self):
        '''
        speed_curve_creator(self)
        Create a speed curve that has the distance / time per frame
        '''
        #Ensure a Speed Curve exists
        self.target = pm.PyNode(self.target)
        maya_utils.anim_attr_utils.create_float_attr(self.target, 'SpeedCurve')

        fps = maya_utils.scene_utils.get_scene_fps()

        #handle first keyframe edge case
        pm.setCurrentTime(self.start_time + 1)
        currPos = self.target.getTranslation(space='world')

        pm.setCurrentTime(self.start_time)
        lastPos = self.target.getTranslation(space='world')
        speed = lastPos.distanceTo(currPos) / (1.0 / fps)
        maya_utils.anim_attr_utils.set_attr_key(self.target, 'SpeedCurve',
                                                speed)

        for frame in xrange(self.start_time + 1, self.end_time + 1):
            pm.setCurrentTime(frame)
            currPos = self.target.getTranslation(space='world')

            speed = lastPos.distanceTo(currPos) / (1.0 / fps)
            maya_utils.anim_attr_utils.set_attr_key(self.target, 'SpeedCurve',
                                                    speed)
            lastPos = currPos
コード例 #9
0
def transferRootJoint(src, dest):

    #This function is used to transfer the root joint
    #We don't have to convert this into another space.
    #we just copy the rotation and translation over

    firstFrame = pm.findKeyframe(src, which='first')
    lastFrame = pm.findKeyframe(src, which='last')
    current = firstFrame
    pm.setCurrentTime(current)

    while current <= lastFrame:

        pm.setCurrentTime(current)

        dest.setTranslation(src.getTranslation())
        dest.setRotation(src.getRotation())
        dest.rotate.setKey()
        dest.translate.setKey()

        if current == lastFrame:
            break

        current = pm.findKeyframe(src, time=current, which='next')
コード例 #10
0
 def __enter__(self):
     self.oldt = pmc.getCurrentTime()
     pmc.setCurrentTime(self.t)
コード例 #11
0
 def testAtTime(self):
     pmc.setCurrentTime(1)
     with at_time(2):
         self.assertEqual(pmc.getCurrentTime(), 2)
     self.assertEqual(pmc.getCurrentTime(), 1)
コード例 #12
0
 def testAtTime(self):
     pmc.setCurrentTime(1)
     with at_time(2):
         self.assertEqual(pmc.getCurrentTime(), 2)
     self.assertEqual(pmc.getCurrentTime(), 1)
コード例 #13
0
# Animation code
import pymel.core as pm
import time

root = pm.PyNode('iPi:Hip')

first = pm.findKeyframe(root, which='first')
last = pm.findKeyframe(root, which='last')

print first, last

curr = first

while curr <= last:
    curr = pm.findKeyframe(root, time=curr, which='next')
    pm.setCurrentTime(curr)
    # apply key values
    if curr==last:
        break
コード例 #14
0
ファイル: utils.py プロジェクト: 1fth3n3ls3/pylib
 def __exit__(self, *_):
     if self.oldt is not None:
         pmc.setCurrentTime(self.oldt)
コード例 #15
0
ファイル: MayaLib.py プロジェクト: mstroehle/PyFlow
 def setCurrentFrame(CurrentFrame=('IntPin', 0)):
     pm.setCurrentTime(CurrentFrame)
コード例 #16
0
def snap_label(label=None,
               restrict_to=None,
               start_time=None,
               end_time=None,
               key=True):
    """
    This will match all the members of the snap group.

    :param label: The name of the snap group to get the members from
    :type label: str

    :param restrict_to: If given, only group members which are also present
        within this list will be matched.
    :type restrict_to: pm.nt.Transform

    :param start_time: The time to start from. If this is not given then
        the match will only occur on the current frame
    :type start_time: int

    :param end_time: The time to stop at. If this is not given then the
        match will only occur on the current frame
    :type end_time: int

    :param key: If true the matching will be keyed. Note, if a start and
        end time are given then this is ignored and the motion will always
        be keyed.
    :type key: bool

    :return:
    """
    # -- Get a list of all the snap nodes with this label
    snap_nodes = members(label, from_nodes=restrict_to)

    # -- Use the current time if we're not given specific
    # -- frame ranges
    start_time = start_time if start_time is not None else int(
        pm.currentTime())
    end_time = end_time if end_time is not None else int(pm.currentTime())

    # -- Cycle the frame range ensuring we dont accidentally
    # -- drop off the last frame
    for frame in range(start_time, end_time + 1):
        pm.setCurrentTime(frame)

        for snap_node in snap_nodes:

            # -- NOTE: We *could* group the target/node together
            # -- outside the frame iteration as an optimisation. For
            # -- the sake of code simplicity on the first pass its
            # -- done during iteration.
            pass

            # -- Get the target node - if there is no target
            # -- we do nothing
            targets = snap_node.snapTarget.inputs()

            if not targets:
                continue

            # -- Pull out the target as a named variable for
            # -- code clarity
            target = targets[0]

            # -- Pull out the node to modify
            nodes = snap_node.snapSource.inputs()

            if not nodes:
                continue

            # -- Pull out the node as a named variable for
            # -- code clarity
            node = nodes[0]

            # -- Match the two objects with the offset matrix
            _set_worldspace_matrix(
                node,
                target,
                snap_node.offsetMatrix.get(),
            )

            # -- Get the list of nodes to reset
            if snap_node.hasAttr('nodesToZero'):
                zero_these = snap_node.nodesToZero.inputs()

                # -- Zero any nodes which require it
                for node_to_zero in zero_these:
                    _zero_node(node_to_zero)

                    if key or start_time != end_time:
                        pm.setKeyframe(node_to_zero)

            # -- Key the match if we need to
            if key or start_time != end_time:
                pm.setKeyframe(node)
コード例 #17
0
def snap(node, target, start_time=None, end_time=None, key=True):
    """
    This will match one node to the other providing there is a snap
    relationship between then. If a time range is given then the match
    will occur over time.

    If no snap relationship exists between the two nodes then a straight
    forward matrix matching will occur.

    :param node: The node to move
    :type node: pm.nt.Transform

    :param target: The node to match to
    :type target: pm.nt.Transform

    :param start_time: The time to start from. If this is not given then
        the match will only occur on the current frame
    :type start_time: int

    :param end_time: The time to stop at. If this is not given then the
        match will only occur on the current frame
    :type end_time: int

    :param key: If true the matching will be keyed. Note, if a start and
        end time are given then this is ignored and the motion will always
        be keyed.
    :type key: bool

    :return:
    """
    # -- Get the snaps between the two nodes
    snap_nodes = get(node, target=target)

    # -- If we have a snap, take the first and use that offset matrix
    # -- otherwise we use
    if snap_nodes:
        offset_matrix = snap_nodes[0].offsetMatrix.get()

    else:
        offset_matrix = pm.dt.Matrix()

    # -- Get the list of nodes to reset
    zero_these = list()
    if snap_nodes[0].hasAttr('nodesToZero'):
        zero_these = snap_nodes[0].nodesToZero.inputs()

    # -- Use the current time if we're not given specific
    # -- frame ranges
    start_time = start_time if start_time is not None else int(
        pm.currentTime())
    end_time = end_time if end_time is not None else int(pm.currentTime())

    # -- Cycle the frame range ensuring we dont accidentally
    # -- drop off the last frame
    for frame in range(start_time, end_time + 1):
        pm.setCurrentTime(frame)

        _set_worldspace_matrix(
            node,
            target,
            offset_matrix,
        )

        # -- Zero any nodes which require it
        for node_to_zero in zero_these:
            _zero_node(node_to_zero)

            if key or start_time != end_time:
                pm.setKeyframe(node_to_zero)

        # -- Check if we need to key
        if key or start_time != end_time:
            pm.setKeyframe(node)
コード例 #18
0
 def setCurrentFrame(CurrentFrame=("IntPin", 0)):
     pm.setCurrentTime(CurrentFrame)
コード例 #19
0
ファイル: test_utils.py プロジェクト: 1fth3n3ls3/pylib
 def testAtTime(self):
     pmc.setCurrentTime(1)
     with utils.atTime(2):
         print(type(pmc.getCurrentTime()))
         self.assertEqual(pmc.getCurrentTime(), 2)
     self.assertEqual(pmc.getCurrentTime(), 1)
コード例 #20
0
 def __exit__(self, *_):
     if self.oldt is not None:
         pmc.setCurrentTime(self.oldt)
コード例 #21
0
import pymel.core as pm
import maya.mel as mel

_isDefault = True
refFrame = ""  # if blank the reference frame will be the first of the timeline

objects = pm.ls(("*snow_geo", "*bark_geo"), type='transform',
                r=True) if (_isDefault) else pm.selected(type='transform')
mel.eval('playButtonStart()') if (refFrame
                                  == "") else pm.setCurrentTime(refFrame)
test = map(lambda obj: (obj + '_reference'), objects)

for obj in objects:
    pm.select(obj)
    mel.eval('CreateTextureReferenceObject()')

pm.group(test, n='Pref_textRefObj_grp')
コード例 #22
0
def InteractivePlayback():
    pm.setCurrentTime(pm.playbackOptions(q=True,minTime=True))
    mm.eval('InteractivePlayback;')
    pm.setCurrentTime(pm.playbackOptions(q=True,minTime=True))
コード例 #23
0
# Animation code
import pymel.core as pm
import time

root = pm.PyNode('iPi:Hip')

first = pm.findKeyframe(root, which='first')
last = pm.findKeyframe(root, which='last')

print first, last

curr = first

while curr <= last:
    curr = pm.findKeyframe(root, time=curr, which='next')
    pm.setCurrentTime(curr)
    # apply key values
    if curr == last:
        break
コード例 #24
0
def main(jointList, newJointList, hip, newHip):

    first = pm.findKeyframe(hip, which='first')
    last = pm.findKeyframe(hip, which='last')
    
    pm.setCurrentTime(0)
    
    parentList = []
    targetParentList = []
        
    parents(hip, dt.Matrix(), parentList, jointList)
    parents(newHip, dt.Matrix(), targetParentList, newJointList)
    
    i = 0
    a = 0
    
    identityMatrix = dt.Matrix()
    identityMatrix2 = dt.Matrix()
    
    while i < len(jointList):
        
        curr = first
        
        pm.setCurrentTime(0)
    
        pyJoint = pm.PyNode(jointList[i])
        targetJoint = pm.PyNode(newJointList[i])
        parentJoint = parentList[i]
        targetParentJoint = targetParentList[i]
        
        bindPoseInverse = pyJoint.getRotation().asMatrix().inverse()
        bindPose = pyJoint.getRotation().asMatrix()
        bindPoseTarget = targetJoint.getRotation().asMatrix()
    
        while curr <= last:
            curr = pm.findKeyframe(hip, time=curr, which='next')
            pm.setCurrentTime(curr)
            
            if i == 0:
               k =  pyJoint.getRotation().asMatrix() * bindPoseInverse
               
               kPrim = identityMatrix.setToIdentity().inverse() * k * identityMatrix2.setToIdentity()
               
               kPrim2 = parentList[i] * kPrim * parentList[i].inverse()
               
               final = bindPoseTarget * kPrim2
               
               targetJoint.setRotation(dt.degrees(dt.EulerRotation(final)))
                        
               targetJoint.setTranslation(pyJoint.getTranslation())
               
               pm.setKeyframe(targetJoint)
            else:
            ####################################HIP DONE###########################################
                
                bodyK = bindPoseInverse * pyJoint.getRotation().asMatrix()
                
                bodykPrim = parentList[i].inverse() * bodyK * parentList[i]
                
                bodykPrim2 =  targetParentList[i] * bodykPrim * targetParentList[i].inverse()
                
                bodyFinal =  bindPoseTarget * bodykPrim2
                
                targetJoint.setRotation(dt.degrees(dt.EulerRotation(bodyFinal)))
                
                pm.setKeyframe(targetJoint)
    
            
            # apply key values
            if curr==last:
                i = i + 1
                break   
コード例 #25
0
ファイル: utils.py プロジェクト: 1fth3n3ls3/pylib
 def __enter__(self):
     self.oldt = pmc.getCurrentTime()
     pmc.setCurrentTime(self.t)
コード例 #26
0
def transferOneJoint(src,dest):
    
    
    #get the upper most parent node of the source, If there is none it will return itself
    #This is done because we need the root node to to the change of basis
    srcRootNode = getRootNode(src)
    
    destRootNode = getRootNode(dest)


    
 
    if srcRootNode == src:
        #this checks if the root node is being processed
        #then we need to include the translation
        #we have another function only for the root node transformation
        transferRootJoint(src,dest)
        print "THIS IS THE ROOTNODE"
    
    
    
    else: #do the normal transfer
        
        
        firstFrame = pm.findKeyframe(src, which ='first') #Find first key frame
        lastFrame = pm.findKeyframe(src, which = 'last')  #Find the lat key frame
        current = firstFrame 
        pm.setCurrentTime(current) #Set current key frame to the first one
        
        
        #get the rotation of the source root in the first frame (IT's the bind pose)      Needed when changing basis 
        srcRootRotation = srcRootNode.getRotation().asMatrix()  
        
        #get the rotation of the destination root joint in the first frame. (Needed when changing basis to destination node)
        #destRootRotation = destRootNode.getRotation().asMatrix()
    
    
        #Get the bind pose of the destination joint. Needed when applying rotation to destination
        destRotation = dest.getRotation().asMatrix()            



        
        srcHierarcyMatrix = src.getRotation().asMatrix() 
        #This will be done on the first frame. 
        #A matrix of the hierarcys TPose will be returned
        #srcHierarchyMatrix is used to isolate the rotation from the source joint
        
        srcChangeofBasisMatrix = getChangeOfBasisMatrix(src)
        #This creates the matrix that is needed when we change the basis of the orientation
        #it is similar to the hierarchyMatrix, However, it is multiplicated in the reverse order, and it does not include the source joint orientation
        
        destChangeofBasisMatrix = getChangeOfBasisMatrix(dest)
        
    
    
        # Loop through the frames
        while current <= lastFrame:
    
            
            
        
            pm.setCurrentTime(current)
             
            srcRotation = getRotationFromJoint(src,srcHierarcyMatrix) #Extract the Rotation from the source, using the hierarchy matrix
            
            # Rotation is extracted from the joint, 
        
            #Now it needs to be transformed into standard coordinate space.
            #this is achieved by doing a change of basis.     
            # inv(srcChangeofBasisMatrix) * srcRotation * srcChangeofBasisMatrix
            srcRotation = srcChangeofBasisMatrix.inverse() * srcRotation * srcChangeofBasisMatrix
            
            
            #Now we need to transform it from the standard coordinate space to the space of the destination joint
            # (h * k * h-1 = k2)
            srcRotation = destChangeofBasisMatrix * srcRotation * destChangeofBasisMatrix.inverse()
            
            
            setRotationToJoint(srcRotation,dest,destRotation)            
    
            dest.rotate.setKey() #Set the keyframe!
            
            if current == lastFrame:
                break
        
            current = pm.findKeyframe(src , time = current, which='next') #Jump to next frame
コード例 #27
0
    for g in geo:
        export_deformer_weights(g, WORKING_DIR)

        # don't use single shader, use incandescence option

        #shader = [x for x in pm.ls(type="shadingEngine") if x.name() == 'initialShadingGroup'][0]
        #pm.sets(shader, forceElement=g)

        #lambert_to_flat(g)

        # remove skinCluster
        pm.delete(g, ch=1)

if True:
    shift_curves(joints, START_FRAME)
    pm.setCurrentTime(START_FRAME)
    apply_joint_orientations(joints)

# scale geometry and joints, freeze scale on geometry, use the translation method for joints
if True:
    scale_factor = GLOBAL_SCALE
    scale_joints(joints, scale_factor)
    scale_geo(geo, scale_factor)

# delete the construction history and import the exported weights
if True:
    pm.refresh()
    for g in geo:
        pm.delete(g, ch=1)
    import_deformer_weights(WORKING_DIR)
    pm.refresh()
コード例 #28
0
def transferOneJoint(src, dest):

    #get the upper most parent node of the source, If there is none it will return itself
    #This is done because we need the root node to to the change of basis
    srcRootNode = getRootNode(src)

    destRootNode = getRootNode(dest)

    if srcRootNode == src:
        #this checks if the root node is being processed
        #then we need to include the translation
        #we have another function only for the root node transformation
        transferRootJoint(src, dest)
        print "THIS IS THE ROOTNODE"

    else:  #do the normal transfer

        firstFrame = pm.findKeyframe(src, which='first')  #Find first key frame
        lastFrame = pm.findKeyframe(src, which='last')  #Find the lat key frame
        current = firstFrame
        pm.setCurrentTime(current)  #Set current key frame to the first one

        #get the rotation of the source root in the first frame (IT's the bind pose)      Needed when changing basis
        srcRootRotation = srcRootNode.getRotation().asMatrix()

        #get the rotation of the destination root joint in the first frame. (Needed when changing basis to destination node)
        #destRootRotation = destRootNode.getRotation().asMatrix()

        #Get the bind pose of the destination joint. Needed when applying rotation to destination
        destRotation = dest.getRotation().asMatrix()

        srcHierarcyMatrix = src.getRotation().asMatrix()
        #This will be done on the first frame.
        #A matrix of the hierarcys TPose will be returned
        #srcHierarchyMatrix is used to isolate the rotation from the source joint

        srcChangeofBasisMatrix = getChangeOfBasisMatrix(src)
        #This creates the matrix that is needed when we change the basis of the orientation
        #it is similar to the hierarchyMatrix, However, it is multiplicated in the reverse order, and it does not include the source joint orientation

        destChangeofBasisMatrix = getChangeOfBasisMatrix(dest)

        # Loop through the frames
        while current <= lastFrame:

            pm.setCurrentTime(current)

            srcRotation = getRotationFromJoint(
                src, srcHierarcyMatrix
            )  #Extract the Rotation from the source, using the hierarchy matrix

            # Rotation is extracted from the joint,

            #Now it needs to be transformed into standard coordinate space.
            #this is achieved by doing a change of basis.
            # inv(srcChangeofBasisMatrix) * srcRotation * srcChangeofBasisMatrix
            srcRotation = srcChangeofBasisMatrix.inverse(
            ) * srcRotation * srcChangeofBasisMatrix

            #Now we need to transform it from the standard coordinate space to the space of the destination joint
            # (h * k * h-1 = k2)
            srcRotation = destChangeofBasisMatrix * srcRotation * destChangeofBasisMatrix.inverse(
            )

            setRotationToJoint(srcRotation, dest, destRotation)

            dest.rotate.setKey()  #Set the keyframe!

            if current == lastFrame:
                break

            current = pm.findKeyframe(src, time=current,
                                      which='next')  #Jump to next frame
コード例 #29
0
ファイル: contexts.py プロジェクト: ldunham1/crab
 def __exit__(self, *exc_info):
     pm.setCurrentTime(self._time)
コード例 #30
0
 def setCurrentFrame(CurrentFrame=(DataTypes.Int, 0)):
     pm.setCurrentTime(CurrentFrame)