示例#1
0
	def build(self, scene, agentOptions):
		if scene.mas().terrainFile:
			self._factory.importObj(scene.mas().terrainFile, "terrain")
		
		MayaPlacement.build(self._factory, scene.mas())
		
		for agentSpec in scene.agentSpecs():
			agent = Agent.Agent(instanced=False)
			agent.agentSpec = agentSpec
			agent.name = agentSpec.agentType
			mayaAgent = MayaSceneAgent.MayaSceneAgent(agent, self._factory, scene)
			mayaAgent.build(agentOptions)
			self._factory.addAgent(mayaAgent)
		
		self._factory.cleanup()
		
		# The layers are off by default to speed up load, turn them on
		# now.
		#	
		MayaAgent.showLayers()
示例#2
0
    def build(self, scene, agentOptions):
        if scene.mas().terrainFile:
            self._factory.importObj(scene.mas().terrainFile, "terrain")

        MayaPlacement.build(self._factory, scene.mas())

        for agentSpec in scene.agentSpecs():
            agent = Agent.Agent(instanced=False)
            agent.agentSpec = agentSpec
            agent.name = agentSpec.agentType
            mayaAgent = MayaSceneAgent.MayaSceneAgent(agent, self._factory,
                                                      scene)
            mayaAgent.build(agentOptions)
            self._factory.addAgent(mayaAgent)

        self._factory.cleanup()

        # The layers are off by default to speed up load, turn them on
        # now.
        #
        MayaAgent.showLayers()
	def doIt(self,argList):
		argData = OpenMaya.MArgDatabase( self.syntax(), argList )

		options = self._parseArgs( argData )
		
		undoQueue = mc.undoInfo( query=True, state=True )

		try:
			try:
				mc.undoInfo( state=False )
				
				scene = Scene.Scene()
				
				file = options[kFileFlag]
				ext = os.path.splitext(file)[1]
				if ext == ".mas":
					scene.setMas(file)
				elif ext == ".cdl":
					scene.addCdl(file)
				else:
					raise npy.Errors.BadArgumentError( "Please provide a Massive setup (.mas) or agent (.cdl) file." )
				
				agentOptions = MayaAgent.Options()
				agentOptions.loadGeometry = options[kLoadGeometryFlag]
				agentOptions.loadPrimitives = options[kLoadSegmentsFlag]
				agentOptions.loadMaterials = options[kLoadMaterialsFlag]
				agentOptions.skinType = options[kSkinTypeFlag]
				agentOptions.instancePrimitives = options[kInstanceSegmentsFlag]
				agentOptions.materialType = options[kMaterialTypeFlag]
				
				mayaScene = MayaScene.MayaScene()
				mayaScene.build(scene, agentOptions)
			finally:
				mc.undoInfo( state=undoQueue )
		except npy.Errors.AbortError:
			self.displayError("Import cancelled by user")
		except:
			raise
示例#4
0
def dump(scene, target):
	agentSpec = AgentSpec.AgentSpec()
	MayaAgent.dump(agentSpec, target)
	scene.addAgentSpec(agentSpec)
示例#5
0
	def build(self, sim, animType, frameStep, cacheGeometry, cacheDir,
			  deleteSkeleton, agentOptions):
		if sim.scene.mas().terrainFile:
			self._factory.importObj(sim.scene.mas().terrainFile, "terrain")
			
		mayaAgents = []
		startFrame = -sys.maxint
		endFrame = -sys.maxint
		
		for agent in sim.agents():
			mayaAgent = MayaSimAgent.MayaSimAgent(agent, self._factory, sim)
			mayaAgent.build(agentOptions, animType, frameStep)
			
			# Presumably every agent will be simmed over the same frame
			# range - however since the frame ranges could conceivably
			# be different, find and and store the earliest startFrame
			# and latest endFrame
			#
			if mayaAgent.simData():
				if -sys.maxint == startFrame or mayaAgent.simData().startFrame < startFrame:
					startFrame = mayaAgent.simData().startFrame
				if -sys.maxint == endFrame or mayaAgent.simData().endFrame > endFrame:
					endFrame = mayaAgent.simData().endFrame
			
			mayaAgents.append(mayaAgent)

		if cacheGeometry:
			# Create geometry caches for each agent.
			#
			meshes = []
			for mayaAgent in mayaAgents:
				meshes.extend( [ geometry.shapeName() for geometry in mayaAgent.geometryData ] )
			cacheFileName = "%s_%s" % (sim.scene.baseName(), sim.range)
			
			mc.cacheFile( directory=cacheDir,
						  singleCache=True,
						  doubleToFloat=True,
						  format="OneFilePerFrame",
						  simulationRate=1,
						  sampleMultiplier=1,
						  fileName=cacheFileName,
						  startTime=startFrame,
						  endTime=endFrame,
						  points=meshes )
			
			# There's a bug in maya where cacheFile will sometimes write a
			# partial path into the cache instead of the full path. To makes
			# sure the attachFile works, we have to query the actual channel
			# names
			cacheFileFullName = "%s/%s.xml" % (cacheDir, cacheFileName)
			meshes = mc.cacheFile(query=True, fileName=cacheFileFullName, channelName=True)
			
			switches = [ maya.mel.eval( 'createHistorySwitch( "%s", false )' % mesh ) for mesh in meshes ]
			switchAttrs = [ ( "%s.inp[0]" % switch ) for switch in switches ]
			mc.cacheFile(attachFile=True,
						 fileName=cacheFileName,
						 directory=cacheDir,
						 channelName=meshes,
						 inAttr=switchAttrs)
			for switch in switches:
				mc.setAttr("%s.playFromCache" % switch, True)
	
			if deleteSkeleton:
				# After creating a geometry cache the skeleton, anim curves, and
				# skin clusters are no longer needed to playback the sim. To save
				# memory the user can choose to delete them.
				#
				for mayaAgent in mayaAgents:
					mayaAgent.deleteSkeleton()

		self._factory.cleanup()
		
		# The layers are off by default to speed up load, turn them on
		# now.
		#	
		MayaAgent.showLayers()
