Beispiel #1
0
        protected override void RemoveObjectFromBulletWorld()
        {
            BPhysicsWorld pw = BPhysicsWorld.Get();

            if (pw != null && m_multiBody != null && isInWorld)
            {
                pw.RemoveMultiBody(m_multiBody);
                isInWorld = false;
            }
        }
Beispiel #2
0
        //called by Physics World just before multi body is added to world.
        //the current multi body properties are used to rebuild the multi body.
        internal override bool _BuildCollisionObject()
        {
            BPhysicsWorld world = BPhysicsWorld.Get();

            if (m_multiBody != null && isInWorld && world != null)
            {
                isInWorld = false;
                world.RemoveMultiBody(m_multiBody);
            }

            if (transform.localScale != UnityEngine.Vector3.one)
            {
                Debug.LogErrorFormat("The local scale on {0} rigid body is not one. Bullet physics does not support scaling on a rigid body world transform. Instead alter the dimensions of the CollisionShape.", name);
                return(false);
            }

            return(CreateMultiBody(ref m_multiBody, ref _localInertia, GetComponent <BCollisionShape>().GetCollisionShape()));
        }
Beispiel #3
0
        internal bool _BuildMultiBody()
        {
            BPhysicsWorld world = BPhysicsWorld.Get();

            if (m_multibody != null && isInWorld && world != null)
            {
                isInWorld = false;
                world.RemoveMultiBody(this);
            }

            if (transform.localScale != UnityEngine.Vector3.one)
            {
                Debug.LogErrorFormat("The local scale on {0} rigid body is not one. Bullet physics does not support scaling on a rigid body world transform. Instead alter the dimensions of the CollisionShape.", name);
            }

            if (!fixedBase && baseMass <= 0f)
            {
                Debug.LogErrorFormat("If not fixed base then baseMass must be greater than zero.");
                return(false);
            }

            m_baseCollisionShape = GetComponent <BCollisionShape>();
            if (m_baseCollisionShape == null)
            {
                Debug.LogErrorFormat("There was no collision shape component attached to this BMultiBody. {0}", name);
                return(false);
            }
            if (GetComponent <BMultiBodyLink>() != null)
            {
                Debug.LogErrorFormat("There must not be a BMultiBodyLink component attached to the gameObject with a BMultiBody component. {0}", name);
                return(false);
            }

            m_links = new List <BMultiBodyLink>();
            if (!GetLinksInChildrenAndNumber(transform, m_links, -1))
            {
                Debug.LogError("Error building multibody");
                return(false);
            }

            if (m_links.Count == 0)
            {
                Debug.LogError("Could not find any links");
                return(false);
            }

            if (!ValidateMultiBodyHierarchy(m_links))
            {
                return(false);
            }

            BCollisionShape[]      shapes      = new BCollisionShape[m_links.Count];
            BMultiBodyConstraint[] constraints = new BMultiBodyConstraint[m_links.Count];
            for (int i = 0; i < m_links.Count; i++)
            {
                shapes[i] = m_links[i].GetComponent <BCollisionShape>();
                if (shapes[i] == null && shapes[i].GetComponent <RigidBody>() != null)
                {
                    Debug.LogErrorFormat("BMultiBodyLink must not have a RigidBody component. {0}", m_links[i]);
                    return(false);
                }
                constraints[i] = m_links[i].GetComponent <BMultiBodyConstraint>();
            }

            BulletSharp.MultiBody mb = m_multibody;
            CreateOrConfigureMultiBody(ref mb, baseMass, shapes, constraints);
            m_multibody = mb;

            //TODO is this allowed
            //m_multibody.UserObject = this;

            return(true);
        }