Exemple #1
0
def returnBaseControlSize(mi_obj, mesh, axis=True, closestInRange=True):
    """ 
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Figure out the base size for a control from a point in space within a mesh

    ARGUMENTS:
    mi_obj(cgmObject instance)
    mesh(obj) = ['option1','option2']
    axis(list) -- what axis to check

    RETURNS:
    axisDistances(dict) -- axis distances, average
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    try:  #>>Figure out the axis to do
        log.info(mi_obj)
        mi_obj = cgmMeta.validateObjArg(mi_obj,
                                        cgmMeta.cgmObject,
                                        noneValid=True)
        if not mi_obj:
            raise ValueError, "mi_obj kw: {0} ".format(mi_obj)

        _str_func = "returnBaseControlSize(%s)" % mi_obj.p_nameShort
        log.debug(">> %s " % (_str_func) + "=" * 75)
        start = time.clock()

        log.debug("%s >> mesh: %s " % (_str_func, mesh))
        log.debug("%s >> axis: %s " % (_str_func, axis))

        try:
            d_axisToDo = {}
            if axis == True:
                axis = ['x', 'y', 'z']
            if type(axis) in [list, tuple]:
                for a in axis:
                    if a in dictionary.stringToVectorDict.keys():
                        if list(a)[0] in d_axisToDo.keys():
                            d_axisToDo[list(a)[0]].append(a)
                        else:
                            d_axisToDo[list(a)[0]] = [a]

                    elif type(a) is str and a.lower() in ['x', 'y', 'z']:
                        buffer = []
                        buffer.append('%s+' % a.lower())
                        buffer.append('%s-' % a.lower())
                        d_axisToDo[a.lower()] = buffer
                    else:
                        log.warning("Don't know what with: '%s'" % a)
            log.debug("%s >> d_axisToDo: %s " % (_str_func, d_axisToDo))
            if not d_axisToDo: return False
        except Exception, error:
            raise Exception, "Axis check | {0}".format(error)

        #>>
        d_returnDistances = {}
        for axis in d_axisToDo:
            log.debug("Checking: %s" % axis)
            directions = d_axisToDo[axis]
            if len(directions) == 1:  #gonna multiply our distance
                try:
                    info = RayCast.findMeshIntersectionFromObjectAxis(
                        mesh, mi_obj.mNode, directions[0])
                    d_returnDistances[axis] = (
                        distance.returnDistanceBetweenPoints(
                            info['near'], mi_obj.getPosition()) * 2)
                except Exception, error:
                    raise Exception, "raycast | %s" % error
            else:
                try:
                    info1 = RayCast.findMeshIntersectionFromObjectAxis(
                        mesh, mi_obj.mNode, directions[0])
                    info2 = RayCast.findMeshIntersectionFromObjectAxis(
                        mesh, mi_obj.mNode, directions[1])
                    if info1 and info2:
                        d_returnDistances[
                            axis] = distance.returnDistanceBetweenPoints(
                                info1['near'], info2['near'])
                except Exception, error:
                    raise Exception, "raycast | %s" % error
obj = mc.ls(sl=True)[0] or False
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+')
Exemple #3
0
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>RayCast Functions =============================================================================================
#Gonna start with some functions found in cgm.core.lib.rayCaster

#findMeshIntersectionFromObjectAxis ==============================================================
'''
This function is for basic casting from actual objects in maya. 
They call on the raw cast functions but it's easier to work with stuff you can 
see when starting out
'''
str_castTo = str_mesh  #Link our mesh as our current object
reload(RayCast)

#1) Do our first cast --------------------------------------------------------------------------------
mi_aimObj.tz = 20
RayCast.findMeshIntersectionFromObjectAxis(str_castTo, mi_aimObj.mNode)
# Result: {} #
#This is gonna return us an empty result because our aim object is not in the sphere and not aiming at, let's aim it...

#2) Cast it again --------------------------------------------------------------------------------
mi_aimObj.ry = 180  #Flip our aim object
RayCast.findMeshIntersectionFromObjectAxis(str_castTo, mi_aimObj.mNode)
# Result: {'source': [0.0, 0.0, 20.0], 'uv': [0.7000001072883606, 0.5], 'hit': [0.0, -9.4730781774936761e-17, 10.000000953674316]} #
#Now, you'll see we're getting our return dict. We return to a dict because we want a more info

#3) Using that info to do something helpful. Let's cast one more time and store it to a holder --------------------------------------------------------------------------------
d_return = RayCast.findMeshIntersectionFromObjectAxis(str_castTo,
                                                      mi_aimObj.mNode)

#4) Just for kicks, let's report that info to get used to that little function --------------------------------------------------------------------------------
report_dict(d_return)
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>RayCast Functions =============================================================================================
#Gonna start with some functions found in cgm.core.lib.rayCaster

#findMeshIntersectionFromObjectAxis ==============================================================
'''
This function is for basic casting from actual objects in maya. 
They call on the raw cast functions but it's easier to work with stuff you can 
see when starting out
'''
str_castTo = str_mesh #Link our mesh as our current object
reload(RayCast)

#1) Do our first cast --------------------------------------------------------------------------------
mi_aimObj.tz = 20
RayCast.findMeshIntersectionFromObjectAxis(str_castTo,mi_aimObj.mNode)
# Result: {} # 
#This is gonna return us an empty result because our aim object is not in the sphere and not aiming at, let's aim it...

#2) Cast it again --------------------------------------------------------------------------------
mi_aimObj.ry = 180#Flip our aim object
RayCast.findMeshIntersectionFromObjectAxis(str_castTo,mi_aimObj.mNode)
# Result: {'source': [0.0, 0.0, 20.0], 'uv': [0.7000001072883606, 0.5], 'hit': [0.0, -9.4730781774936761e-17, 10.000000953674316]} # 
#Now, you'll see we're getting our return dict. We return to a dict because we want a more info

#3) Using that info to do something helpful. Let's cast one more time and store it to a holder --------------------------------------------------------------------------------
d_return = RayCast.findMeshIntersectionFromObjectAxis(str_castTo,mi_aimObj.mNode)

#4) Just for kicks, let's report that info to get used to that little function --------------------------------------------------------------------------------
report_dict(d_return)
Exemple #5
0
            hit = False

            #shoot our ray, store the hit
            log.debug("Casting: %i>>%f"%(i,rotateValue))
            mc.setAttr("%s.rotate%s"%(mi_rotObj.mNode,latheAxis.capitalize()),rotateValue)
            log.debug(mc.getAttr("%s.rotate%s"%(mi_rotObj.mNode,latheAxis.capitalize())) )

            #mi_rotObj.__setattr__('rotate%s'%latheAxis.capitalize(),rotateValue)
            try:
                log.debug("mesh: %s"%mesh)
                log.debug("mi_loc.mNode: %s"%mi_loc.mNode)
                log.debug("aimAxis: %s"%aimAxis)
                log.debug("latheAxis: %s"%latheAxis)
                log.debug("maxDistance: %s"%maxDistance)

                d_castReturn = RayCast.findMeshIntersectionFromObjectAxis(mesh, mi_loc.mNode, axis=aimAxis, maxDistance = maxDistance, firstHit=False) or {}
                d_hitReturnFromValue[rotateValue] = d_castReturn	
                if closestInRange:
                    hit = d_castReturn.get('near') or False
                else:
                    hit = d_castReturn.get('far') or False
                if not hit:log.info("{0} -- {1}".format(rotateValue,d_castReturn))

                """if closestInRange:
		    try:
			d_castReturn = RayCast.findMeshIntersectionFromObjectAxis(mesh, mi_loc.mNode, axis=aimAxis, maxDistance = maxDistance) or {}
		    except StandardError,error:
			log.error("createMeshSliceCurve >> closestInRange error : %s"%error)
			return False
		    log.debug("closest in range castReturn: %s"%d_castReturn)		
		    d_hitReturnFromValue[rotateValue] = d_castReturn	
