• Advertisement
Sign in to follow this  

Simple Custom Model Format (solved)

This topic is 3511 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am following a tutorial, specifically the one about vertex and index buffers. I think that I understand what they are: vertex buffers hold vertices and index buffers provide a way to reuse the triangles formed by the vertices. The problem that I'm having is that a box that I exported was extremely skewed. I wrote an exporter for my modeling program to export just the geometry, and I am 100% sure that is is giving me the right data, but it isn't rendering properly. The format is simple - vertex count, then x/y/z of all vertices, then face count followed by the face x/y/z. I've debugged the loading section just to make sure. Basically, I have this vertex structure:
struct CUSTOMVERTEX
{
	float x, y, z; // Position in 3d space
	DWORD color;   // Color
};

CUSTOMVERTEX *gt = NULL;
USHORT *gti = NULL;


Where gt is my actual vertices once loaded in to be used for my vertex buffer, and gti is the indices to be used in the index buffer. Here is where I create the buffers (see the source at the tutorial):
    m_VB.CreateBuffer(pDevice, vertCount, D3DFVF_XYZ | D3DFVF_DIFFUSE, sizeof(CUSTOMVERTEX));
    m_VB.SetData(vertCount, gt);
    m_IB.CreateBuffer(pDevice, faceCount * 3, D3DFMT_INDEX16);
    m_IB.SetData(faceCount * 3, gti);
    m_VB.SetIndexBuffer(&m_IB);



And rendering:
	pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
	pDevice->BeginScene();

    pDevice->SetTransform( D3DTS_WORLD, m_transform.GetTransform() );
	vb.Render( pDevice, faceCount, D3DPT_TRIANGLELIST );

	pDevice->EndScene();
	pDevice->Present(0, 0, 0, 0);


Now, I am guessing that a face is just a fancy name for a triangle. Perhaps this is where I am going wrong, but I'm not sure. The exports for the face x/y/z of faces of a simple box look like
[1,3,4]
[4,2,1]
[5,6,8]
[8,7,5]
[1,2,6]
[6,5,1]
[2,4,8]
[8,6,2]
[4,3,7]
[7,8,4]
[3,1,5]
[5,7,3]



...I figured these numbers to be the correct indexes for the buffer. Am I wrong in this assumption? If not, then how do I get the correct indices? Pardon me if I sound like a complete noob to 3d programming; I am. Thanks for your help. [Edited by - Kuraitou on July 13, 2008 1:03:49 PM]

Share this post


Link to post
Share on other sites
Advertisement
I suspect your indices, Kuraitou. It appears that each of the face indices should be reduced by 1.

That is, [1,3,4] should be [0,2,3], [4,2,1] should be [3,1,0], etc.

Remember, indexing is zero-based! [smile]

By the way, the term "face" is used because an object face isn't always a triangle. It could be a quad, for instance.

Share this post


Link to post
Share on other sites
That was the problem, apparently. I do feel quite stupid for not realizing it earlier, many thanks and ++ratings.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement