I am trying to load a file I exported from 3D Studio.
The file I exported contains 16 objects.
To export I dumped all vertices to file in one long shot.
Then for each object I dumped it's faces out to file.
I am loading this info into DirectX. All vertices into one large VB and all
face info into 16 different index buffers. When I run the program I see nothing.
The model is centered at origin. It's extents are 1000+- in X and Y axes and 15+- on Z axis. I have a camera pointed at origin located 3500 units up (the z axis) so I should be looking straight down at the mesh. I've also -3500 units for the camera thinking it was a backfacing issue.
Code to fill the vertex buffer
device.VertexFormat = CustomVertex.PositionColored.Format;
CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored
[_Vertexes.Count];
int i;
for(i=0; i<_Vertexes.Count; i++)
{
verts.Position = new Vector3(((Vertex)_Vertexes).GetVertexX(),
((Vertex)_Vertexes).GetVertexY(),
((Vertex)_Vertexes).GetVertexZ());
verts.Color = System.Drawing.Color.Aqua.ToArgb();
}
VertexBuffer vb = new VertexBuffer(typeof(CustomVertex.PositionColored), _Vertexes.Count, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);
vb.SetData(verts, 0, LockFlags.None);
device.SetStreamSource(0,vb, 0);
Code to fill and render Index Buffers
short[] indices;
int i;
indices = new short[_IndexArray.Count];
for(i=0; i<indices.Length; i++)
{
indices = (short)_IndexArray;
}
IndexBuffer ib = new IndexBuffer(typeof(short), indices.Length, device, Usage.WriteOnly, Pool.Default);
device.Indices = ib;
device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0, 0, 10521, 0,indices.Length/3);
Code to setup camera and other matrices
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, 1.0f, 10000.0f);
device.Transform.View = Matrix.LookAtLH(new Vector3(0,0, distance), new Vector3(0,0,0), new Vector3(0,1,0));
device.RenderState.Lighting = false;
device.Transform.World = Matrix.RotationZ(angle / (float)Math.PI);
device.RenderState.FillMode = FillMode.WireFrame;
angle += 0.1f;
distance is my z (it starts at 3500 and I can move it up or down with the keyboard)
angle is simply used to rotate the camera around the z axis a little each frame.
The mesh file contains 10521 vertices.
The part of the mesh I want to render with the Index Buffer contains 3309 indices so 1103 faces to render out of a total of 18410 faces.
However, nothing is showing up.
Thanks for having a look,
Webby