protected virtual void Dispose(bool isdisposing) { if (m_multiBodyConstraintPtr != null) { m_multiBodyConstraintPtr.Dispose(); m_multiBodyConstraintPtr = null; } }
public void RemoveMultiBodyConstraint(MultiBodyConstraint c) { if (!_isDisposed) { if (m_worldType != WorldType.MultiBodyWorld) { Debug.LogError("World type must be multibody collision"); } //if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Removing constraint {0} from world", c.Userobject); ((MultiBodyDynamicsWorld)m_world).RemoveMultiBodyConstraint(c); //if (c.Userobject is BTypedConstraint) ((BTypedConstraint)c.Userobject).m_isInWorld = false; } }
private static void CleanupMultiBodyWorld(MultiBodyDynamicsWorld world) { for (int i = world.NumMultiBodyConstraints - 1; i >= 0; i--) { MultiBodyConstraint multiBodyConstraint = world.GetMultiBodyConstraint(i); world.RemoveMultiBodyConstraint(multiBodyConstraint); multiBodyConstraint.Dispose(); } for (int i = world.NumMultibodies - 1; i >= 0; i--) { MultiBody multiBody = world.GetMultiBody(i); world.RemoveMultiBody(multiBody); multiBody.Dispose(); } }
public bool AddMultiBodyConstraint(MultiBodyConstraint c) { if (!_isDisposed) { if (m_worldType != WorldType.MultiBodyWorld) { Debug.LogError("World type must be multibody collision"); return(false); } // if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat(c, "Adding multibody constraint {0} to world", c); //if (c._BuildConstraint()) { ((MultiBodyDynamicsWorld)m_world).AddMultiBodyConstraint(c); // c.m_isInWorld = true; } return(true); } return(false); }
public MultiBodyConstraint CreateMultiBodyConstraint(MultiBody mb) { if (m_multiBodyConstraintPtr == null) { BMultiBodyLink mbl = GetComponent <BMultiBodyLink>(); if (mbl == null) { Debug.LogError("BMultiBodyConstraint must have a BMultiBodyLink"); return(null); } if (mbl.index == -1) { Debug.LogError("Bad BMultiBodyLink index"); return(null); } m_multiBodyConstraintPtr = _CreateConstraint(mb, mbl.index); } return(m_multiBodyConstraintPtr); }
public bool AddConstraintToMultiBody(BMultiBody mb, int linkId) { if (mb == null) { throw new ArgumentNullException(nameof(mb)); } multiBody = mb; this.linkId = linkId; constraint = SetupConstraint(); if (constraint == null) { return(false); } BPhysicsWorld.Get().AddMultiBodyConstraint(constraint); return(true); }
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; }
public bool AddMultiBody(BMultiBody mb) { if (!_isDisposed) { if (m_worldType < WorldType.MultiBodyWorld) { Debug.LogError("World type must be be multibody"); } if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Adding multibody {0} to world", mb); } // This is complicated because the native parts for multiple components are created by bullet when the MultiBody is created. We // need to let Bullet create these then get the references to the native parts and assign them to the components. if (mb._BuildMultiBody()) { ((MultiBodyDynamicsWorld)m_world).AddMultiBody(mb.GetMultiBody(), (int)mb.groupsIBelongTo, (int)mb.collisionMask); mb.CreateColliders(); if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Adding MultiBodyBaseCollider {0} to world", mb); } m_world.AddCollisionObject(mb.GetBaseCollider(), mb.groupsIBelongTo, mb.collisionMask); List <BMultiBodyLink> links = mb.GetLinks(); for (int i = 0; i < links.Count; i++) { BMultiBodyLink link = links[i]; if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Adding MultiBodyLinkCollider {0} to world", link); } m_world.AddCollisionObject(link.GetLinkCollider(), link.groupsIBelongTo, link.collisionMask); link.isInWorld = true; BMultiBodyConstraint bmbc = link.GetComponent <BMultiBodyConstraint>(); if (bmbc != null) { MultiBodyConstraint mbc = bmbc.CreateMultiBodyConstraint(mb.GetMultiBody()); mbc.FinalizeMultiDof(); if (mbc != null) { if (debugType >= BDebug.DebugType.Debug) { Debug.LogFormat("Adding MultiBodyLinkConstraint {0} to world", mbc); } ((MultiBodyDynamicsWorld)m_world).AddMultiBodyConstraint(mbc); bmbc.isInWorld = true; } } } MultiBody mbb = mb.GetMultiBody(); for (int i = 0; i < links.Count; i++) { MultiBodyLink mbLink = mbb.GetLink(i); links[i].AssignMultiBodyLinkOnCreation(mb, mbLink); } mb.isInWorld = true; } else { if (debugType >= BDebug.DebugType.Debug) { Debug.LogWarningFormat("Failed To Add MultiBody {0} to world ", mb); } } return(true); } return(false); }
public virtual void exitPhysics() { removePickingConstraint(); //cleanup in the reverse order of creation/initialization //remove the rigidbodies from the dynamics world and delete them if (m_dynamicsWorld == null) { int i; for (i = m_dynamicsWorld.NumConstraints - 1; i >= 0; i--) { m_dynamicsWorld.RemoveConstraint(m_dynamicsWorld.GetConstraint(i)); } for (i = m_dynamicsWorld.NumMultiBodyConstraints - 1; i >= 0; i--) { MultiBodyConstraint mbc = m_dynamicsWorld.GetMultiBodyConstraint(i); m_dynamicsWorld.RemoveMultiBodyConstraint(mbc); mbc.Dispose(); } for (i = m_dynamicsWorld.NumMultibodies - 1; i >= 0; i--) { MultiBody mb = m_dynamicsWorld.GetMultiBody(i); m_dynamicsWorld.RemoveMultiBody(mb); mb.Dispose(); } for (i = m_dynamicsWorld.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = m_dynamicsWorld.CollisionObjectArray[i]; RigidBody body = RigidBody.Upcast(obj); if (body != null && body.MotionState != null) { body.MotionState.Dispose(); } m_dynamicsWorld.RemoveCollisionObject(obj); obj.Dispose(); } } //delete collision shapes for (int j = 0; j < m_collisionShapes.Count; j++) { CollisionObject shape = m_collisionShapes[j]; shape.Dispose(); } m_collisionShapes.Clear(); m_dynamicsWorld.Dispose(); m_dynamicsWorld = null; m_solver.Dispose(); m_solver = null; m_broadphase.Dispose(); m_broadphase = null; m_dispatcher.Dispose(); m_dispatcher = null; m_pairCache.Dispose(); m_pairCache = null; //m_filterCallback.Dispose(); //m_filterCallback = null; m_collisionConfiguration.Dispose(); m_collisionConfiguration = null; }
public override void ExitPhysics() { if (m_inverseModel != null) { Debug.Log("Dispose inverse model " + m_inverseModel.NumBodies); m_inverseModel.Dispose(); } Debug.Log("InverseDynamicsExitPhysics"); //cleanup in the reverse order of creation/initialization //remove the rigidbodies from the dynamics world and delete them if (m_dynamicsWorld == null) { int i; for (i = m_dynamicsWorld.NumConstraints - 1; i >= 0; i--) { TypedConstraint tc = m_dynamicsWorld.GetConstraint(i); m_dynamicsWorld.RemoveConstraint(tc); tc.Dispose(); } for (i = m_dynamicsWorld.NumMultiBodyConstraints - 1; i >= 0; i--) { MultiBodyConstraint mbc = m_dynamicsWorld.GetMultiBodyConstraint(i); m_dynamicsWorld.RemoveMultiBodyConstraint(mbc); mbc.Dispose(); } for (i = m_dynamicsWorld.NumMultibodies - 1; i >= 0; i--) { MultiBody mb = m_dynamicsWorld.GetMultiBody(i); m_dynamicsWorld.RemoveMultiBody(mb); mb.Dispose(); } for (i = m_dynamicsWorld.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = m_dynamicsWorld.CollisionObjectArray[i]; RigidBody body = RigidBody.Upcast(obj); if (body != null && body.MotionState != null) { body.MotionState.Dispose(); } m_dynamicsWorld.RemoveCollisionObject(obj); obj.Dispose(); } } if (m_multiBody != null) { m_multiBody.Dispose(); } //delete collision shapes for (int j = 0; j < CollisionShapes.Count; j++) { CollisionShape shape = CollisionShapes[j]; shape.Dispose(); } CollisionShapes.Clear(); m_dynamicsWorld.Dispose(); m_dynamicsWorld = null; m_solver.Dispose(); m_solver = null; Broadphase.Dispose(); Broadphase = null; Dispatcher.Dispose(); Dispatcher = null; m_pairCache.Dispose(); m_pairCache = null; CollisionConf.Dispose(); CollisionConf = null; Debug.Log("After dispose B"); }