Example #1
0
        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);
        }
Example #2
0
        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);
        }
        private void OnSimulationPostStep(agxSDK.Simulation simulation)
        {
            if (simulation == null)
            {
                return;
            }

            var gcs = simulation.getSpace().getGeometryContacts();

            m_contactList.Clear();
            m_contactList.Capacity = 4 * gcs.Count;
            for (int i = 0; i < gcs.Count; ++i)
            {
                var gc = gcs[i];
                if (!gc.isEnabled())
                {
                    continue;
                }

                for (uint j = 0; j < gc.points().size(); ++j)
                {
                    var p = gc.points().at(j);
                    if (!p.enabled)
                    {
                        continue;
                    }

                    m_contactList.Add(new ContactData()
                    {
                        Point = p.point.ToHandedVector3(), Normal = p.normal.ToHandedVector3()
                    });
                }
            }
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        private void OnSimulationPostStep(agxSDK.Simulation simulation)
        {
            if (simulation == null)
            {
                return;
            }

            // Only collect data for contacts if they are enabled
            if (m_renderContacts)
            {
                var gcs = simulation.getSpace().getGeometryContacts();

                m_contactList.Clear();
                m_contactList.Capacity = System.Math.Max(m_contactList.Capacity, 4 * gcs.Count);

                for (int i = 0; i < gcs.Count; ++i)
                {
                    var gc = gcs[i];
                    if (gc.isEnabled())
                    {
                        var contactPoints = gc.points();
                        for (uint j = 0; j < contactPoints.size(); ++j)
                        {
                            var contactPoint = contactPoints.at(j);
                            if (contactPoint.enabled)
                            {
                                m_contactList.Add(new ContactData()
                                {
                                    Point  = contactPoint.point.ToHandedVector3(),
                                    Normal = contactPoint.normal.ToHandedVector3()
                                });
                            }
                            contactPoint.ReturnToPool();
                        }
                        contactPoints.ReturnToPool();
                    }
                    gc.ReturnToPool();
                }
            }
        }
        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);
        }