Exemplo n.º 1
0
    def doMove(self,**kws):
	if kws:log.debug("Snap.doMove>>> kws: %s"%kws)
	if len(self.l_targets) == 1:
	    #>>> Check our target	    
	    i_target = cgmMeta.cgmNode( self.l_targets[0] )
	    log.debug("i_target: %s"%i_target)
	    targetType = i_target.getMayaType()	    

	    if self.b_snapComponents:
		components = self.i_obj.getComponents()
		if not components:raise StandardError,"This objects has no components to snap: '%s'"%self.i_obj.getShortName()
		#>>>Progress bar
		mayaMainProgressBar = gui.doStartMayaProgressBar(len(components))		
		for c in components:
		    if mc.progressBar(mayaMainProgressBar, query=True, isCancelled=True ) :
			break
		    mc.progressBar(mayaMainProgressBar, edit=True, status = ("Wrapping '%s'"%c), step=1)
		    
		    if targetType in ['mesh','nurbsSurface','nurbsCurve']:
			pos = distance.returnWorldSpacePosition(c)
			targetLoc = mc.spaceLocator()
			mc.move (pos[0],pos[1],pos[2], targetLoc[0])

			closestLoc = locators.locClosest([targetLoc[0]],i_target.mNode)
			if self._posOffset:
			    self.doOrientObjToSurface(i_target.mNode,closestLoc)
			    mc.move (self._posOffset[0],self._posOffset[1],self._posOffset[2], [closestLoc], r=True, rpr = True, os = True, wd = True)								
			position.movePointSnap(c,closestLoc)
			mc.delete([targetLoc[0],closestLoc])
			
		gui.doEndMayaProgressBar(mayaMainProgressBar)#Close out this progress bar    
		
	    else:
		pos = False
		if self.b_snaptoSurface:#>>> If our target is surface we can use
		    if targetType in ['mesh','nurbsCurve','nurbsSurface']:
			i_locObj = self.i_obj.doLoc()#Get our position loc
			i_locTarget = cgmMeta.cgmObject( locators.locClosest([i_locObj.mNode],i_target.mNode) )#Loc closest
			#i_locObj.rename('objLoc')
			#i_locTarget.rename('targetLoc')
			if self._posOffset:
			    try:
				self.doOrientObjToSurface(i_target.mNode,i_locTarget.mNode)
				mc.move (self._posOffset[0],self._posOffset[1],self._posOffset[2], [i_locTarget.mNode], r=True, rpr = True, os = True, wd = True)								
			    except StandardError,error:
				log.warn("self._posOffset failure!")
				log.error(error)
			
			pos = i_locTarget.getPosition(True)
			i_locObj.delete()
			i_locTarget.delete()
		elif self.b_midSurfacePos:
		    log.debug("Snap.move>>> midSurfacePos mode!")
		    if targetType not in ['mesh','nurbsCurve','nurbsSurface']:
			log.warning("Can't do midSurfacPos on targetType: '%s'"%targetType)
			return False
		    #Get the axis info
		    axisToCheck = kws.pop('axisToCheck',False)
		    if not axisToCheck:
			axisToCheck = []		    
			up = dictionary.returnVectorToString(self._upVector) or False
			if not up:
			    raise StandardError,"SnapFactory>>> must have up vector for midSurfaceSnap: %s"%self._upVector
			for a in ['x','y','z']:
			    if a != up[0]:
				axisToCheck.append(a)
			if not axisToCheck:
			    raise StandardError,"SnapFactory>>> couldn't find any axis to do"
		    #i_locObj = self.i_obj.doLoc()#Get our position loc		
		    #log.debug(axisToCheck)
		    pos = RayCast.findMeshMidPointFromObject(i_target.mNode, self.i_obj.mNode, axisToCheck=axisToCheck,**kws)
		    #i_locObj.delete()
		    
		else:
		    pos = i_target.getPosition(True)	    
		if pos:
		    if self.i_obj.isComponent():
			if self.b_softSelection:#Only need to do this if soft select is on
			    mc.softSelect(softSelectEnabled = True)
			    mc.select(self.i_obj.getComponent())
			    mc.move (pos[0],pos[1],pos[2],rpr=True)
			    mc.select(cl=True)
			else:
			    mc.move (pos[0],pos[1],pos[2], self.i_obj.getComponent())	    		    
		    else:
			mc.move (pos[0],pos[1],pos[2], self.i_obj.mNode, rpr=True)	    
