protected virtual void _InitializePhysicsWorld()
        {
            _isDisposed = false;
            CreatePhysicsWorld(out m_world, out CollisionConf, out Dispatcher, out Broadphase, out constraintSolver, out softBodyWorldInfo);

            if (m_world is DiscreteDynamicsWorld)
            {
                _ddWorld = (DiscreteDynamicsWorld)m_world;
            }

            //Add a BPhysicsWorldLateHelper component to call FixedUpdate

            lateUpdateHelper = gameObject.AddComponent <BPhysicsWorldLateHelper>();

            lateUpdateHelper.m_world        = world;
            lateUpdateHelper.m_ddWorld      = _ddWorld;
            lateUpdateHelper.m_physicsWorld = this;
        }
Esempio n. 2
0
 protected virtual void _InitializePhysicsWorld()
 {
     _isDisposed = false;
     CreatePhysicsWorld(out m_world, out CollisionConf, out Dispatcher, out Broadphase, out Solver, out softBodyWorldInfo);
     if (m_world is DiscreteDynamicsWorld)
     {
         _ddWorld = (DiscreteDynamicsWorld)m_world;
     }
     //Add a BPhysicsWorldLateHelper component to call FixedUpdate
     lateUpdateHelper = GetComponent <BPhysicsWorldLateHelper>();
     if (lateUpdateHelper == null)
     {
         lateUpdateHelper = gameObject.AddComponent <BPhysicsWorldLateHelper>();
     }
     lateUpdateHelper.m_world                  = world;
     lateUpdateHelper.m_ddWorld                = _ddWorld;
     lateUpdateHelper.m_physicsWorld           = this;
     lateUpdateHelper.m__frameCount            = 0;
     lateUpdateHelper.m_lastSimulationStepTime = 0;
 }
 protected virtual void _InitializePhysicsWorld()
 {
     _isDisposed = false;
     CreatePhysicsWorld(out m_world, out CollisionConf, out Dispatcher, out Broadphase, out Solver, out softBodyWorldInfo);
     if (m_world is DiscreteDynamicsWorld)
     {
         _ddWorld = (DiscreteDynamicsWorld)m_world;
     }
     //Add a BPhysicsWorldLateHelper component to call FixedUpdate
     lateUpdateHelper = GetComponent<BPhysicsWorldLateHelper>();
     if (lateUpdateHelper == null)
     {
         lateUpdateHelper = gameObject.AddComponent<BPhysicsWorldLateHelper>();
     }
     lateUpdateHelper.m_world = world;
     lateUpdateHelper.m_ddWorld = _ddWorld;
     lateUpdateHelper.m_physicsWorld = this;
     lateUpdateHelper.m__frameCount = 0;
     lateUpdateHelper.m_lastSimulationStepTime = 0;
 }
Esempio n. 4
0
        protected virtual void _InitializePhysicsWorld()
        {
            _isDisposed = false;
            if (m_worldType == WorldType.SoftBodyAndRigidBody && m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf)
            {
                BDebug.LogError(debugType, "For World Type = SoftBodyAndRigidBody collisionType must be collisionType=SoftBodyRigidBodyCollisionConf. Switching");
                m_collisionType = CollisionConfType.SoftBodyRigidBodyCollisionConf;
            }

            if (m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf)
            {
                CollisionConf = new DefaultCollisionConfiguration();
            }
            else if (m_collisionType == CollisionConfType.SoftBodyRigidBodyCollisionConf)
            {
                CollisionConf = new SoftBodyRigidBodyCollisionConfiguration();
            }

            Dispatcher = new CollisionDispatcher(CollisionConf);

            if (m_broadphaseType == BroadphaseType.DynamicAABBBroadphase)
            {
                Broadphase = new DbvtBroadphase();
            }
            else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase)
            {
                Broadphase = new AxisSweep3(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies);
            }
            else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase_32bit)
            {
                Broadphase = new AxisSweep3_32Bit(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies);
            }
            else
            {
                Broadphase = null;
            }

            if (m_worldType == WorldType.CollisionOnly)
            {
                m_world  = new CollisionWorld(Dispatcher, Broadphase, CollisionConf);
                _ddWorld = null;
            }
            else if (m_worldType == WorldType.RigidBodyDynamics)
            {
                m_world  = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
                _ddWorld = (DiscreteDynamicsWorld)m_world;
            }
            else if (m_worldType == WorldType.MultiBodyWorld)
            {
                m_world  = new MultiBodyDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
                _ddWorld = (DiscreteDynamicsWorld)m_world;
            }
            else if (m_worldType == WorldType.SoftBodyAndRigidBody)
            {
                Solver            = new SequentialImpulseConstraintSolver();
                Solver.RandSeed   = sequentialImpulseConstraintSolverRandomSeed;
                softBodyWorldInfo = new SoftBodyWorldInfo
                {
                    AirDensity   = 1.2f,
                    WaterDensity = 0,
                    WaterOffset  = 0,
                    WaterNormal  = BulletSharp.Math.Vector3.Zero,
                    Gravity      = UnityEngine.Physics.gravity.ToBullet(),
                    Dispatcher   = Dispatcher,
                    Broadphase   = Broadphase
                };
                softBodyWorldInfo.SparseSdf.Initialize();

                m_world  = new SoftRigidDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
                _ddWorld = (DiscreteDynamicsWorld)m_world;

                m_world.DispatchInfo.EnableSpu = true;
                softBodyWorldInfo.SparseSdf.Reset();
                softBodyWorldInfo.AirDensity   = 1.2f;
                softBodyWorldInfo.WaterDensity = 0;
                softBodyWorldInfo.WaterOffset  = 0;
                softBodyWorldInfo.WaterNormal  = BulletSharp.Math.Vector3.Zero;
                softBodyWorldInfo.Gravity      = m_gravity.ToBullet();
            }
            if (_ddWorld != null)
            {
                _ddWorld.Gravity = m_gravity.ToBullet();
            }
            if (_doDebugDraw)
            {
                DebugDrawUnity db = new DebugDrawUnity();
                db.DebugMode        = _debugDrawMode;
                m_world.DebugDrawer = db;
            }

            //Add a BPhysicsWorldLateHelper component to call FixedUpdate
            lateUpdateHelper = GetComponent <BPhysicsWorldLateHelper>();
            if (lateUpdateHelper == null)
            {
                lateUpdateHelper = gameObject.AddComponent <BPhysicsWorldLateHelper>();
            }
            lateUpdateHelper.m_world                  = m_world;
            lateUpdateHelper.m_ddWorld                = _ddWorld;
            lateUpdateHelper.m_physicsWorld           = this;
            lateUpdateHelper.m__frameCount            = 0;
            lateUpdateHelper.m_lastSimulationStepTime = 0;
        }