Example #1
0
        ShapeData CreateShape(CollisionShape shape)
        {
            ShapeData shapeData = new ShapeData();

            if (shape.ShapeType == BroadphaseNativeType.SoftBodyShape)
            {
                // Soft body geometry is recreated each frame. Nothing to do here.
                return(shapeData);
            }

            uint[] indices;
            BulletSharp.Math.Vector3[] vertexBuffer = CreateShape(shape, out indices);

            if (vertexBuffer != null)
            {
                shapeData.VertexCount = vertexBuffer.Length / 2;

                Vector3[] vertices = new Vector3[shapeData.VertexCount];
                Vector3[] normals  = new Vector3[shapeData.VertexCount];

                int i;
                for (i = 0; i < shapeData.VertexCount; i++)
                {
                    vertices[i] = vertexBuffer[i * 2];
                    normals[i]  = vertexBuffer[i * 2 + 1];
                }

                shapeData.SetVertexBuffer(vertices);
                shapeData.SetNormalBuffer(normals);
            }

            if (indices != null)
            {
                ushort[] indices_s = CompactIndexBuffer(indices);
                if (indices_s != null)
                {
                    shapeData.SetIndexBuffer(indices_s);
                }
                else
                {
                    shapeData.SetIndexBuffer(indices);
                }
                shapeData.ElementCount = indices.Length;
            }

            return(shapeData);
        }
Example #2
0
        ShapeData CreateShape(CollisionShape shape)
        {
            ShapeData shapeData = new ShapeData();

            uint[] indices;
            BulletSharp.Vector3[] vertexBuffer = CreateShape(shape, out indices);

            if (vertexBuffer != null)
            {
                shapeData.VertexCount = vertexBuffer.Length / 2;

                Vector3[] vertices = new Vector3[shapeData.VertexCount];
                Vector3[] normals  = new Vector3[shapeData.VertexCount];

                int i;
                for (i = 0; i < shapeData.VertexCount; i++)
                {
                    vertices[i] = vertexBuffer[i * 2];
                    normals[i]  = vertexBuffer[i * 2 + 1];
                }

                shapeData.SetVertexBuffer(vertices);
                shapeData.SetNormalBuffer(normals);
            }

            if (indices != null)
            {
                ushort[] indices_s = CompactIndexBuffer(indices);
                if (indices_s != null)
                {
                    shapeData.SetIndexBuffer(indices_s);
                }
                else
                {
                    shapeData.SetIndexBuffer(indices);
                }
                shapeData.ElementCount = indices.Length;
            }

            return(shapeData);
        }