当前位置: 首页>>代码示例>>Python>>正文


Python cmds.draggerContext函数代码示例

本文整理汇总了Python中maya.cmds.draggerContext函数的典型用法代码示例。如果您正苦于以下问题:Python draggerContext函数的具体用法?Python draggerContext怎么用?Python draggerContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了draggerContext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: drag

 def drag(self, *args):
     
     self.dragPoint = mc.draggerContext(self.draggerContext, query=True, dragPoint=True)
     
     #if this doesn't work, try getmodifier
     self.modifier = mc.draggerContext(self.draggerContext, query=True, modifier=True)
     
     self.x = ((self.dragPoint[0] - self.anchorPoint[0]) * self.multiplier) + self.defaultValue
     self.y = ((self.dragPoint[1] - self.anchorPoint[1]) * self.multiplier) + self.defaultValue
     
     if self.minValue is not None and self.x < self.minValue:
         self.x = self.minValue
     if self.maxValue is not None and self.x > self.maxValue:
         self.x = self.maxValue
     
     #dragString
     if self.modifier == 'control':
         if self.button == 1:
             self.dragControlLeft(*args)
         elif self.button == 2:
             self.dragControlMiddle(*args)
     elif self.modifier == 'shift':
         if self.button == 1:
             self.dragShiftLeft(*args)
         elif self.button == 2:
             self.dragShiftMiddle(*args)
     else:
         if self.button == 1:
             self.dragLeft()
         elif self.button == 2:
             self.dragMiddle()
     
     mc.refresh()
开发者ID:Bumpybox,项目名称:Tapp,代码行数:33,代码来源:ml_utilities.py

示例2: __init__

 def __init__(self,
             name = 'mlDraggerContext',
             title = 'Dragger',
             defaultValue=0,
             minValue=None,
             maxValue=None,
             multiplier=0.01,
             cursor='hand'
             ):
     
     self.multiplier = multiplier
     self.defaultValue = defaultValue
     self.minValue = minValue
     self.maxValue = maxValue
     self.cycleCheck = mc.cycleCheck(query=True, evaluation=True)
     
     self.draggerContext = name
     if not mc.draggerContext(self.draggerContext, exists=True):
         self.draggerContext = mc.draggerContext(self.draggerContext)
                                                 
     mc.draggerContext(self.draggerContext, edit=True,
                     pressCommand=self.press, 
                     dragCommand=self.drag,
                     releaseCommand=self.release,
                     cursor=cursor,
                     drawString=title,
                     undoMode='all'
                     )
开发者ID:Bumpybox,项目名称:Tapp,代码行数:28,代码来源:ml_utilities.py

