示例#1
0
    def _onDrag(self):
        '''
        This is called when the tool is dragged.
        Here we want to record the drag change then set a keyframe on the target attributes.
        '''

        # Grab the drag position
        dragPosition = pmc.draggerContext(animSketchTool.contextname,
                                          q=True,
                                          dragPoint=True)

        if self.singleAxis:
            # Subtract the initial position to get the difference
            if self.verticalControl:
                delta = dragPosition[1] - self.pressPosition[1]
            else:
                delta = dragPosition[0] - self.pressPosition[0]

            # If inverted, reverse the delta
            if self.inverted:
                delta *= -1

            # Scale the value and set the input value
            self.input = delta / (100 / self.sensitivity)
        else:
            self.lastInput = self.input
            self.input = dragPosition

        # Set a keyframe
        self._setKeys()
示例#2
0
 def onPress(self):
     """
     
     """
     pressPosition = pm.draggerContext(self.context, q=True, anchorPoint=True)
     worldPos, worldDir = spc.getViewportClick(pressPosition[0], pressPosition[1])
     intersected = spc.targetSurfaceLoopIntersect(self.meshList, worldPos, worldDir)
     self.addJoint(pm.dt.Point(intersected.hitPoint.x, intersected.hitPoint.y, intersected.hitPoint.z))
示例#3
0
    def runContext(self):
        """
        Set maya tool to this context
        """
        if pm.draggerContext(self.context, exists=True):
            pm.setToolTo(self.context)

        self.nextJoint()
示例#4
0
 def __init__(self, mesh, ui, grp):
     """
     mesh [PyNode.mesh] - mesh to place joints on
     mesh will be converted added to sp3dObjectList to be used for intersections
     """
     
     self.meshList = spg.sp3dObjectList('target')
     self.meshList.addObj(str(mesh))
     
     # create dragger context
     if pm.draggerContext('FaceJointPlacementContext', exists=True):
         pm.deleteUI('FaceJointPlacementContext')
         
     self.context = pm.draggerContext('FaceJointPlacementContext', pressCommand=self.onPress, name='FaceJointPlacementContext', cursor='crossHair')
     
     self.jointsList = ui.placerMapping
     
     self.targetMesh = mesh
     self.jointIndex = 0
     self.ui = ui
     self.grp = grp
     
     self.camera = pm.PyNode('persp')
示例#5
0
    def _onPress(self):
        '''
        This is called when the tool is first pressed down.
        Here we'll grab some initial values and create the callback
        '''

        # Grab the initial press position, we'll use this for reference
        self.pressPosition = pmc.draggerContext(animSketchTool.contextname,
                                                query=True,
                                                anchorPoint=True)

        # Create the timer callback, this will watch idle events when held down
        # We'll grab a reference to the id to remove later
        self.callbackID = om.MTimerMessage.addTimerCallback(
            1 / self.framerate, self._onIdleFrame)

        # Grab the start time, this way we can track the duration of the hold
        self.startTime = time.time()

        # Grab the current frame in the timeline to start from
        self.startFrame = pmc.currentTime(q=True)

        # Grab the start value for each target
        self.targetStartValues = [
            pmc.getAttr(target) for target in self.targets
        ]

        # Set the initial input value
        if self.singleAxis:
            self.input = 0
        else:
            self.lastInput = self.input
            self.input = self.pressPosition

        # Set a keyframe at the frame just before the startFrame
        for target in self.targets:
            pmc.setKeyframe(target, t=self.startFrame)

        # Begin the scrub, this way sound will play
        pmc.timeControl(self.playbackSlider, edit=True, beginScrub=True)
示例#6
0
    def create(self,
               targets,
               sensitivity=1.0,
               timeScale=1.0,
               singleAxis=False,
               simplify=True,
               verticalControl=True,
               tolerance=0.05,
               inverted=False,
               framerate=24):

        # Set each of the tool settings
        self.targets = targets
        self.target = pmc.PyNode(self.targets[0].split('.')[0])
        self.framerate = framerate
        self.sensitivity = sensitivity
        self.timeScale = timeScale
        self.singleAxis = singleAxis
        self.simplify = simplify
        self.verticalControl = verticalControl
        self.tolerance = tolerance
        self.playbackSlider = maya.mel.eval('$tmpVar=$gPlayBackSlider')
        self.inverted = inverted

        # Set up default input values
        self.lastInput = (0, 0, 0)
        self.input = 0

        # Check if an existing dragger context exists, if so, delete it
        if (pmc.draggerContext(animSketchTool.contextname, exists=True)):
            pmc.deleteUI(animSketchTool.contextname)

        # Create the dragger context. This will create a new tool that watches for drag events
        if singleAxis:

            # Determine the cursor shape based on the direction
            if self.verticalControl:
                cursor = 'dolly'
            else:
                cursor = 'track'

            # Create the dragger context with the correct space and cursor shape
            pmc.draggerContext(animSketchTool.contextname,
                               pressCommand=self._onPress,
                               dragCommand=self._onDrag,
                               cursor=cursor,
                               releaseCommand=self._onRelease,
                               undoMode='step',
                               image1='/MotionBlur.png')
        else:

            # Create the dragger context with space set to 'world'
            pmc.draggerContext(animSketchTool.contextname,
                               pressCommand=self._onPress,
                               dragCommand=self._onDrag,
                               cursor='hand',
                               releaseCommand=self._onRelease,
                               undoMode='step',
                               image1='/MotionBlur.png',
                               space='world')

        # Set the currentTool
        pmc.setToolTo(animSketchTool.contextname)