from cgm.lib import locators
from cgm.lib import distance
reload(distance)
from cgm.core.lib import rayCaster as RayCast
reload(RayCast)

obj = mc.ls(sl=True)[0] or False
obj = ''
objList = []

#>>> Distance
#=======================================================
i_obj = cgmMeta.cgmObject(mc.ls(sl=True)[0])
i_obj.getPosition()
mesh = 'Morphy_Body_GEO'
RayCast.findMeshIntersectionFromObjectAxis(mesh,i_obj.mNode)
info = RayCast.findMeshIntersectionFromObjectAxis(mesh,i_obj.mNode,vector = [0,-1,0])
log.info(info)
info = distance.findMeshIntersection(mesh,i_obj.getPosition(), vector)
vector = [matrix[9],matrix[10],matrix[11]]
vector = [matrix[8],matrix[9],matrix[10]]#Z
vector = [-matrix[8],-matrix[9],-matrix[10]]#Z
RayCast.findMeshIntersectionFromObjectAxis(mesh,i_obj.mNode,axis = 'z-')
locators.doLocPos(info['hit'])
for axis in ['x+','x-','z+','z-']:
    locators.doLocPos(RayCast.findMeshIntersectionFromObjectAxis(mesh,i_obj.mNode,axis = axis)['hit'])