示例3: TraceGestureRelease

    def TraceGestureRelease( self ):
        """ when the mouse is released, find the matching joint trajectory """
        if debug>0: print("begin RELEASE")
        releasePosition = Vector( mc.draggerContext( 'TraceGesture', query=True, dragPoint=True) ).projectToPlane( self.trace[self.nearestRoot].normal, planePt=self.trace[self.nearestRoot].planePt )
        if debug>0: print "release! ", releasePosition
        theTrace = self.trace[self.nearestRoot]
        selectedMotion = None
        if theTrace.closestJoint and theTrace.timespan and (theTrace.timespan[1]-theTrace.timespan[0]) > 1 and \
           not mc.draggerContext( 'TraceGesture', query=True, modifier=True) == "ctrl":        
            theDTW = theTrace.dtws[theTrace.closest]
            if debug > 0:
                print "closest = ", theTrace.closestJoint, theTrace.timespan
                if not mc.objExists("DTW_Y"):
                    mc.group(n="DTW_Y",empty=True)
                for pt in theDTW.Y:
                    loc = mc.spaceLocator(p=pt)
                    mc.parent(loc,"DTW_Y")
        ##    ghostJoint(trace[nearestRoot].closestJoint,trace[nearestRoot].timespan)

            # Build the motion curve and store it's name in the selectedMotions dictionary
            duration = [ int(theTrace.timespan[0]), int(theTrace.timespan[1]+1) ]
            keyframes = [ theTrace.searchList[theTrace.closestJoint].points[frame] for frame in range(duration[0],duration[1]) ]
            selectedMotion = bmt.CurveMotionTrace( theTrace.closestJoint, keys=keyframes ) #duration=theTrace.timespan )
            
        else:
            self.ScrubToNearestTimeOnPath( releasePosition, self.nearestRoot, self.nearestPath )
            cam2pop = self.CameraToPopDist()
            path = theTrace.searchList[self.nearestPath]
            pointKey = path.ClosestTimeTo(releasePosition)
            closestPoint = path.points[pointKey]
            closestPtOnPath = closestPoint.projectToPlane( theTrace.normal, planePt=theTrace.planePt )
            mouse2path = (releasePosition - closestPtOnPath).mag()
            # if motion paths are visible and no drag happened
            # and releasePosition is very close to the path,
            # then select the whole motion path
            if self.motionPathsVisible[self.nearestRoot] and mouse2path < 0.3:  
                # Build the motion curve and store it's name in the selectedMotions dictionary
                duration = [ mc.playbackOptions(q=True,min=True),mc.playbackOptions(q=True,max=True)+1 ]
                keyframes = [ theTrace.searchList[self.nearestPath].points[frame] for frame in range(duration[0],duration[1]) ]
                selectedMotion = bmt.CurveMotionTrace( self.nearestPath, keys=keyframes ) #duration=[mc.playbackOptions(q=True,min=True),mc.playbackOptions(q=True,max=True)] )

            # if not scrubbing
            if not mc.draggerContext( 'TraceGesture', query=True, modifier=True) == "ctrl" and \
               cam2pop >= self.viewFitDistance:      # if trucked out, and mouse is clicked (w/ no drag)
                mc.select(self.nearestRoot)     # zoom in on the nearest root for a better view
                mc.viewFit(fitFactor=2.5)            # the invisible parts of the roots can artificially enlarge the BB, so truck in a little extra
                mc.select(clear=True)
        if selectedMotion:
            selectedMotionCurve = selectedMotion.construct(self.nearestPath)
            
            if not self.nearestRoot in self.selectedMotions.keys():
                self.selectedMotions[self.nearestRoot] = []
            mc.setAttr("%s_MotionTraces.visibility"%self.nearestRoot, 0)
            selectedMotionCurve = mc.rename(selectedMotionCurve, "%s_selection%d"%(self.nearestPath,len(self.selectedMotions[self.nearestRoot])))
            self.selectedMotions[self.nearestRoot].append( selectedMotionCurve )
            self.AddCustomAttr( selectedMotionCurve, "isTraceSelection", True )
            self.AddCustomAttr( selectedMotionCurve, "interactTime", time.time()-self.startTime )
            self.AddCustomAttr( selectedMotionCurve, "startFrame", duration[0] )
            self.AddCustomAttr( selectedMotionCurve, "endFrame", duration[1] )
        mc.select(cl=True)
开发者ID:jeisenma,项目名称:traceSelectionInMaya,代码行数:60,代码来源:traceSelectTool.py

示例4: getProjectedPoint

 def getProjectedPoint(self, dragged):
     '''
     gets the mouse position (in screen coordinates) 
     and finds the projected point on the plane that is parallel to the camera (in world coordinates).
     '''               
     # if we first clicked inside the viewport
     if not dragged:
         
         mousePosition = cmds.draggerContext(self._mContext, query = True, anchorPoint = True)
         self._mView.viewToWorld(int(mousePosition[0]), int(mousePosition[1]), self._mRayPos, self._mRayDir)           
         self.setOriginPoint()                                       
     
     # if we are dragging the mouse                
     else:
         
         if self._mOriginPt:
             
             mousePosition = cmds.draggerContext(self._mContext, query = True, dragPoint = True)
             modifier = cmds.draggerContext(self._mContext, query = True, modifier = True)
             
             self._mView.viewToWorld(int(mousePosition[0]), int(mousePosition[1]), self._mNear, self._mFar)
             self.planeLineIntersection(self._mNear, self._mFar, self._mOriginPt, self._mEye)
             
             mRadius = self._mOriginPt.distanceTo(self._mDragPt)
             cmds.setAttr(self._mVoroImpactShape + '.radius', mRadius)
             cmds.setAttr(self._mVoroImpactTrs + '.visibility', True)
             
             if modifier == 'shift':
                 cmds.setAttr(self._mVoroImpactShader + '.color', 1.0, 0.0, 0.0, type = 'double3')
                 cmds.setAttr(self._mVoroImpactShader + '.incandescence', 0.15, 0.0, 0.0, type = 'double3')
                 cmds.setAttr(self._mVoroImpactTrs + '.overrideColor', 13)
             else:
                 cmds.setAttr(self._mVoroImpactShader + '.color', 0.0, 1.0, 0.0, type = 'double3')
                 cmds.setAttr(self._mVoroImpactShader + '.incandescence', 0.0, 0.15, 0.0, type = 'double3')
                 cmds.setAttr(self._mVoroImpactTrs + '.overrideColor', 14)                     
