示例#1
0
        public void TearDown()
        {
            world.RemoveSoftBody(softBody);
            softBody.Dispose();
            softBodyWorldInfo.Dispose();

            world.Dispose();
            solver.Dispose();
            broadphase.Dispose();
            dispatcher.Dispose();
            conf.Dispose();
        }
        public void SoftBodyDebugDrawHelpersTest()
        {
            var softBodyWorldInfo = new SoftBodyWorldInfo();

            using (var debugDrawer = new DebugDrawer())
            {
                using (var softBody = SoftBodyHelpers.CreateEllipsoid(softBodyWorldInfo, Vector3.Zero, new Vector3(1), 4))
                {
                    SoftBodyHelpers.DrawInfos(softBody, debugDrawer, true, true, true);
                    Assert.That(debugDrawer.Draw3DTextCalled, Is.True);

                    SoftBodyHelpers.Draw(softBody, debugDrawer, SoftDrawFlags);
                    SoftBodyHelpers.DrawClusterTree(softBody, debugDrawer);
                    SoftBodyHelpers.DrawFaceTree(softBody, debugDrawer);
                    SoftBodyHelpers.DrawFrame(softBody, debugDrawer);
                    SoftBodyHelpers.DrawNodeTree(softBody, debugDrawer);
                }
                Assert.That(debugDrawer.DrawLineCalled, Is.True);
            }

            softBodyWorldInfo.Dispose();
        }
        protected void Dispose(bool disposing)
        {
            if (debugType >= BDebug.DebugType.Debug)
            {
                Debug.Log("BDynamicsWorld Disposing physics.");
            }

            if (PhysicsWorldHelper != null)
            {
                PhysicsWorldHelper.m_ddWorld = null;
                PhysicsWorldHelper.m_world   = null;
            }
            if (m_world != null)
            {
                //remove/dispose constraints
                int i;
                if (_ddWorld != null)
                {
                    if (debugType >= BDebug.DebugType.Debug)
                    {
                        Debug.LogFormat("Removing Constraints {0}", _ddWorld.NumConstraints);
                    }
                    for (i = _ddWorld.NumConstraints - 1; i >= 0; i--)
                    {
                        TypedConstraint constraint = _ddWorld.GetConstraint(i);
                        _ddWorld.RemoveConstraint(constraint);
                        if (constraint.Userobject is BTypedConstraint)
                        {
                            ((BTypedConstraint)constraint.Userobject).m_isInWorld = false;
                        }
                        if (debugType >= BDebug.DebugType.Debug)
                        {
                            Debug.LogFormat("Removed Constaint {0}", constraint.Userobject);
                        }
                        constraint.Dispose();
                    }
                }

                if (debugType >= BDebug.DebugType.Debug)
                {
                    Debug.LogFormat("Removing Collision Objects {0}", m_world.NumCollisionObjects);
                }
                //remove the rigidbodies from the dynamics world and delete them
                for (i = m_world.NumCollisionObjects - 1; i >= 0; i--)
                {
                    CollisionObject obj  = m_world.CollisionObjectArray[i];
                    RigidBody       body = obj as RigidBody;
                    if (body != null && body.MotionState != null)
                    {
                        Debug.Assert(body.NumConstraintRefs == 0, "Rigid body still had constraints");
                        body.MotionState.Dispose();
                    }
                    m_world.RemoveCollisionObject(obj);
                    if (obj.UserObject is BCollisionObject)
                    {
                        ((BCollisionObject)obj.UserObject).isInWorld = false;
                    }
                    if (debugType >= BDebug.DebugType.Debug)
                    {
                        Debug.LogFormat("Removed CollisionObject {0}", obj.UserObject);
                    }
                    obj.Dispose();
                }

                MultiBodyDynamicsWorld _mbdWorld = m_world as MultiBodyDynamicsWorld;
                if (_mbdWorld != null)
                {
                    if (debugType >= BDebug.DebugType.Debug)
                    {
                        Debug.LogFormat("Removing MultiBody Constraints {0}", _mbdWorld.NumMultiBodyConstraints);
                    }
                    for (i = _mbdWorld.NumMultiBodyConstraints - 1; i >= 0; i--)
                    {
                        MultiBodyConstraint constraint = _mbdWorld.GetMultiBodyConstraint(i);
                        _mbdWorld.RemoveMultiBodyConstraint(constraint);

                        /* if (constraint.Userobject is BTypedConstraint) ((BTypedConstraint)constraint.Userobject).m_isInWorld = false;
                         * if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Removed Constaint {0}", constraint.Userobject);*/
                        constraint.Dispose();
                    }

                    if (debugType >= BDebug.DebugType.Debug)
                    {
                        Debug.LogFormat("Removing Multibodies {0}", _mbdWorld.NumMultibodies);
                    }
                    //remove the rigidbodies from the dynamics world and delete them
                    for (i = _mbdWorld.NumMultibodies - 1; i >= 0; i--)
                    {
                        MultiBody mb = _mbdWorld.GetMultiBody(i);

                        _mbdWorld.RemoveMultiBody(mb);
                        if (mb.UserObject is BMultiBody bmb)
                        {
                            bmb.isInWorld = false;
                        }
                        if (debugType >= BDebug.DebugType.Debug)
                        {
                            Debug.LogFormat("Removed CollisionObject {0}", mb.UserObject);
                        }
                        mb.Dispose();
                    }
                }

                if (m_world.DebugDrawer != null)
                {
                    if (m_world.DebugDrawer is IDisposable)
                    {
                        IDisposable dis = (IDisposable)m_world.DebugDrawer;
                        dis.Dispose();
                    }
                }

                m_world.Dispose();
                Broadphase.Dispose();
                Dispatcher.Dispose();
                CollisionConf.Dispose();
                _ddWorld = null;
                m_world  = null;
            }

            if (Broadphase != null)
            {
                Broadphase.Dispose();
                Broadphase = null;
            }
            if (Dispatcher != null)
            {
                Dispatcher.Dispose();
                Dispatcher = null;
            }
            if (CollisionConf != null)
            {
                CollisionConf.Dispose();
                CollisionConf = null;
            }
            if (constraintSolver != null)
            {
                constraintSolver.Dispose();
                constraintSolver = null;
            }
            if (softBodyWorldInfo != null)
            {
                softBodyWorldInfo.Dispose();
                softBodyWorldInfo = null;
            }
            _isDisposed = true;
            singleton   = null;
        }