示例#6
0
def dump(scene, target):
    agentSpec = AgentSpec.AgentSpec()
    MayaAgent.dump(agentSpec, target)
    scene.addAgentSpec(agentSpec)
示例#7
0
    def build(self, sim, animType, frameStep, cacheGeometry, cacheDir,
              deleteSkeleton, agentOptions):
        if sim.scene.mas().terrainFile:
            self._factory.importObj(sim.scene.mas().terrainFile, "terrain")

        mayaAgents = []
        startFrame = -sys.maxint
        endFrame = -sys.maxint

        for agent in sim.agents():
            mayaAgent = MayaSimAgent.MayaSimAgent(agent, self._factory, sim)
            mayaAgent.build(agentOptions, animType, frameStep)

            # Presumably every agent will be simmed over the same frame
            # range - however since the frame ranges could conceivably
            # be different, find and and store the earliest startFrame
            # and latest endFrame
            #
            if mayaAgent.simData():
                if -sys.maxint == startFrame or mayaAgent.simData(
                ).startFrame < startFrame:
                    startFrame = mayaAgent.simData().startFrame
                if -sys.maxint == endFrame or mayaAgent.simData(
                ).endFrame > endFrame:
                    endFrame = mayaAgent.simData().endFrame

            mayaAgents.append(mayaAgent)

        if cacheGeometry:
            # Create geometry caches for each agent.
            #
            meshes = []
            for mayaAgent in mayaAgents:
                meshes.extend([
                    geometry.shapeName() for geometry in mayaAgent.geometryData
                ])
            cacheFileName = "%s_%s" % (sim.scene.baseName(), sim.range)

            mc.cacheFile(directory=cacheDir,
                         singleCache=True,
                         doubleToFloat=True,
                         format="OneFilePerFrame",
                         simulationRate=1,
                         sampleMultiplier=1,
                         fileName=cacheFileName,
                         startTime=startFrame,
                         endTime=endFrame,
                         points=meshes)

            # There's a bug in maya where cacheFile will sometimes write a
            # partial path into the cache instead of the full path. To makes
            # sure the attachFile works, we have to query the actual channel
            # names
            cacheFileFullName = "%s/%s.xml" % (cacheDir, cacheFileName)
            meshes = mc.cacheFile(query=True,
                                  fileName=cacheFileFullName,
                                  channelName=True)

            switches = [
                maya.mel.eval('createHistorySwitch( "%s", false )' % mesh)
                for mesh in meshes
            ]
            switchAttrs = [("%s.inp[0]" % switch) for switch in switches]
            mc.cacheFile(attachFile=True,
                         fileName=cacheFileName,
                         directory=cacheDir,
                         channelName=meshes,
                         inAttr=switchAttrs)
            for switch in switches:
                mc.setAttr("%s.playFromCache" % switch, True)

            if deleteSkeleton:
                # After creating a geometry cache the skeleton, anim curves, and
                # skin clusters are no longer needed to playback the sim. To save
                # memory the user can choose to delete them.
                #
                for mayaAgent in mayaAgents:
                    mayaAgent.deleteSkeleton()

        self._factory.cleanup()

        # The layers are off by default to speed up load, turn them on
        # now.
        #
        MayaAgent.showLayers()