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 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 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()
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()