Beispiel #1
0
def writeExportDict( toolName=None, toolVersion=None, **kwargs ):
	'''
	wraps the filesystem method of the same name - and populates the dict with maya
	specific data
	'''
	d = filesystem.writeExportDict( toolName, toolVersion, **kwargs )
	d[ kEXPORT_DICT_SCENE ] = cmd.file( q=True, sn=True )
	d[ kEXPORT_DICT_APP_VERSION ] = cmd.about( version=True )

	return d
Beispiel #2
0
def writeExportDict(toolName=None, toolVersion=None, **kwargs):
    '''
	wraps the filesystem method of the same name - and populates the dict with maya
	specific data
	'''
    d = filesystem.writeExportDict(toolName, toolVersion, **kwargs)
    d[kEXPORT_DICT_SCENE] = cmd.file(q=True, sn=True)
    d[kEXPORT_DICT_APP_VERSION] = cmd.about(version=True)

    return d
Beispiel #3
0
def getWeightsFromDmx( dmxFilepath=None ):
	'''
	loads a dmx and gathers weight data from the meshes present.  the data returned can be fed to the
	applyWeights function to effectively transfer skinning data between meshes of differing topology
	'''
	geoAndData = {}

	#define the data we're gathering
	joints = {}
	jointHierarchies = {}
	weightData = []
	weightDataAppend = weightData.append


	#load the dmx file
	dmxFilepath = DmxFile( dmxFilepath )
	root = dmxFilepath.read()
	model = root.model


	#data gathering time!
	for mesh in dmxedit.MeshIt( model ):
		meshName = mesh.name
		state = mesh.currentState
		try:
			jointWeights = state.jointWeights
			jointIndices = state.jointIndices
		except AttributeError: continue

		jointList = getJointList( mesh )
		jointCount = state.jointCount
		for idx, pos in enumerate( state.positions ):
			baseIdx = idx * jointCount

			#generate the weight list first because if the weight is zero, the jointIndex can potentially be bogus
			weightList = [ jointWeights[ baseIdx + n ] for n in range( jointCount ) ]
			jointIdxList = [ jointIndices[ baseIdx + n ] for n in range( jointCount ) ]

			jointNameList = []
			append = jointNameList.append
			for n, jIdx in enumerate( jointIdxList ):
				try: append( jointList[ jIdx ].name )
				except IndexError:
					assert weightList[ n ] < 1e-6, "weighting refers to a non-existant joint"
					append( jointList[ 0 ].name )


			#so this is kinda dumb - but using a dict here we can easily remap on restore if joint names
			#are different by storing the dict's value as the joint to use, and the key as the joint that
			#the vert was originally weighted to
			for j in jointNameList:
				joints[ j ] = j

			pos = pos.x, pos.y, pos.z
			vertData = VertSkinWeight( pos )
			vertData.populate( meshName, idx, jointNameList, weightList)
			weightDataAppend( vertData )


	#sort the weightData by ascending x values so we can search faster
	weightData = sortByIdx( weightData )


	#generate joint hierarchy data - so if joints are missing on load we can find the best match
	for elt in jointList:
		jointHierarchies[ elt.name ] = [ p for p in iterParents( elt, True ) ]


	#generate the misc data for the weights
	miscData = writeExportDict( TOOL_NAME, TOOL_VERSION, kEXPORT_DICT_SOURCE=dmxFilepath )


	return WeightSaveData( (miscData, joints, jointHierarchies, weightData) )