private static void _createPlane( Mesh mesh )
{
SubMesh sub = mesh.CreateSubMesh();
float[] vertices = new float[ 32 ] {
-100, -100, 0, // pos
0,0,1, // normal
0,1, // texcoord
100, -100, 0,
0,0,1,
1,1,
100, 100, 0,
0,0,1,
1,0,
-100, 100, 0 ,
0,0,1,
0,0
};
mesh.SharedVertexData = new VertexData();
mesh.SharedVertexData.vertexCount = 4;
VertexDeclaration decl = mesh.SharedVertexData.vertexDeclaration;
VertexBufferBinding binding = mesh.SharedVertexData.vertexBufferBinding;
int offset = 0;
decl.AddElement( 0, offset, VertexElementType.Float3, VertexElementSemantic.Position );
offset += VertexElement.GetTypeSize( VertexElementType.Float3 );
decl.AddElement( 0, offset, VertexElementType.Float3, VertexElementSemantic.Normal );
offset += VertexElement.GetTypeSize( VertexElementType.Float3 );
decl.AddElement( 0, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0 );
offset += VertexElement.GetTypeSize( VertexElementType.Float2 );
HardwareVertexBuffer vbuf = HardwareBufferManager.Instance.CreateVertexBuffer( decl, 4, BufferUsage.StaticWriteOnly );
binding.SetBinding( 0, vbuf );
vbuf.WriteData( 0, vbuf.Size, vertices, true );
sub.useSharedVertices = true;
HardwareIndexBuffer ibuf = HardwareBufferManager.Instance.CreateIndexBuffer( IndexType.Size16, 6, BufferUsage.StaticWriteOnly );
short[] faces = new short[ 6 ] { 0, 1, 2, 0, 2, 3 };
sub.IndexData.indexBuffer = ibuf;
sub.IndexData.indexCount = 6;
sub.IndexData.indexStart = 0;
ibuf.WriteData( 0, ibuf.Size, faces, true );
mesh.BoundingBox = new AxisAlignedBox( new Vector3( -100, -100, 0 ), new Vector3( 100, 100, 0 ) );
mesh.BoundingSphereRadius = Utility.Sqrt( 100 * 100 + 100 * 100 );
}