void Main_Initialization() { Agx_Simulation.Start(dt); //Starts the sim. dir = Application.streamingAssetsPath; //Get the path of the streaming assets //If I start with 3 modules. Then, each time user clicks "Add Module", it adds a new module to the simulation (sim will be started, but not timestep). //LOAD: Scenario scenario = Deserialize <Scenario>(); /* Loading the directories for the object files */ load_FrameDirectories(scenario.robot); Load_Robot(scenario.robot); Load_Scene(scenario.scene); simulation_Running = true; Visualization.enabled = true; if (Visualization.enabled) { Load_Vis(); } SetContactPoints();//if custom contact points: move to MainInitialization(). InvokeRepeating("Update_Sim", 0, dt); }
public void LoadFromXml(string path) { //get robot //design finished //deserialize if (!simulation_Started) { dir = Application.streamingAssetsPath;//Get the path of the streaming assets Clear_Vis(); Reset_Opti(); Agx_Simulation.Start(dt); //Starts the sim. simulation_Started = true; // true; simulation_Running = false; try { scenario = Deserialize <Scenario>(path); } catch (FileNotFoundException e) { Debug.Log("Scenario not found! " + e); AgX_Interface.AgX_Assembly.RemoveFromSim(); AgX_Interface.Agx_Simulation.Stop(); UnityEngine.SceneManagement.SceneManager.LoadScene(0); } SetContactFriction();//if custom contact points: move to MainInitialization(). CancelInvoke(); Dynamics.nextAction = "Idle"; //scenario = Deserialize<Scenario>(Application.streamingAssetsPath + "/XML/Scenario.xml"); robot = Load_Robot(scenario.robot); /* Loading the directories for the object files */ Load_FrameDirectories(robot); sceneObjects = LoadSceneObjects(scenario.sceneObjects); //possibly remove this scene = new Scene(); Load_Scene(scenario.scene); Visualization.enabled = true; if (Visualization.enabled) { Load_Vis(); Update_Vis(robot); } if (finalizeButton != null) { finalizeButton.SetActive(false); } } else { Debug.Log("Must load before simulation is started");//UnityEditor.EditorUtility.DisplayDialog("Load/Save error!", "Must load before simulation is started", "Ok"); } }
Robot robot;//Global for pos/rot update //Robot OriginalRobot = new Robot(); void Main_Initialization() { dir = Application.streamingAssetsPath;//Get the path of the streaming assets if (!simulation_Started) { Clear_Vis(); Reset_Opti(); Agx_Simulation.Start(dt);//Starts the sim. simulation_Started = true; CancelInvoke(); Dynamics.nextAction = "Idle"; //Load: scenario = Deserialize <Scenario>(Application.streamingAssetsPath + "/XML/Scenario.xml"); SetContactFriction(); // Loading the directories for the object files Load_FrameDirectories(scenario.robot); robot = Load_Robot(scenario.robot); sceneObjects = LoadSceneObjects(scenario.sceneObjects); scene = new Scene(); Load_Scene(scenario.scene); //SetMovementVariables(); Visualization.enabled = true; if (Visualization.enabled) { Load_Vis(); Update_Vis(robot); } } }
void Start() { //Start simulation: Agx_Simulation.Start(0.01); //Setting position and rotations: var pos = new AgX_Interface.Vector3(0, 0, 0); var u_quat = UnityEngine.Quaternion.Euler(0, 90, 0); AgX_Interface.Quaternion frame_rot = new AgX_Interface.Quaternion(u_quat.x, u_quat.y, u_quat.z, u_quat.w); //Create Frames: Frame[] frames = new Frame[2]; for (int i = 0; i < 2; i++) { frames[i] = new Frame() { guid = Guid.NewGuid(), position = pos, scale = 10, quatRotation = frame_rot, //rotation = rot, mass = 10, isStatic = false, materialName = "Plastic" }; } //download mesh obj file: loadmesh(); //Set mesh of frames: frames[0].SetMesh(AgxHelper(leftmesh.vertices), AgxHelper(leftmesh.uv), leftmesh.triangles); frames[1].SetMesh(AgxHelper(rightmesh.vertices), AgxHelper(rightmesh.uv), rightmesh.triangles); //Create Joint: Simulation_Core.Joint joint = new Simulation_Core.Joint() { guid = Guid.NewGuid(), leftFrameGuid = frames[0].guid, rightFrameGuid = frames[1].guid, type = "Hinge", lowerRangeLimit = -Math.PI / 2, upperRangeLimit = Math.PI / 2, max_vel = Math.PI / 6, Kp = 3 }; //Create Module: var module = new Module(); module.Create(frames[0], joint, frames[1]); //Add module to robot: robot.Add_Module(module); //Add second module to robot: //robot.Add_Module(module2,new Simulation_Core.Joint()); //Initialize robot: robot.Initialize(); //Scene object: sceneobj = new SceneObject() { guid = Guid.NewGuid(), shape = "Box", size = new AgX_Interface.Vector3(5, 1, 10), position = new AgX_Interface.Vector3(0, -2, 0), quatRotation = new AgX_Interface.Quaternion(0, 0, 0, 1), materialName = "Rock", mass = 10, isStatic = true }; sceneobj.Initialize(); //Load vis from mesh and robot + scene object: Load_Vis(); //Start sim update loop: InvokeRepeating("Update_Sim", 0.01f, 0.01f); }