Ejemplo n.º 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;
     }
 }
Ejemplo n.º 2
0
 public bool AddMultiBody(BMultiBody mb)
 {
     if (!_isDisposed)
     {
         if (m_worldType != WorldType.MultiBodyWorld)
         {
             Debug.LogError("World type must be multibody collision");
             return(false);
         }
         if (debugType >= BDebug.DebugType.Debug)
         {
             Debug.LogFormat(mb, "Adding multibody {0} to world", mb.name);
         }
         if (mb._BuildCollisionObject())
         {
             ((MultiBodyDynamicsWorld)m_world).AddMultiBody(mb.MultiBody);
             mb.isInWorld = true;
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
 /// <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 MultiBodyLinkColliders can be
 /// obtatined and are assigned using this function.
 /// </summary>
 internal void AssignMultiBodyLinkColliderOnCreation(BMultiBody mb, MultiBodyLinkCollider linkCollider)
 {
     m_linkCollider = linkCollider;
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 /// <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;
 }