示例#4
0
        protected void Dispose(bool disposing)
        {
            if (debugType >= BDebug.DebugType.Debug)
            {
                Debug.Log("BDynamicsWorld Disposing physics.");
            }

            /* NU
             * if (lateUpdateHelper != null)
             * {
             *  lateUpdateHelper.m_ddWorld = null;
             *  lateUpdateHelper.m_world = null;
             * }
             */
            if (m_world != null)
            {
                //remove/dispose constraints
                int i;
                if (_ddWorld != null)
                {
                    if (debugType >= BDebug.DebugType.Debug)
                    {
                        Debug.LogFormat("Removing Constraints {0}", _ddWorld.NumConstraints);
                    }
                    for (i = _ddWorld.NumConstraints - 1; i >= 0; i--)
                    {
                        TypedConstraint constraint = _ddWorld.GetConstraint(i);
                        _ddWorld.RemoveConstraint(constraint);
                        if (constraint.Userobject is BTypedConstraint)
                        {
                            ((BTypedConstraint)constraint.Userobject).m_isInWorld = false;
                        }
                        if (debugType >= BDebug.DebugType.Debug)
                        {
                            Debug.LogFormat("Removed Constaint {0}", constraint.Userobject);
                        }
                        constraint.Dispose();
                    }
                }

                /* gRally
                 * if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Removing Collision Objects {0}", _ddWorld.NumCollisionObjects);
                 * //remove the rigidbodies from the dynamics world and delete them
                 * for (i = m_world.NumCollisionObjects - 1; i >= 0; i--)
                 * {
                 *  CollisionObject obj = m_world.CollisionObjectArray[i];
                 *  RigidBody body = obj as RigidBody;
                 *  if (body != null && body.MotionState != null)
                 *  {
                 *      Debug.Assert(body.NumConstraintRefs == 0, "Rigid body still had constraints");
                 *      body.MotionState.Dispose();
                 *  }
                 *  m_world.RemoveCollisionObject(obj);
                 *  if (obj.UserObject is BCollisionObject) ((BCollisionObject)obj.UserObject).isInWorld = false;
                 *  if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Removed CollisionObject {0}", obj.UserObject);
                 *  obj.Dispose();
                 * }
                 *
                 */

                if (m_world.DebugDrawer != null)
                {
                    if (m_world.DebugDrawer is IDisposable)
                    {
                        IDisposable dis = (IDisposable)m_world.DebugDrawer;
                        dis.Dispose();
                    }
                }

                m_world.Dispose();
                Broadphase.Dispose();
                Dispatcher.Dispose();
                CollisionConf.Dispose();
                _ddWorld = null;
                m_world  = null;
            }

            if (Broadphase != null)
            {
                Broadphase.Dispose();
                Broadphase = null;
            }
            if (Dispatcher != null)
            {
                Dispatcher.Dispose();
                Dispatcher = null;
            }
            if (CollisionConf != null)
            {
                CollisionConf.Dispose();
                CollisionConf = null;
            }
            if (Solver != null)
            {
                Solver.Dispose();
                Solver = null;
            }
            if (softBodyWorldInfo != null)
            {
                softBodyWorldInfo.Dispose();
                softBodyWorldInfo = null;
            }
            _isDisposed = true;
            singleton   = null;
        }
 public void TearDown()
 {
     _softBodyWorldInfo.Dispose();
 }