matrix = mc.xform(i_obj.mNode, q=True,  matrix=True, worldSpace=True)
matrix
len(matrix)
Exemple #7
0
def returnBaseControlSize(mi_obj,mesh,axis=True):
    """ 
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Figure out the base size for a control from a point in space within a mesh

    ARGUMENTS:
    mi_obj(cgmObject instance)
    mesh(obj) = ['option1','option2']
    axis(list) -- what axis to check
    
    RETURNS:
    axisDistances(dict) -- axis distances, average
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """       
    try:#>>Figure out the axis to do
	log.info(mi_obj)	
	mi_obj = cgmMeta.validateObjArg(mi_obj,cgmMeta.cgmObject,noneValid = True)
	if not mi_obj:
	    raise ValueError,"mi_obj kw: {0} ".format(mi_obj)
	
	_str_funcName = "returnBaseControlSize(%s)"%mi_obj.p_nameShort
	log.debug(">> %s "%(_str_funcName) + "="*75)
	start = time.clock()
	
	log.debug("%s >> mesh: %s "%(_str_funcName,mesh))  
	log.debug("%s >> axis: %s "%(_str_funcName,axis)) 
	
	try:
	    d_axisToDo = {}
	    if axis == True:
		axis = ['x','y','z']
	    if type(axis) in [list,tuple]:
		for a in axis:
		    if a in dictionary.stringToVectorDict.keys():
			if list(a)[0] in d_axisToDo.keys():
			    d_axisToDo[list(a)[0]].append( a )
			else:
			    d_axisToDo[list(a)[0]] = [ a ]
			     
		    elif type(a) is str and a.lower() in ['x','y','z']:
			buffer = []
			buffer.append('%s+'%a.lower())
			buffer.append('%s-'%a.lower())  
			d_axisToDo[a.lower()] = buffer
		    else:
			log.warning("Don't know what with: '%s'"%a)
	    log.debug("%s >> d_axisToDo: %s "%(_str_funcName,d_axisToDo))  
	    if not d_axisToDo:return False	    
	except Exception,error:
	    raise Exception,"Axis check | {0}".format(error)
	
	
	#>>
	d_returnDistances = {}
	for axis in d_axisToDo:
	    log.debug("Checking: %s"%axis)
	    directions = d_axisToDo[axis]
	    if len(directions) == 1:#gonna multiply our distance 
		try:
		    info = RayCast.findMeshIntersectionFromObjectAxis(mesh,mi_obj.mNode,directions[0])
		    d_returnDistances[axis] = (distance.returnDistanceBetweenPoints(info['hit'],mi_obj.getPosition()) *2)
		except Exception,error:
		    raise Exception,"raycast | %s"%error
	    else:
		try:
		    info1 = RayCast.findMeshIntersectionFromObjectAxis(mesh,mi_obj.mNode,directions[0])
		    info2 = RayCast.findMeshIntersectionFromObjectAxis(mesh,mi_obj.mNode,directions[1])
		    if info1 and info2:
			d_returnDistances[axis] = distance.returnDistanceBetweenPoints(info1['hit'],info2['hit'])                    
		except Exception,error:
		    raise Exception,"raycast | %s"%error
