Dynamic Layout

Dynamic Layout

import Atoms import AtomsCore import AtomsMath import os class MyAgentEmitter(Atoms.BehaviourModule): def __init__(self): Atoms.BehaviourModule.__init__(self) self.unique_id = 0 atype = AtomsCore.StringMetadata() self.addAttribute("agentType", atype, True) tooltipAType = AtomsCore.StringMetadata("The agent type name") self.addAttributeProperty("agentType", Atoms.GLOBAL_NAMES.BEHAVIOUR.TOOLTIP, tooltipAType) atHardConstructor = AtomsCore.StringMetadata(Atoms.GLOBAL_NAMES.BEHAVIOUR.HARD_CONSTRUCTORS.AGENT_TYPE) self.addAttributeProperty("agentType", Atoms.GLOBAL_NAMES.BEHAVIOUR.HARD_CONSTRUCTOR, atHardConstructor) def initSimulation(self, agentGroup): #Called at the first frame of the simulation pass def agentsCreated(self, agents, agentGroup): #Called at the beginning of each frame if any agents is created. #Here you can add operators/nodes to the AgentBehaviourNetwork #of each agent or create new metadatas pass def agentsKilled(self, agents, agentGroup): #Called at the beginning of each frame if any agents is killed pass def preFrame(self, agentGroup): attributes = self.attributes() at_attribute = Atoms.BehaviourModuleStringAttributeCache(attributes, "agentType", self.name(), agentGroup) #Called at the beginning of each frame before any agents is created if int(Atoms.SimulationTime.instance().time()) % 15 == 0: data = Atoms.AgentInitData() data.direction = AtomsMath.V3d(1.0, 0.0, 0.0) data.groupId = self.unique_id data.position = AtomsMath.V3d(0.0, 0.0, 0.0) data.scale = AtomsMath.V3d(1.0, 1.0, 1.0) data.upDirection = AtomsMath.V3d(0.0, 1.0, 0.0) value = at_attribute.getAttributeValue(data.groupId, str(data.groupId), None) data.agentType = Atoms.AgentTypes.instance().agentType(value) if not data.agentType: return agentGroup.initializeNewAgents([data]) self.unique_id = self.unique_id + 1 def initFrame(self, agents, agentGroup): #Called at the beginning of each frame after agentsCreated is called. #Typically here you would create/edit metadatas pass def endFrame(self, agents, agentGroup): #Called at the end of each frame. At this stage the poses of the #agents have already been built. #Typically here you would create/edit metadatas or change your agent #poses. pass @staticmethod def category(): return "Python"

Copyright © 2017, Toolchefs LTD.