开发者ID:jeffhong21,项目名称:scripts,代码行数:35,代码来源:IShatterCTX.py

示例5: __init__

    def __init__(self, uioptions, transformoptions, sourcelist, targetlist):
        '''
        initial setup
        '''
        #create the tool context
        if (mc.draggerContext(spPaint3dContextID, exists=True)):
            mc.deleteUI(spPaint3dContextID);
        mc.draggerContext(spPaint3dContextID, pressCommand=self.onPress, dragCommand=self.onDrag, releaseCommand=self.onRelease, name=spPaint3dContextID, cursor='crossHair', undoMode='step')

        #create context local options
        self.runtimeUpdate(uioptions, transformoptions, sourcelist, targetlist)

        #debug purpose
        self.reentrance = 0

        #initialise world up vector
        if ( (mc.upAxis(q=True, axis=True)) == "y" ):
            self.worldUp = om.MVector (0,1,0);
        elif ( (mc.upAxis(q=True, axis=True)) == "z" ):
            self.worldUp = om.MVector (0,0,1);
        else:
            #can't figure out up vector
            mc.confirmDialog(title='Weird stuff happening', message='Not getting any proper info on what the current up vector is. Quitting...')
            sys.exit()

        #fetch current scene unit
        self.unit = mc.currentUnit(query=True, linear=True)
开发者ID:utsdab,项目名称:usr,代码行数:27,代码来源:spPaint3dContext.py

示例6: buildUI

	def buildUI(self) :
		self.resetExternalContext()

		self.window = cmds.window("autorigging_ui", title="Auto-rigging (BB, EL, TP)", w=self.width, h=self.height)
		
		# Title
		cmds.columnLayout(w=self.width, h=self.height)
		cmds.separator(h=10)
		cmds.text(label="Autorigging", w=self.width,h=20, backgroundColor=[0.15,0.15,0.15])
		cmds.separator(h=10)

		# Mesh selector
		self.meshSelector = cmds.optionMenu(w=self.width,h=30,label="Choisissez un Mesh :")
		for m in cmds.ls(type="transform"):
			cmds.menuItem(label=str(m))

		cmds.separator(h=40)

		# Point buttons
		cmds.scrollLayout(w=self.width)
		self.definePointButtons()
		

		# Action buttons (enter mode)
		cmds.setParent("..")
		cmds.setParent("..") # Here to exit scrollLayout
		cmds.separator(h=10)
		cmds.rowLayout(numberOfColumns=3)
		self.activateButton = cmds.button("activetaBtn",
			label="Activer", 
			w=self.width/3 - 10, 
			h=self.pointButtonHeight,
			command=self.onActivateButtonClick
		)
		self.generateButton = cmds.button("generateBtn",
			label="Generer", 
			w=self.width/3 - 10, 
			h=self.pointButtonHeight,
			command=self.onGenerateButtonClick
		)
		self.autoGenerateButton = cmds.button("generateAutoRigBtn",
			label="AutoGenerer", 
			w=self.width/3 - 10, 
			h=self.pointButtonHeight,
			command=self.onAutoRigButtonClick
		)
		# Console
		
		cmds.setParent("..")
		cmds.columnLayout()
		cmds.separator(h=10)
		self.consoleText = cmds.text(label="Auto-rigging non-actif", width=self.width, height=50, backgroundColor=[0.3,0.3,0.3])

		cmds.showWindow(self.window)

		cmds.draggerContext("riggingContext", space="world", pressCommand=self.on3DSceneClick)
		
		# Registring context ?
		cmds.setToolTo("riggingContext")
