protected void OnGUI() { if (m_simulation == null || m_statisticsWindowData == null) { return; } var simColor = Color.Lerp(Color.white, Color.blue, 0.2f); var spaceColor = Color.Lerp(Color.white, Color.green, 0.2f); var dynamicsColor = Color.Lerp(Color.white, Color.yellow, 0.2f); var eventColor = Color.Lerp(Color.white, Color.cyan, 0.2f); var dataColor = Color.Lerp(Color.white, Color.magenta, 0.2f); var labelStyle = m_statisticsWindowData.LabelStyle; var simTime = agx.Statistics.instance().getTimingInfo("Simulation", "Step forward time"); var spaceTime = agx.Statistics.instance().getTimingInfo("Simulation", "Collision-detection time"); var dynamicsSystemTime = agx.Statistics.instance().getTimingInfo("Simulation", "Dynamics-system time"); var preCollideTime = agx.Statistics.instance().getTimingInfo("Simulation", "Pre-collide event time"); var preTime = agx.Statistics.instance().getTimingInfo("Simulation", "Pre-step event time"); var postTime = agx.Statistics.instance().getTimingInfo("Simulation", "Post-step event time"); var lastTime = agx.Statistics.instance().getTimingInfo("Simulation", "Last-step event time"); var numBodies = m_simulation.getDynamicsSystem().getRigidBodies().Count; var numShapes = m_simulation.getSpace().getGeometries().Count; var numConstraints = m_simulation.getDynamicsSystem().getConstraints().Count + m_simulation.getSpace().getGeometryContacts().Count; GUILayout.Window(m_statisticsWindowData.Id, m_statisticsWindowData.Rect, id => { GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Total time: ", simColor) + simTime.current.ToString("0.00") + " ms", 14, true), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Pre-collide step: ", eventColor) + preCollideTime.current.ToString("0.00") + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Collision detection: ", spaceColor) + spaceTime.current.ToString("0.00") + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Pre step: ", eventColor) + preTime.current.ToString("0.00") + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Dynamics solvers: ", dynamicsColor) + dynamicsSystemTime.current.ToString("0.00") + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Post step: ", eventColor) + postTime.current.ToString("0.00") + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Last step: ", eventColor) + lastTime.current.ToString("0.00") + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Data: ", dataColor), 14, true), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Update frequency: ", dataColor) + (int)(1.0f / TimeStep + 0.5f) + " Hz"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Number of bodies: ", dataColor) + numBodies), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Number of shapes: ", dataColor) + numShapes), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Number of constraints: ", dataColor) + numConstraints), labelStyle); }, "AGX Dynamics statistics", Utils.GUI.Skin.window); }
private agxSDK.Simulation GetOrCreateSimulation() { if (m_simulation == null) { NativeHandler.Instance.MakeMainThread(); m_simulation = new agxSDK.Simulation(); m_space = m_simulation.getSpace(); m_system = m_simulation.getDynamicsSystem(); // Solver settings will assign number of threads. if (m_solverSettings != null) { m_solverSettings.SetSimulation(m_simulation); m_solverSettings.GetInitialized <SolverSettings>(); } // No solver settings - set the default. else { agx.agxSWIG.setNumThreads(Convert.ToUInt32(SolverSettings.DefaultNumberOfThreads)); } } return(m_simulation); }
public static void Start(double dt) { agx.agxSWIG.init(); sim_Instance = new agxSDK.Simulation(); //Initialize the simulation sim_Instance.setUniformGravity(new agx.Vec3(0, -9.80665f, 0)); //set gravity in Y direction sim_Instance.getDynamicsSystem().getTimeGovernor().setTimeStep(dt); // set timestep }
private agxSDK.Simulation GetOrCreateSimulation() { if (m_simulation == null) { NativeHandler.Instance.MakeMainThread(); m_simulation = new agxSDK.Simulation(); m_space = m_simulation.getSpace(); m_system = m_simulation.getDynamicsSystem(); // Since AGXUnity.Simulation is optional in the hierarchy // we have to synchronize fixedDeltaTime here if SimulationTool // never has been seen in the inspector. if (AutoSteppingMode == AutoSteppingModes.FixedUpdate) { TimeStep = Time.fixedDeltaTime; } // Solver settings will assign number of threads. if (m_solverSettings != null) { m_solverSettings.SetSimulation(m_simulation); m_solverSettings.GetInitialized <SolverSettings>(); } // No solver settings - set the default. else { agx.agxSWIG.setNumThreads(Convert.ToUInt32(SolverSettings.DefaultNumberOfThreads)); } StepCallbacks.OnInitialize(m_simulation); } return(m_simulation); }
public SolverSettings RestoreLocalDataFrom(agxSDK.Simulation simulation) { var solver = simulation.getSolver(); var config = solver.getNlMcpConfig(); NumberOfThreads = System.Convert.ToInt32(agx.agxSWIG.getNumThreads()); WarmStartDirectContacts = simulation.getDynamicsSystem().getUpdateTask().getSubtask("MatchContactStates").isEnabled(); RestingIterations = System.Convert.ToInt32(solver.getNumRestingIterations()); DryFrictionIterations = System.Convert.ToInt32(solver.getNumDryFrictionIterations()); McpAlgorithm = Convert(config.mcpAlgorithmType); McpInnerIterations = System.Convert.ToInt32(config.numMcpIterations); McpInnerTolerance = System.Convert.ToSingle(config.mcpTolerance); McpOuterIterations = System.Convert.ToInt32(config.numOuterIterations); McpOuterTolerance = System.Convert.ToSingle(config.outerTolerance); return(this); }
private agxSDK.Simulation GetOrCreateSimulation() { if (m_simulation == null) { NativeHandler.Instance.MakeMainThread(); m_simulation = new agxSDK.Simulation(); m_defaultNumDryFrictionIterations = (int)m_simulation.getSolver().getNumDryFrictionIterations(); m_defaultNumRestingIterations = (int)m_simulation.getSolver().getNumRestingIterations(); m_space = m_simulation.getSpace(); m_system = m_simulation.getDynamicsSystem(); m_system.setEnableContactWarmstarting(m_warmStartingDirectContacts); } return(m_simulation); }
protected void OnGUI() { if (m_simulation == null) { return; } if (!NativeHandler.Instance.HasValidLicense) { GUILayout.Window(GUIUtility.GetControlID(FocusType.Passive), new Rect(new Vector2(16, 0.5f * Screen.height), new Vector2(Screen.width - 32, 32)), id => { // Invalid license if initialized. if (NativeHandler.Instance.Initialized && agx.Runtime.instance().getStatus().Length > 0) { GUILayout.Label(Utils.GUI.MakeLabel("AGX Dynamics: " + agx.Runtime.instance().getStatus(), Color.red, 18, true), Utils.GUI.Skin.label); } else { GUILayout.Label(Utils.GUI.MakeLabel("AGX Dynamics: Errors occurred during initialization of AGX Dynamics.", Color.red, 18, true), Utils.GUI.Skin.label); } }, "AGX Dynamics not properly initialized", Utils.GUI.Skin.window); return; } if (m_statisticsWindowData == null) { return; } var simColor = Color.Lerp(Color.white, Color.blue, 0.2f); var spaceColor = Color.Lerp(Color.white, Color.green, 0.2f); var dynamicsColor = Color.Lerp(Color.white, Color.yellow, 0.2f); var eventColor = Color.Lerp(Color.white, Color.cyan, 0.2f); var dataColor = Color.Lerp(Color.white, Color.magenta, 0.2f); var memoryColor = Color.Lerp(Color.white, Color.red, 0.2f); var labelStyle = m_statisticsWindowData.LabelStyle; var simTime = agx.Statistics.instance().getTimingInfo("Simulation", "Step forward time"); var spaceTime = agx.Statistics.instance().getTimingInfo("Simulation", "Collision-detection time"); var dynamicsSystemTime = agx.Statistics.instance().getTimingInfo("Simulation", "Dynamics-system time"); var preCollideTime = agx.Statistics.instance().getTimingInfo("Simulation", "Pre-collide event time"); var preTime = agx.Statistics.instance().getTimingInfo("Simulation", "Pre-step event time"); var postTime = agx.Statistics.instance().getTimingInfo("Simulation", "Post-step event time"); var lastTime = agx.Statistics.instance().getTimingInfo("Simulation", "Last-step event time"); var numBodies = m_simulation.getDynamicsSystem().getRigidBodies().Count; var numShapes = m_simulation.getSpace().getGeometries().Count; var numConstraints = m_simulation.getDynamicsSystem().getConstraints().Count + m_simulation.getSpace().getGeometryContacts().Count; GUILayout.Window(m_statisticsWindowData.Id, m_statisticsWindowData.Rect, id => { GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Total time: ", simColor) + simTime.current.ToString("0.00").PadLeft(5, ' ') + " ms", 14, true), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Pre-collide step: ", eventColor) + preCollideTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Collision detection: ", spaceColor) + spaceTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Pre step: ", eventColor) + preTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Dynamics solvers: ", dynamicsColor) + dynamicsSystemTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Post step: ", eventColor) + postTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Last step: ", eventColor) + lastTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Data: ", dataColor), 14, true), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Update frequency: ", dataColor) + (int)(1.0f / TimeStep + 0.5f) + " Hz"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Number of bodies: ", dataColor) + numBodies), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Number of shapes: ", dataColor) + numShapes), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Number of constraints: ", dataColor) + numConstraints), labelStyle); GUILayout.Label(""); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("StepForward (managed):", memoryColor), 14, true), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Step forward: ", memoryColor) + m_statisticsWindowData.ManagedStepForward.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Allocations (managed):", memoryColor), 14, true), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Pre step callbacks: ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PreStepForward).PadLeft(6, ' ')), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Pre synchronize: ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PreSynchronizeTransforms).PadLeft(6, ' ')), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Step forward: ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.StepForward).PadLeft(6, ' ')), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Post synchronize: ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PostSynchronizeTransforms).PadLeft(6, ' ')), labelStyle); GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag(" - Post step callbacks: ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PostStepForward).PadLeft(6, ' ')), labelStyle); }, "AGX Dynamics statistics", Utils.GUI.Skin.window); }