예제 #1
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);
        }