开发者ID:LecomteEmerick,项目名称:MayaProject,代码行数:59,代码来源:autoriggin_ui.py

示例7: drag

 def drag(self):
     self.dragPoint = mc.draggerContext(self.name, query=True, dragPoint=True)
     self.button = mc.draggerContext( self.name, query=True, button=True)
     self.modifier = mc.draggerContext( self.name, query=True, modifier=True)
     
     self.x = self.dragPoint[0]
     self.y = self.dragPoint[1]
     self.z = self.dragPoint[2]
开发者ID:GuidoPollini,项目名称:MuTools,代码行数:8,代码来源:DraggerContextFactory.py

示例8: TraceGesturePress

    def TraceGesturePress( self ):
        """ Procedure called on press """
        if debug>0: print("begin PRESS")
        # Clean up: if there are any locators or groups in the scene, delete them
        if( len(mc.ls("locator*")) > 0 ):
            mc.delete(mc.ls("locator*"))
        if( len(mc.ls("*Grp")) > 0 ):
            mc.delete(mc.ls("*Grp"))

        # find the position of the mouse click
        pressPosition = Vector( mc.draggerContext( 'TraceGesture', query=True, anchorPoint=True) )

        camPos = self.CameraPosition()
        viewAxis = self.CameraViewAxis()
        closestObj2Cam = self.FindNearestObjectToCamera()
        self.interactionPlane = Plane(viewAxis,closestObj2Cam)

        pressPosition = self.FindRayPlaneIntersect( camPos, pressPosition, self.interactionPlane )
        if debug > 0:
            mc.group(n="traceGrp",empty=True)
            loc = mc.spaceLocator(p=pressPosition)
            mc.parent(loc,"traceGrp")

        for root in self.xformRoots:
            # remember whether (or not) the motion paths for a root were visible when the interaction started
            self.motionPathsVisible[root] = mc.getAttr("%s_MotionTraces.visibility"%root)
            # set up all the traces
            self.trace[root].Clear()
            # set the trace normal to the viewing normal of the camera
            self.trace[root].normal = self.interactionPlane.normal #Vector( mc.xform(mc.lookThru(q=True), q=True, m=True)[8:11] )
            self.trace[root].planePt = self.interactionPlane.point #closestObj2Cam

        self.nearestRoot, rootDist = self.FindNearestRoot( pressPosition, self.interactionPlane )
        mc.setAttr("%s_MotionTraces.visibility"%self.nearestRoot, 1)   # vis the new display layer

        # make a group to hold the trace locators
        if debug > 0:
            mc.group(name="trace%sGrp"%self.nearestRoot,empty=True)
            loc = mc.spaceLocator(p=pressPosition)
            mc.parent(loc,"trace%sGrp"%self.nearestRoot)
        # reset the trace
        self.trace[self.nearestRoot].Clear()
        # start the timer
        self.startTime = time.time()
        # set the trace normal to the viewing normal of the camera
        self.trace[self.nearestRoot].normal = Vector( mc.xform(mc.lookThru(q=True), q=True, m=True)[8:11] )
        self.trace[self.nearestRoot].planePt = closestObj2Cam
                
        # add the initial click position to the trace
        self.trace[self.nearestRoot].AddPoint( pressPosition )
        
        self.nearestPath, pathDist = self.FindNearestMotionPath( pressPosition, self.nearestRoot )
        if not mc.draggerContext( 'TraceGesture', query=True, modifier=True) == "ctrl":
            self.trace[self.nearestRoot].SetUpDTWs()
            mc.refresh(currentView=True,force=True)
        if debug>0: print("end PRESS")
开发者ID:jeisenma,项目名称:traceSelectionInMaya,代码行数:56,代码来源:traceSelectTool.py

