Beispiel #1
0
 def on_reference(self, theFile):
     referenceFile(theFile, 'ref')
Beispiel #2
0
	def on_reference( self, theFile ):
		referenceFile( theFile, 'ref' )
Beispiel #3
0
def buildRigForModel( scene=None, referenceModel=True, deletePlacers=False ):
	'''
	given a model scene whose skeleton is assumed to have been built by the
	skeletonBuilder tool, this function will create a rig scene by referencing
	in said model, creating the rig as best it knows how, saving the scene in
	the appropriate spot etc...
	'''

	#if no scene was passed, assume we're acting on the current scene
	if scene is None:
		scene = Path( cmd.file( q=True, sn=True ) )
	#if the scene WAS passed in, open the desired scene if it isn't already open
	else:
		scene = Path( scene )
		curScene = Path( cmd.file( q=True, sn=True ) )
		if curScene:
			if scene != curScene:
				mel.saveChanges( 'file -f -open "%s"' % scene )
		else: cmd.file( scene, f=True, open=True )

	#if the scene is still none bail...
	if not scene and referenceModel:
		raise SceneNotSavedError( "Uh oh, your scene hasn't been saved - Please save it somewhere on disk so I know where to put the rig.  Thanks!" )

	#backup the current state of the scene, just in case something goes south...
	if scene.exists():
		backupFilename = scene.up() / ('%s_backup.%s' % (scene.name(), scene.getExtension()))
		if backupFilename.exists():
			backupFilename.delete()

		cmd.file( rename=backupFilename )
		cmd.file( save=True, force=True )
		cmd.file( rename=scene )

	#finalize
	failedParts = finalizeAllParts()
	if failedParts:
		confirmDialog( t='Finalization Failure', m='The following parts failed to finalize properly:\n\n%s' % '\n'.join( map( str, failedParts ) ), b='OK', db='OK' )
		return

	#delete placers if desired - NOTE: this should be done after after finalization because placers are often used to define alignment for end joints
	if deletePlacers:
		for part in SkeletonPart.IterAllParts():
			placers = part.getPlacers()
			if placers:
				delete( placers )

	#if desired, create a new scene and reference in the model
	if referenceModel:

		#remove any unknown nodes in the scene - these cause maya to barf when trying to save
		unknownNodes = ls( type='unknown' )
		if unknownNodes:
			delete( unknownNodes )

		#scene.editoradd()
		cmd.file( f=True, save=True )
		cmd.file( f=True, new=True )

		referenceFile( scene, 'model' )

		#rename the scene to the rig
		rigSceneName = '%s_rig.ma' % scene.name()
		rigScene = scene.up() / rigSceneName
		cmd.file( rename=rigScene )
		cmd.file( f=True, save=True, typ='mayaAscii' )
	else:
		rigScene = scene

	buildRigForAllParts()
	setupMirroring()

	return rigScene