示例#6
0
        protected void Dispose(bool disposing)
        {
            BDebug.Log(debugType, "BDynamicsWorld Disposing physics.");

            if (m_world != null)
            {
                //remove/dispose constraints
                int i;
                if (_ddWorld != null)
                {
                    for (i = _ddWorld.NumConstraints - 1; i >= 0; i--)
                    {
                        TypedConstraint constraint = _ddWorld.GetConstraint(i);
                        _ddWorld.RemoveConstraint(constraint);
                        if (constraint.Userobject is BTypedConstraint)
                        {
                            ((BTypedConstraint)constraint.Userobject).isInWorld = false;
                        }
                        if ((debugType & BDebug.DebugType.Debug) == BDebug.DebugType.Debug)
                        {
                            Debug.LogFormat("Removed Constaint {0}", constraint.Userobject);
                        }
                        constraint.Dispose();
                    }
                }

                //remove the rigidbodies from the dynamics world and delete them
                for (i = m_world.NumCollisionObjects - 1; i >= 0; i--)
                {
                    CollisionObject obj  = m_world.CollisionObjectArray[i];
                    RigidBody       body = obj as RigidBody;
                    if (body != null && body.MotionState != null)
                    {
                        body.MotionState.Dispose();
                    }
                    m_world.RemoveCollisionObject(obj);
                    if (obj.UserObject is BCollisionObject)
                    {
                        ((BCollisionObject)obj.UserObject).isInWorld = false;
                    }
                    if ((debugType & BDebug.DebugType.Debug) == BDebug.DebugType.Debug)
                    {
                        Debug.LogFormat("Removed CollisionObject {0}", obj.UserObject);
                    }
                    obj.Dispose();
                }

                if (m_world.DebugDrawer != null)
                {
                    if (m_world.DebugDrawer is IDisposable)
                    {
                        IDisposable dis = (IDisposable)m_world.DebugDrawer;
                        dis.Dispose();
                    }
                }

                m_world.Dispose();
                Broadphase.Dispose();
                Dispatcher.Dispose();
                CollisionConf.Dispose();
                _ddWorld = null;
                m_world  = null;
            }

            if (Broadphase != null)
            {
                Broadphase.Dispose();
                Broadphase = null;
            }
            if (Dispatcher != null)
            {
                Dispatcher.Dispose();
                Dispatcher = null;
            }
            if (CollisionConf != null)
            {
                CollisionConf.Dispose();
                CollisionConf = null;
            }
            if (Solver != null)
            {
                Solver.Dispose();
                Solver = null;
            }
            if (softBodyWorldInfo != null)
            {
                softBodyWorldInfo.Dispose();
                softBodyWorldInfo = null;
            }
            _isDisposed = true;
            singleton   = null;
        }
示例#7
0
        protected void Dispose(bool disposing)
        {
            if (lateUpdateHelper != null)
            {
                lateUpdateHelper.m_ddWorld = null;
                lateUpdateHelper.m_world   = null;
            }
            if (m_world != null)
            {
                //remove/dispose constraints
                int i;
                if (_ddWorld != null)
                {
                    for (i = _ddWorld.NumConstraints - 1; i >= 0; i--)
                    {
                        TypedConstraint constraint = _ddWorld.GetConstraint(i);
                        _ddWorld.RemoveConstraint(constraint);
                        if (constraint.Userobject is BTypedConstraint)
                        {
                            ((BTypedConstraint)constraint.Userobject).m_isInWorld = false;
                        }
                        constraint.Dispose();
                    }
                }

                //remove the rigidbodies from the dynamics world and delete them
                for (i = m_world.NumCollisionObjects - 1; i >= 0; i--)
                {
                    CollisionObject obj  = m_world.CollisionObjectArray[i];
                    RigidBody       body = obj as RigidBody;
                    if (body != null && body.MotionState != null)
                    {
                        Debug.Assert(body.NumConstraintRefs == 0, "Rigid body still had constraints");
                        body.MotionState.Dispose();
                    }
                    m_world.RemoveCollisionObject(obj);
                    if (obj.UserObject is BCollisionObject)
                    {
                        ((BCollisionObject)obj.UserObject).isInWorld = false;
                    }
                    obj.Dispose();
                }

                if (m_world.DebugDrawer != null)
                {
                    if (m_world.DebugDrawer is IDisposable)
                    {
                        IDisposable dis = (IDisposable)m_world.DebugDrawer;
                        dis.Dispose();
                    }
                }

                m_world.Dispose();
                Broadphase.Dispose();
                Dispatcher.Dispose();
                CollisionConf.Dispose();
                _ddWorld = null;
                m_world  = null;
            }

            if (Broadphase != null)
            {
                Broadphase.Dispose();
                Broadphase = null;
            }
            if (Dispatcher != null)
            {
                Dispatcher.Dispose();
                Dispatcher = null;
            }
            if (CollisionConf != null)
            {
                CollisionConf.Dispose();
                CollisionConf = null;
            }
            if (constraintSolver != null)
            {
                constraintSolver.Dispose();
                constraintSolver = null;
            }
            if (softBodyWorldInfo != null)
            {
                softBodyWorldInfo.Dispose();
                softBodyWorldInfo = null;
            }
            _isDisposed = true;
            singleton   = null;
        }