Exemplo n.º 2
0
    def doMove(self, **kws):
        if kws: log.debug("Snap.doMove>>> kws: %s" % kws)
        if len(self.l_targets) == 1:
            #>>> Check our target
            i_target = cgmMeta.cgmNode(self.l_targets[0])
            log.debug("i_target: %s" % i_target)
            targetType = i_target.getMayaType()

            if self.b_snapComponents:
                components = self.i_obj.getComponents()
                if not components:
                    raise StandardError, "This objects has no components to snap: '%s'" % self.i_obj.getShortName(
                    )
                #>>>Progress bar
                mayaMainProgressBar = gui.doStartMayaProgressBar(
                    len(components))
                for c in components:
                    if mc.progressBar(mayaMainProgressBar,
                                      query=True,
                                      isCancelled=True):
                        break
                    mc.progressBar(mayaMainProgressBar,
                                   edit=True,
                                   status=("Wrapping '%s'" % c),
                                   step=1)

                    if targetType in ['mesh', 'nurbsSurface', 'nurbsCurve']:
                        pos = distance.returnWorldSpacePosition(c)
                        targetLoc = mc.spaceLocator()
                        mc.move(pos[0], pos[1], pos[2], targetLoc[0])

                        closestLoc = locators.locClosest([targetLoc[0]],
                                                         i_target.mNode)
                        if self._posOffset:
                            self.doOrientObjToSurface(i_target.mNode,
                                                      closestLoc)
                            mc.move(self._posOffset[0],
                                    self._posOffset[1],
                                    self._posOffset[2], [closestLoc],
                                    r=True,
                                    rpr=True,
                                    os=True,
                                    wd=True)
                        position.movePointSnap(c, closestLoc)
                        mc.delete([targetLoc[0], closestLoc])

                gui.doEndMayaProgressBar(
                    mayaMainProgressBar)  #Close out this progress bar

            else:
                pos = False
                if self.b_snaptoSurface:  #>>> If our target is surface we can use
                    if targetType in ['mesh', 'nurbsCurve', 'nurbsSurface']:
                        i_locObj = self.i_obj.doLoc()  #Get our position loc
                        i_locTarget = cgmMeta.cgmObject(
                            locators.locClosest([i_locObj.mNode],
                                                i_target.mNode))  #Loc closest
                        #i_locObj.rename('objLoc')
                        #i_locTarget.rename('targetLoc')
                        if self._posOffset:
                            try:
                                self.doOrientObjToSurface(
                                    i_target.mNode, i_locTarget.mNode)
                                mc.move(self._posOffset[0],
                                        self._posOffset[1],
                                        self._posOffset[2],
                                        [i_locTarget.mNode],
                                        r=True,
                                        rpr=True,
                                        os=True,
                                        wd=True)
                            except StandardError, error:
                                log.warn("self._posOffset failure!")
                                log.error(error)

                        pos = i_locTarget.getPosition(True)
                        i_locObj.delete()
                        i_locTarget.delete()
                elif self.b_midSurfacePos:
                    log.debug("Snap.move>>> midSurfacePos mode!")
                    if targetType not in [
                            'mesh', 'nurbsCurve', 'nurbsSurface'
                    ]:
                        log.warning(
                            "Can't do midSurfacPos on targetType: '%s'" %
                            targetType)
                        return False
                    #Get the axis info
                    axisToCheck = kws.pop('axisToCheck', False)
                    if not axisToCheck:
                        axisToCheck = []
                        up = dictionary.returnVectorToString(
                            self._upVector) or False
                        if not up:
                            raise StandardError, "SnapFactory>>> must have up vector for midSurfaceSnap: %s" % self._upVector
                        for a in ['x', 'y', 'z']:
                            if a != up[0]:
                                axisToCheck.append(a)
                        if not axisToCheck:
                            raise StandardError, "SnapFactory>>> couldn't find any axis to do"
                    #i_locObj = self.i_obj.doLoc()#Get our position loc
                    #log.debug(axisToCheck)
                    pos = RayCast.findMeshMidPointFromObject(
                        i_target.mNode,
                        self.i_obj.mNode,
                        axisToCheck=axisToCheck,
                        **kws)
                    #i_locObj.delete()

                else:
                    pos = i_target.getPosition(True)
                if pos:
                    if self.i_obj.isComponent():
                        if self.b_softSelection:  #Only need to do this if soft select is on
                            mc.softSelect(softSelectEnabled=True)
                            mc.select(self.i_obj.getComponent())
                            mc.move(pos[0], pos[1], pos[2], rpr=True)
                            mc.select(cl=True)
                        else:
                            mc.move(pos[0], pos[1], pos[2],
                                    self.i_obj.getComponent())
                    else:
                        mc.move(pos[0],
                                pos[1],
                                pos[2],
                                self.i_obj.mNode,
                                rpr=True)
