Hi,
New to 3d concepts, but have been experimenting with SharpDX (i have been using XNA in a 2d capacity previously) and wondering about loading Vertices from an external source..
Looking at the Sample code from the SharpDX sdk, It hard codes the vertices of a triangle, Now its my understanding that a mesh is just a list of vertices contained within in a file(among other things) So my hypothesis is that i could draw that triangle in blender, and load it from file, then draw it?
IF this is the case, whats a good way to go about doing this? primary thoughts would be to create a class to hold that data...
Here's the SharpDX template for reference:
namespace MiniTri
{
[StructLayout(LayoutKind.Sequential)]
struct Vertex
{
public Vector4 Position;
public SharpDX.Color Color;
}
/// <summary>
/// SlimDX2 port of SlimDX-MiniTri Direct3D9 Sample
/// </summary>
static class Program
{
[STAThread]
static void Main()
{
var form = new RenderForm("SlimDX2 - MiniTri Direct3D9 Sample");
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(form.ClientSize.Width,form.ClientSize.Height));
var vertices = new VertexBuffer(device, 3 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
vertices.Lock(0, 0, LockFlags.None).WriteRange(new[] {
new Vertex() { Color = Color.Red, Position = new Vector4(400.0f, 100.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Blue, Position = new Vector4(650.0f, 500.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Green, Position = new Vector4(150.0f, 500.0f, 0.5f, 1.0f) }
});
vertices.Unlock();
var vertexElems = new[] {
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
};
var vertexDecl = new VertexDeclaration(device, vertexElems);
RenderLoop.Run(form, () =>
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
device.BeginScene();
device.SetStreamSource(0, vertices, 0, 20);
device.VertexDeclaration = vertexDecl;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
device.EndScene();
device.Present();
});
}
}
}