// Create a body object in Bullet,
        // Update prim.BSBody with the information about the new body if one is created.
        // Returns 'true if an object was actually created.
        // Called at taint-time.
        bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletWorld sim,
                        PhysicalDestructionCallback bodyCallback)
        {
            bool ret = false;

            // the mesh, hull or native shape must have already been created in Bullet
            bool mustRebuild = !prim.PhysBody.HasPhysicalBody;

            // If there is an existing body, verify it's of an acceptable type.
            // If not a solid object, body is a GhostObject. Otherwise a RigidBody.
            if (!mustRebuild)
            {
                CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(prim.PhysBody);
                if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY ||
                    !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT)
                {
                    // If the collisionObject is not the correct type for solidness, rebuild what's there
                    mustRebuild = true;
                    if (DDetail)
                    {
                        DetailLog("{0},BSShapeCollection.CreateBody,forceRebuildBecauseChangingBodyType,bodyType={1}",
                                  prim.LocalID, bodyType);
                    }
                }
            }

            if (mustRebuild || forceRebuild)
            {
                // Free any old body
                DereferenceBody(prim.PhysBody, bodyCallback);

                BulletBody aBody;
                if (prim.IsSolid)
                {
                    aBody = PhysicsScene.PE.CreateBodyFromShape(sim, prim.PhysShape.physShapeInfo, prim.LocalID,
                                                                prim.RawPosition, prim.RawOrientation);
                    if (DDetail)
                    {
                        DetailLog("{0},BSShapeCollection.CreateBody,rigid,body={1}", prim.LocalID, aBody);
                    }
                }
                else
                {
                    aBody = PhysicsScene.PE.CreateGhostFromShape(sim, prim.PhysShape.physShapeInfo, prim.LocalID,
                                                                 prim.RawPosition, prim.RawOrientation);
                    if (DDetail)
                    {
                        DetailLog("{0},BSShapeCollection.CreateBody,ghost,body={1}", prim.LocalID, aBody);
                    }
                }

                ReferenceBody(aBody);

                prim.PhysBody = aBody;

                ret = true;
            }
            return(ret);
        }
예제 #2
0
        // Create a body object in Bullet.
        // Updates prim.BSBody with the information about the new body if one is created.
        // Returns 'true' if an object was actually created.
        // Called at taint-time.
        private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletWorld sim, BulletShape shape,
                                BodyDestructionCallback bodyCallback)
        {
            bool ret = false;

            // the mesh, hull or native shape must have already been created in Bullet
            bool mustRebuild = !prim.PhysBody.HasPhysicalBody;

            // If there is an existing body, verify it's of an acceptable type.
            // If not a solid object, body is a GhostObject. Otherwise a RigidBody.
            if (!mustRebuild)
            {
                CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(prim.PhysBody.ptr);
                if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY ||
                    !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT)
                {
                    // If the collisionObject is not the correct type for solidness, rebuild what's there
                    mustRebuild = true;
                }
            }

            if (mustRebuild || forceRebuild)
            {
                // Free any old body
                DereferenceBody(prim.PhysBody, true, bodyCallback);

                BulletBody aBody;
                Object     bodyPtr = null;
                if (prim.IsSolid)
                {
                    bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr,
                                                                prim.LocalID, prim.RawPosition, prim.RawOrientation);
                    if (DDetail)
                    {
                        DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString());
                    }
                }
                else
                {
                    bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr,
                                                                 prim.LocalID, prim.RawPosition, prim.RawOrientation);
                    if (DDetail)
                    {
                        DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString());
                    }
                }
                aBody = new BulletBody(prim.LocalID, bodyPtr);

                ReferenceBody(aBody, true);

                prim.PhysBody = aBody;

                ret = true;
            }

            return(ret);
        }
예제 #3
0
        // Create a body object in Bullet.
        // Updates prim.BSBody with the information about the new body if one is created.
        // Returns 'true' if an object was actually created.
        // Called at taint-time.
        private bool CreateBody(bool forceRebuild, BSPrim prim, BulletSim sim, BulletShape shape,
                                ShapeData shapeData, BodyDestructionCallback bodyCallback)
        {
            bool ret = false;

            // the mesh, hull or native shape must have already been created in Bullet
            bool mustRebuild = (prim.BSBody.ptr == IntPtr.Zero);

            // If there is an existing body, verify it's of an acceptable type.
            // If not a solid object, body is a GhostObject. Otherwise a RigidBody.
            if (!mustRebuild)
            {
                CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(prim.BSBody.ptr);
                if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY ||
                    !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT)
                {
                    // If the collisionObject is not the correct type for solidness, rebuild what's there
                    mustRebuild = true;
                }
            }

            if (mustRebuild || forceRebuild)
            {
                DereferenceBody(prim.BSBody, true, bodyCallback);

                BulletBody aBody;
                IntPtr     bodyPtr = IntPtr.Zero;
                if (prim.IsSolid)
                {
                    bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr,
                                                                shapeData.ID, shapeData.Position, shapeData.Rotation);
                    // DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X"));
                }
                else
                {
                    bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr,
                                                                 shapeData.ID, shapeData.Position, shapeData.Rotation);
                    // DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X"));
                }
                aBody = new BulletBody(shapeData.ID, bodyPtr);

                ReferenceBody(aBody, true);

                prim.BSBody = aBody;

                ret = true;
            }

            return(ret);
        }
예제 #4
0
 public void SetInternalType(CollisionObjectTypes types)
 {
     m_internalType = types;
 }
예제 #5
0
 public void SetInternalType(CollisionObjectTypes types)
 {
     m_internalType = types;
 }