Exemplo n.º 3
0
#7) Here's another sample to play with. Move the cast object around within the sphere and try some of these
for axis in ['x+','x-','z+','z-']:
    locators.doLocPos(RayCast.findMeshIntersectionFromObjectAxis(str_castTo,mi_aimObj.mNode,axis = axis)['hit'])
#===============================================================================================

#findMeshMidPointFromObject ==============================================================
'''
This function is for positioning objects in mesh iteratively 
'''

#1) Let's start by moving our caster object
mi_aimObj.translate = 6,2.5,1.5

#2) So let's start by playig with the caster
RayCast.findMeshMidPointFromObject(str_castTo,mi_aimObj.mNode, axisToCheck = ['x','z'],maxIterations=5)
# Result: [0.18749999999999992, 1.9396939318297912, -0.48360811199787312] # 
#So we get back a position in space..

#3) Let's feed that to our translate
mi_aimObj.translate = RayCast.findMeshMidPointFromObject(str_castTo,mi_aimObj.mNode, axisToCheck = ['x','z'],maxIterations=5)

#3) Play with moving the mi_aimObj around and reruning step 3. Play with the options as well

#=================================================================================================================
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>ShapeCast Functions =============================================================================================
#We're gonna look at some more functions which are one of the practical applications of rayCasting
obj = ''
objList = []

#>>
surface = 'skullPlate'
RayCast.findSurfaceIntersection(surface, [0, 0, 0], [0, 1, 0])

#>>> Distance
#=======================================================
i_obj = cgmMeta.cgmObject(mc.ls(sl=True)[0])
i_obj.getPosition()
mesh = 'Morphy_Body_GEO'
mesh = 'polySurface2'

RayCast.findMeshIntersectionFromObjectAxis(mesh, i_obj.mNode)
RayCast.findMeshMidPointFromObject(mesh, i_obj.mNode)
info = RayCast.findMeshIntersectionFromObjectAxis(mesh,
                                                  i_obj.mNode,
                                                  vector=[0, -1, 0])
RayCast.findMeshIntersectionFromObjectAxis(mesh,
                                           i_obj.mNode,
                                           'z+',
                                           singleReturn=False)
RayCast.findFurthestPointInRangeFromObject(mesh, i_obj.mNode, 'z+')
pos = RayCast.findMeshMidPointFromObject(mesh, i_obj.mNode, axisToCheck=['y'])
locators.doLocPos(pos)
obj = 'l_ankle_tmplObj'
mesh = '|Morphy_grp|noTransform_grp|geo_grp|base_geo_grp|Morphy_Body_GEO'
RayCast.findMeshIntersectionFromObjectAxis(mesh, obj, 'z+')

log.info(info)
Exemplo n.º 5
0
        RayCast.findMeshIntersectionFromObjectAxis(str_castTo,
                                                   mi_aimObj.mNode,
                                                   axis=axis)['hit'])
#===============================================================================================

#findMeshMidPointFromObject ==============================================================
'''
This function is for positioning objects in mesh iteratively 
'''

#1) Let's start by moving our caster object
mi_aimObj.translate = 6, 2.5, 1.5

#2) So let's start by playig with the caster
RayCast.findMeshMidPointFromObject(str_castTo,
                                   mi_aimObj.mNode,
                                   axisToCheck=['x', 'z'],
                                   maxIterations=5)
# Result: [0.18749999999999992, 1.9396939318297912, -0.48360811199787312] #
#So we get back a position in space..

#3) Let's feed that to our translate
mi_aimObj.translate = RayCast.findMeshMidPointFromObject(
    str_castTo, mi_aimObj.mNode, axisToCheck=['x', 'z'], maxIterations=5)

#3) Play with moving the mi_aimObj around and reruning step 3. Play with the options as well

#=================================================================================================================
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>ShapeCast Functions =============================================================================================