Beispiel #1
0
def getJointBounds(joints, threshold=0.65, space=SPACE_OBJECT):
    '''
	if the joints are skinned, then the influenced verts that have weights greater than the given
	influenced are transformed into the space specified (if SPACE_OBJECT is used, the space of the
	first joint is used), and the bounds of the verts in this space are returned as a 2-tuple of
	bbMin, bbMax
	'''

    global MVector, MTransformationMatrix, Vector

    if not isinstance(joints, (list, tuple)):
        joints = [joints]

    theJoint = joints[0]
    verts = []

    for j in joints:
        verts += meshUtils.jointVertsForMaya(j, threshold)

    jointDag = api.getMDagPath(theJoint)

    if space == SPACE_OBJECT:
        jointMatrix = jointDag.inclusiveMatrix()
    elif space == SPACE_LOCAL:
        jointMatrix = jointDag.exclusiveMatrix()
    elif space == SPACE_WORLD:
        jointMatrix = OpenMaya.MMatrix()
    else:
        raise TypeError("Invalid space specified")

    vJointPos = MTransformationMatrix(jointMatrix).rotatePivot(
        kWorld) + MTransformationMatrix(jointMatrix).getTranslation(kWorld)
    vJointPos = Vector([vJointPos.x, vJointPos.y, vJointPos.z])

    vJointBasisX = MVector(-1, 0, 0) * jointMatrix
    vJointBasisY = MVector(0, -1, 0) * jointMatrix
    vJointBasisZ = MVector(0, 0, -1) * jointMatrix

    bbox = MBoundingBox()
    for vert in verts:
        #get the position relative to the joint in question
        vPos = Vector(xform(vert, query=True, ws=True, t=True))
        vPos = vJointPos - vPos

        #now transform the joint relative position into the coordinate space of that joint
        #we do this so we can get the width, height and depth of the bounds of the verts
        #in the space oriented along the joint
        vPosInJointSpace = Vector(vPos)
        vPosInJointSpace = vPosInJointSpace.change_space(
            vJointBasisX, vJointBasisY, vJointBasisZ)

        bbox.expand(MPoint(*vPosInJointSpace))

    bbMin, bbMax = bbox.min(), bbox.max()
    bbMin = Vector([bbMin.x, bbMin.y, bbMin.z])
    bbMax = Vector([bbMax.x, bbMax.y, bbMax.z])

    return bbMin, bbMax
Beispiel #2
0
def getJointBounds( joints, threshold=0.65, space=SPACE_OBJECT ):
	'''
	if the joints are skinned, then the influenced verts that have weights greater than the given
	influenced are transformed into the space specified (if SPACE_OBJECT is used, the space of the
	first joint is used), and the bounds of the verts in this space are returned as a 2-tuple of
	bbMin, bbMax
	'''

	global MVector, MTransformationMatrix, Vector

	if not isinstance( joints, (list, tuple) ):
		joints = [ joints ]

	theJoint = joints[ 0 ]
	verts = []

	for j in joints:
		verts += meshUtils.jointVertsForMaya( j, threshold )

	jointDag = api.getMDagPath( theJoint )

	if space == SPACE_OBJECT:
		jointMatrix = jointDag.inclusiveMatrix()
	elif space == SPACE_LOCAL:
		jointMatrix = jointDag.exclusiveMatrix()
	elif space == SPACE_WORLD:
		jointMatrix = OpenMaya.MMatrix()
	else: raise TypeError( "Invalid space specified" )

	vJointPos = MTransformationMatrix( jointMatrix ).rotatePivot( kWorld ) + MTransformationMatrix( jointMatrix ).getTranslation( kWorld )
	vJointPos = Vector( [vJointPos.x, vJointPos.y, vJointPos.z] )

	vJointBasisX = MVector(-1,0,0) * jointMatrix
	vJointBasisY = MVector(0,-1,0) * jointMatrix
	vJointBasisZ = MVector(0,0,-1) * jointMatrix

	bbox = MBoundingBox()
	for vert in verts:
		#get the position relative to the joint in question
		vPos = Vector( xform( vert, query=True, ws=True, t=True ) )
		vPos = vJointPos - vPos

		#now transform the joint relative position into the coordinate space of that joint
		#we do this so we can get the width, height and depth of the bounds of the verts
		#in the space oriented along the joint
		vPosInJointSpace = Vector( vPos )
		vPosInJointSpace = vPosInJointSpace.change_space( vJointBasisX, vJointBasisY, vJointBasisZ )

		bbox.expand( MPoint( *vPosInJointSpace ) )

	bbMin, bbMax = bbox.min(), bbox.max()
	bbMin = Vector( [bbMin.x, bbMin.y, bbMin.z] )
	bbMax = Vector( [bbMax.x, bbMax.y, bbMax.z] )

	return bbMin, bbMax
Beispiel #3
0
    def on_selectVerts(self, *a):
        selJoints = self.UI_tsl.getSelectedItems()
        if not selJoints:
            return

        verts = []
        for j in selJoints:
            verts += meshUtils.jointVertsForMaya(j)

        if verts:
            cmd.hilite([self._mesh])
            cmd.select(verts)
            mel.artAttrSkinToolScript(4)
	def on_selectVerts( self, *a ):
		selJoints = self.UI_tsl.getSelectedItems()
		if not selJoints:
			return

		verts = []
		for j in selJoints:
			verts += meshUtils.jointVertsForMaya( j )

		if verts:
			cmd.hilite( [ self._mesh ] )
			cmd.select( verts )
			mel.artAttrSkinToolScript( 4 )
Beispiel #5
0
    def on_selectIntersectingVerts(self, *a):
        selJoints = self.UI_tsl.getSelectedItems()
        if not selJoints:
            return

        allVerts = []
        jointVerts = {}

        for j in selJoints:
            jointVerts[j] = verts = meshUtils.jointVertsForMaya(j)
            allVerts += verts

        allVerts = set(allVerts)

        commonVerts = []
        for j, jVerts in jointVerts.iteritems():
            commonVerts += allVerts.intersection(set(jVerts))

        if commonVerts:
            cmd.hilite([self._mesh])
            cmd.select(commonVerts)
            mel.artAttrSkinToolScript(4)
	def on_selectIntersectingVerts( self, *a ):
		selJoints = self.UI_tsl.getSelectedItems()
		if not selJoints:
			return

		allVerts = []
		jointVerts = {}

		for j in selJoints:
			jointVerts[ j ] = verts = meshUtils.jointVertsForMaya( j )
			allVerts += verts

		allVerts = set( allVerts )

		commonVerts = []
		for j, jVerts in jointVerts.iteritems():
			commonVerts += allVerts.intersection( set( jVerts ) )

		if commonVerts:
			cmd.hilite( [ self._mesh ] )
			cmd.select( commonVerts )
			mel.artAttrSkinToolScript( 4 )