示例9: Dragger

	def Dragger(self, selection = 'NA' , historyName = '', speed = [0.01, .1, .0001] ):
		if selection == 'NA':
			self.selection = self.getSelection()
		else:
			self.selection = selection
		self.history = self.getHistory(self.selection, -1, historyName)
		self.attribute = self.history[-1] + Cache.currentAttribute
		try:
			cmds.draggerContext( 'dragTool', edit=True, pressCommand= partial(self.pressFunction), dragCommand= partial(self.dragFunction), finalize = partial(self.exitFunction),  undoMode = "step")
		except:
			cmds.draggerContext( 'dragTool', pressCommand= partial(self.pressFunction), dragCommand= partial(self.dragFunction), finalize = partial(self.exitFunction), undoMode = "step" )
		cmds.setToolTo( 'dragTool' )
开发者ID:jricker,项目名称:JR_Maya,代码行数:12,代码来源:JR_dragger_class.py

示例10: press

 def press(self):
     if not mc.draggerContext(self.name,query=True,exists=True): # if it exists, delete it       
         self.build
         self.setTool()            
     
     self.anchorPoint = mc.draggerContext(self.name, query=True, anchorPoint=True)
     self.modifier = mc.draggerContext(self.name, query=True, modifier=True)
     self.button = mc.draggerContext(self.name, query=True, button=True)
     
     self.x = self.anchorPoint[0]
     self.y = self.anchorPoint[1]
     self.z = self.anchorPoint[2]
开发者ID:GuidoPollini,项目名称:MuTools,代码行数:12,代码来源:DraggerContextFactory.py

示例11: pressEvent

    def pressEvent(self):
        button = cmds.draggerContext(DRAGGER, query=True, button=True)

        # Leave the tool by middle click
        if button == 2:
            cmds.setToolTo('selectSuperContext')
            return

        # Get clicked point in viewport screen space
        pressPosition = cmds.draggerContext(DRAGGER, query=True, ap=True)
        x = pressPosition[0]
        y = pressPosition[1]

        self.ANCHOR_POINT = [x, y]

        # Convert
        point_in_3d, vector_in_3d = convertTo3D(x, y)

        # Get MFnMesh of snap target
        targetDagPath = getDagPathFromScreen(x, y)

        # If draggin outside of objects
        if targetDagPath is None:
            return

        # Create new object to snap
        self.DUPLICATED = self.getNewObject()

        # Get origianl scale information
        self.SCALE_ORIG = cmds.getAttr(self.DUPLICATED + ".scale")[0]

        self.MATRIX_ORIG = cmds.xform(self.SOURCE, q=True, matrix=True)

        self.TARGET_FNMESH = OpenMaya.MFnMesh(targetDagPath)

        transformMatrix = self.getMatrix(
            point_in_3d,
            vector_in_3d,
            self.TARGET_FNMESH,
            self.SCALE_ORIG,
            self.MATRIX_ORIG)

        # Reset transform of current object
        cmds.setAttr(self.DUPLICATED + ".translate", *[0, 0, 0])

        location = [-i for i
                    in cmds.xform(self.DUPLICATED, q=True, ws=True, rp=True)]
        cmds.setAttr(self.DUPLICATED + ".translate", *location)
        cmds.makeIdentity(self.DUPLICATED, apply=True, t=True)

        # Apply transformMatrix to the new object
        cmds.xform(self.DUPLICATED, matrix=transformMatrix)
开发者ID:jonnybrowo,项目名称:miMayaUtils,代码行数:52,代码来源:duplicateOverSurface.py

示例12: overshoot