Exemple #8
0
	    #shoot our ray, store the hit
	    log.debug("Casting: %i>>%f"%(i,rotateValue))
	    mc.setAttr("%s.rotate%s"%(mi_rotObj.mNode,latheAxis.capitalize()),rotateValue)
	    log.debug(mc.getAttr("%s.rotate%s"%(mi_rotObj.mNode,latheAxis.capitalize())) )
	    
	    #mi_rotObj.__setattr__('rotate%s'%latheAxis.capitalize(),rotateValue)
	    try:
		log.debug("mesh: %s"%mesh)
		log.debug("mi_loc.mNode: %s"%mi_loc.mNode)
		log.debug("aimAxis: %s"%aimAxis)
		log.debug("latheAxis: %s"%latheAxis)
		log.debug("maxDistance: %s"%maxDistance)
		
		if closestInRange:
		    try:
			d_castReturn = RayCast.findMeshIntersectionFromObjectAxis(mesh, mi_loc.mNode, axis=aimAxis, maxDistance = maxDistance) or {}
		    except StandardError,error:
			log.error("createMeshSliceCurve >> closestInRange error : %s"%error)
			return False
		    log.debug("closest in range castReturn: %s"%d_castReturn)		
		    d_hitReturnFromValue[rotateValue] = d_castReturn	
		    log.debug("From %s: %s" %(rotateValue,d_castReturn))
			
		else:
		    d_castReturn = RayCast.findMeshIntersectionFromObjectAxis(mesh, mi_loc.mNode, axis=aimAxis, maxDistance = maxDistance, singleReturn=False) or {}
		    log.debug("castReturn: %s"%d_castReturn)
		    if d_castReturn.get('hits'):
			closestPoint = distance.returnFurthestPoint(mi_loc.getPosition(),d_castReturn.get('hits')) or False
			d_castReturn['hit'] = closestPoint
			log.debug("From %s: %s" %(rotateValue,d_castReturn))
		    
from cgm.lib import locators
from cgm.lib import distance
reload(distance)
from cgm.core.lib import rayCaster as RayCast
reload(RayCast)

obj = mc.ls(sl=True)[0] or False
obj = ''
objList = []

#>>> Distance
#=======================================================
i_obj = cgmMeta.cgmObject(mc.ls(sl=True)[0])
i_obj.getPosition()
mesh = 'Morphy_Body_GEO'
RayCast.findMeshIntersectionFromObjectAxis(mesh, i_obj.mNode)
info = RayCast.findMeshIntersectionFromObjectAxis(mesh,
                                                  i_obj.mNode,
                                                  vector=[0, -1, 0])
log.info(info)
info = distance.findMeshIntersection(mesh, i_obj.getPosition(), vector)
vector = [matrix[9], matrix[10], matrix[11]]
vector = [matrix[8], matrix[9], matrix[10]]  #Z
vector = [-matrix[8], -matrix[9], -matrix[10]]  #Z
RayCast.findMeshIntersectionFromObjectAxis(mesh, i_obj.mNode, axis='z-')
locators.doLocPos(info['hit'])
for axis in ['x+', 'x-', 'z+', 'z-']:
    locators.doLocPos(
        RayCast.findMeshIntersectionFromObjectAxis(mesh,
                                                   i_obj.mNode,
                                                   axis=axis)['hit'])