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); }
/// <summary> /// BMultiBodyLinks do not create their own native parts. That happens as part of the MultiBody creation. /// After the native MultiBody has been created. The references to the native MultiBodyLinks can be /// obtatined and are assigned using this function. /// </summary> internal void AssignMultiBodyLinkOnCreation(BMultiBody mb, MultiBodyLink link) { m_link = link; }