def overshoot(baseFrame='previous'):
	'''Input kan either be 'previous','next' or an integer'''
	
	global attrDict
	global deltaX
	global lastVal
	deltaX = 0
	lastVal = 0
	
	print "# Initializing drag"
	
	selList = mc.ls(sl=True)
	
	try:
		###	Checking userInput
		if baseFrame != 'previous' and baseFrame != 'next' and type(baseFrame) != type(123):
			raise QuitException, "# init >> Input is incorrect. Only supported inputs are 'previous', 'next' or an integer"
	
		###	Checking selection
		if selList != None:
			attrDict = calcAttrDiff(selList, baseFrame)
		else:
			raise QuitException, "# Init >> Nothing is selected"
			
		###	Initializing context
		if mc.draggerContext( 'overshootCtx', exists=True ) == 0:
			mc.draggerContext( "overshootCtx" )
			
		
		###	Checking script file name (execution namespace)
		if __name__ != '__main__':
			prefix = __name__ + '.'
		else:
			prefix = ''
			
		mc.draggerContext( 
			'overshootCtx', 
			edit=True,
			pressCommand= prefix + 'overshoot_OnPress()', 
			dragCommand= prefix + 'overshoot_OnDrag()', 
			releaseCommand= prefix + 'overshoot_EndDrag()',
			cursor='crossHair' 
			);
			
			
		mm.eval('storeLastAction( "restoreLastContext " + `currentCtx` )')
		mc.setToolTo( 'overshootCtx' )
		
	except QuitException, arg:
		print "### Tool terminated ###"
		if arg != None:
			print arg,
开发者ID:joetainment,项目名称:mmmmtools,代码行数:52,代码来源:OMT_to_overshoot.py

示例13: load

 def load(s):
     sel = cmds.ls(sl=True)
     if sel and sel[0] in s.valid:
         s.sel = sel[0]
         s.tool = cmds.currentCtx()
         s.myTool = "TempTool"
         if cmds.draggerContext(s.myTool, exists=True):
             cmds.deleteUI(s.myTool)
         cmds.draggerContext(s.myTool, name=s.myTool, pressCommand=s.click, cursor='hand')
         cmds.setToolTo(s.myTool)
         print "Make a selection"
     else:
         print "Nothing selected"
开发者ID:internetimagery,项目名称:RigTool,代码行数:13,代码来源:joints.py

示例14: press

 def press(self, *args):
     '''
     Be careful overwriting the press method in child classes, because of the undoInfo openChunk
     '''
     
     self.anchorPoint = mc.draggerContext(self.draggerContext, query=True, anchorPoint=True)
     self.button = mc.draggerContext(self.draggerContext, query=True, button=True)
     #dragString
     
     # This makes it so the script editor doesn't get spammed by a cycle in the puppet
     mc.cycleCheck(evaluation=False)
     
     # This turns off the undo queue until we're done dragging, so we can undo it.
     mc.undoInfo(openChunk=True)
开发者ID:Bumpybox,项目名称:Tapp,代码行数:14,代码来源:ml_utilities.py

示例15: pressFunction

	def pressFunction(self):
		self.attribute = self.history[-1] + Cache.currentAttribute # re-init the attribute in case cached has been switched
		self.modifier = cmds.draggerContext( 'dragTool', query=True, modifier=True)
		self.button = cmds.draggerContext('dragTool', query = True, button=True)
		self.attributeValue = cmds.getAttr( self.attribute )
		if cmds.currentUnit( query=True, linear=True ) == 'cm':
			self.speed = .01 # modifier for speed traveled through values while dragging
		elif cmds.currentUnit( query=True, linear=True ) == 'm':
			self.speed = .001 # modifier for speed traveled through values while dragging
		else:
			self.speed = .0001
		self.space = 'screen' # initialize the variable
		if isinstance(self.attributeValue, list): # only edit the space based on button if the attribute is a list value
			# If left click is used, then the space is set to (X,Y,Z) world based
			# If middle click is used, space is set to (X, Y) screen based
			if self.button == 1: # left button
				self.space = 'world' # tracking space used
				cmds.draggerContext( 'dragTool', edit=True, space = 'world')
			elif self.button == 2: # middle button
				self.space = 'screen' # tracking space used
				cmds.draggerContext( 'dragTool', edit=True, space = 'screen')
		else: # set to 'screen' as default if the attr isn't a list value
			cmds.draggerContext( 'dragTool', edit=True, space = 'screen')
		if self.modifier == 'ctrl':
			self.speed = self.speed * .01
		if self.modifier == 'shift':
			self.speed = self.speed * 10
		if len(self.dragDirection) > 0:
			self.dragDirection = []
开发者ID:jricker,项目名称:JR_Maya,代码行数:29,代码来源:JR_dragger_class.py


注:本文中的maya.cmds.draggerContext函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。