public static SlimDX.Direct3D9.Mesh XPositionTexcoord(Device device, IndexedFeed feed) { VertexElement[] ve = new VertexElement[]{ new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0), new VertexElement(0, (short)Vector3.SizeInBytes, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0), VertexElement.VertexDeclarationEnd }; SlimDX.Direct3D9.Mesh mesh = null; DataStream vertices = null; DataStream indices = null; bool useShortIndices = true; feed((nVertices, nFaces) => { mesh = new SlimDX.Direct3D9.Mesh(device, nFaces, nVertices, MeshFlags.Managed, VertexFormat.Position | VertexFormat.Texture1); vertices = mesh.VertexBuffer.Lock(0, nVertices*(Vector3.SizeInBytes + Vector2.SizeInBytes), LockFlags.None); indices = mesh.IndexBuffer.Lock(0, sizeof(short)*nFaces*3, LockFlags.None); }, (pos, texcoord) => { vertices.Write(pos); vertices.Write(texcoord); }, (index) => { if (useShortIndices) indices.Write<short>((short)index); else indices.Write<int>((int)index); }); mesh.VertexBuffer.Unlock(); mesh.IndexBuffer.Unlock(); return mesh; }
public static SlimDX.Direct3D9.Mesh XPositionTexcoordNormal(Device device, IndexedFeed feed) { SlimDX.Direct3D9.Mesh mesh = null; DataStream vertices = null; DataStream indices = null; bool useShortIndices = true; feed((nVertices, nFaces) => { mesh = new SlimDX.Direct3D9.Mesh(device, nFaces, nVertices, MeshFlags.Managed, VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Normal); vertices = mesh.VertexBuffer.Lock(0, nVertices * (Vector3.SizeInBytes + Vector2.SizeInBytes + Vector3.SizeInBytes), LockFlags.None); indices = mesh.IndexBuffer.Lock(0, sizeof(short) * nFaces * 3, LockFlags.None); }, (pos, texcoord) => { vertices.Write(pos); vertices.Write(new Vector3(1, 1, 1)); vertices.Write(texcoord); }, (index) => { if (useShortIndices) indices.Write<short>((short)index); else indices.Write<int>((int)index); }); mesh.VertexBuffer.Unlock(); mesh.IndexBuffer.Unlock(); return mesh; }
public static Mesh PositionTexcoord(Device device, IndexedFeed feed) { VertexElement[] ve = new VertexElement[]{ new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0), new VertexElement(0, (short)Vector3.SizeInBytes, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0), VertexElement.VertexDeclarationEnd }; Mesh mesh = new Mesh(); mesh.MeshType = MeshType.Indexed; mesh.VertexFormat = VertexFormat.Position | VertexFormat.Texture1; mesh.VertexSize = Vector3.SizeInBytes + Vector2.SizeInBytes; DataStream vertices = null; DataStream indices = null; bool useShortIndices = true; feed((nVertices, nFaces) => { mesh.NVertices = nVertices; mesh.NFaces = nFaces; if (mesh.NVertices >= short.MaxValue) useShortIndices = false; mesh.Vertices = new VertexBuffer(device, mesh.VertexSize * mesh.NVertices, Usage.None, VertexFormat.None/*mesh.VertexFormat*/, Pool.Managed); mesh.Indices = new IndexBuffer(device, (useShortIndices ? sizeof(short) : sizeof(int)) * mesh.NFaces * 3, Usage.None, Pool.Managed, useShortIndices); vertices = mesh.Vertices.Lock(0, mesh.VertexSize * mesh.NVertices, LockFlags.None); indices = mesh.Indices.Lock(0, (useShortIndices ? sizeof(short) : sizeof(int)) * mesh.NFaces * 3, LockFlags.None); }, (pos, texcoord) => { vertices.Write(pos); vertices.Write(texcoord); }, (index) => { if (useShortIndices) indices.Write<short>((short)index); else indices.Write<int>((int)index); }); mesh.Vertices.Unlock(); mesh.Indices.Unlock(); return mesh; }