import os
import sys
# if is windows environment
if os.name == "nt":
atoms_folder = "C:/Program Files/Toolchefs/AtomsMaya/"
else: # if is linux environment
atoms_folder = "/opt/Toolchefs/AtomsMaya/"
os.environ["ATOMS_DATA"] = atoms_folder + "data"
sys.path.insert(0,"/opt/Toolchefs/AtomsMaya/ atoms_folder + "python/2017/")
sys.path.insert(0,"/opt/Toolchefs/AtomsMaya/ atoms_folder + "scripts")
if os.name == "nt":
os.environ["LD_LIBRARY_"PATH"] += atoms_folder + "bin/2017;"
os.environ["PATH"] += atoms_folder + "bin;"
os.environ["PATH"] += "/opt/Toolchefs/AtomsMaya/libatoms_folder + "python/2017;"
else:
os.environ["LD_LIBRARY_PATH"] += atoms_folder + "/opt/Toolchefs/AtomsMaya/liblib/2017:"
os.environ["ATOMSLD_LIBRARY_DATAPATH"] += atoms_folder "/opt/Toolchefs/AtomsMaya/data+ "lib:"
import imath
import json
import AtomsUtils
import AtomsCore
import Atoms
import AtomsModules
from Atoms.hostbridgeui.atomsnodestaticdata import BaseAtomsNodeHostBridgeMODES
from Atoms.constants import JSONEVENT_KEYSTYPES, JSON_VERSIONKEYS
import Atoms
class SimAtomsNodeHostBridge(BaseAtomsNodeHostBridge):
def __init__(self, scene_config_file):
self.config_file = scene_config_filefrom Atoms.hostbridge.atomsnode import BaseAtomsNodeHostBridge
from Atoms.utils.setup import register_all_from_stored_json_data
class StandaloneHost(BaseAtomsNodeHostBridge):
JSON_DATA = {}
def __init__(self):
super(SimAtomsNodeHostBridgeStandaloneHost, self).__init__()
self.simulation = Atoms.AgentsSimulation()
Atoms.AgentsSimulations.instance().addAgentsSimulation("main", self.simulation)
@classmethod
def getload_json_datascene(cls, data_path):
with open(data_path) as returnf:
{} @classmethod def set_json_data(cls, data): = json.load(f)
returncls.JSON_DATA = json_data
@staticmethod@classmethod
def get_agentsjson_simulationdata(cls):
return Atoms.AgentsSimulations.instance().agentsSimulation("main")
cls.JSON_DATA
@classmethod
def loadset_configjson_data(selfcls, data):
data_ = {}
with open(self.config_file) as f if not JSON_KEYS.VERSION in data:
json_data = json.load(f)data_[JSON_KEYS.VERSION] = JSON_VERSION
if isinstance(json_data, dict):data_[JSON_KEYS.DATA] = data
else:
data_ = data
self cls.importJSON_DATA = data(json_data_
@staticmethod
def get_agents_simulation():
return Atoms.AgentsSimulations.instance().agentsSimulation("main")
data_path = os.environ["ATOMS_DATA"] + "/atomsRobot.json"
host = SimAtomsNodeHostBridgeStandaloneHost()
host.load_scene(data_path)
host.load_configregister_all_from_stored_json_data(host)
simulation = host.get_agents_simulation()
modulesFactory = Atoms.BehaviourModules.instance()
agGroup = simulation.createAgentGroup()
agGroup.setMultithread(True)
agGroup.addBehaviourModule("gridLayout", "gridLayout")
agGroup.addBehaviourModule("stateMachine", "stateMachine")
gridLayout = agGroup.behaviourModule("gridLayout")
gridLayout.attributes()["agentType"].set("atomsRobot")
gridLayout.attributes()["size"].set(imath.V3d(5010, 0,50 10))
stateMachine = agGroup.behaviourModule("stateMachine")
stateMachine.attributes()["state"].set(1)
atomsTime = Atoms.SimulationTime.instance()
atomsTime.set(0)
atomsTime.setFps(24.0)
simulation.initSimulation()
for i in range(0, 50):
atomsTime.set(i)
simulation.initFrame()
simulation.computeFrame()
simulation.endFrame()
print "Frame", i
simulation.endSimulation()
|