import maya.cmds as mc

from cgm.core import cgm_Meta as cgmMeta
from cgm.core import cgm_PuppetMeta as cgmPM
import Red9.core.Red9_Meta as r9Meta

from cgm.lib import locators
from cgm.lib import distance

reload(distance)

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'
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

locators.doLocPos(info['hit'])

matrix = mc.xform(i_obj.mNode, q=True, matrix=True, worldSpace=True)
matrix
len(matrix)
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)
info = RayCast.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,
Exemple #3
0
#6) What if we wanna have more than one hit returned as the ray goes through the object...let's change a flag
d_return = RayCast.findMeshIntersectionFromObjectAxis(str_castTo,
                                                      mi_aimObj.mNode,
                                                      singleReturn=False)
#Then let's loc those
for i, hit_point in enumerate(d_return.get('hits')):
    mc.spaceLocator(p=hit_point, name="hit_{0}".format(i))

#7) Does it work with nurbs?
str_castTo = str_surface  #Link to the surface and let's go back and do the same 1-6 above
#It does, awesome

#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'],
mc.spaceLocator(p = d_return.get('source'),name = "source_single")
#here we see our cast point of origin

#6) What if we wanna have more than one hit returned as the ray goes through the object...let's change a flag
d_return = RayCast.findMeshIntersectionFromObjectAxis(str_castTo,mi_aimObj.mNode,singleReturn = False)
#Then let's loc those
for i,hit_point in enumerate(d_return.get('hits')):
    mc.spaceLocator(p = hit_point,name = "hit_{0}".format(i))

#7) Does it work with nurbs?
str_castTo = str_surface#Link to the surface and let's go back and do the same 1-6 above
#It does, awesome

#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..
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)