Пример #1
0
 public void RemoveMultiBody(BMultiBody mb)
 {
     if (!_isDisposed)
     {
         if (m_worldType < WorldType.MultiBodyWorld)
         {
             Debug.LogError("World type must be multibody");
         }
         if (debugType >= BDebug.DebugType.Debug)
         {
             Debug.LogFormat("Removing multibody {0} from world", mb);
         }
         List <BMultiBodyLink> links = mb.GetLinks();
         for (int i = 0; i < links.Count; i++)
         {
             if (debugType >= BDebug.DebugType.Debug)
             {
                 Debug.LogFormat("Removing MultiBodyLinkCollider {0} from world", links[i]);
             }
             m_world.RemoveCollisionObject(links[i].GetLinkCollider());
             links[i].isInWorld = false;
         }
         if (debugType >= BDebug.DebugType.Debug)
         {
             Debug.LogFormat("Removing MultiBodyBaseCollider {0} from world", mb);
         }
         m_world.RemoveCollisionObject(mb.GetBaseCollider());
         ((MultiBodyDynamicsWorld)m_world).RemoveMultiBody(mb.GetMultiBody());
         mb.isInWorld = false;
     }
 }
Пример #2
0
        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);
        }