views:

183

answers:

2

Hello,

I'm trying to read 3D models which were created for a DirectX applications, which are defined in the following way :

  • In the file header, the Flexible Vertex Format (FVF) of the mesh is given (actually, I have any combinations of D3DFVF_{XYZ,DIFFUSE,NORMAL,TEX1,TEX2} in the meshes I tested)
  • Then, n vertices are given in a linear pattern, with the fields presents according to the FVF.

However, I do not know the order of these fields. The logic would be that it is defined somewhere in DirectX documentation, but I was unable to find it. For example, which of these two structures is correct with FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL (C syntax, but this problem applies to every language) ?

// This one ?
struct vertex1
{
    D3DVERTEX pos;
    DWORD color;
    D3DVERTEX normal;
};

// Or this one ?
struct vertex2
{
    D3DVERTEX pos;
    D3DVERTEX normal;
    DWORD color;
};

I would like a general answer to this question with all the possible fields (for example, XYZ before DIFFUSE before NORMAL before TEX1 before TEX2). A pointer to the right page of the documentation would be fine too as I was not able to find it :) .

+1  A: 

Well you should be defining it as follows.

struct EitherVertex
{
    float x, y, z;
    DWORD col;
    float nx, ny, nz
};

or

struct EitherVertex
{
    D3DXVECTOR3 pos;
    DWORD col;
    D3DXVECTOR3 nrm;
};

(D3DVERTEX refers to an entire vertex struct and not just a 3 element vector)

Of your 2 options a lot depends on how you access those vert elements. If you are using the depreceated FVF then the second of your 2 choice is the more correct.

If however you are using Vertex Declarations then YOU define where in the struct the relevant data is and the ordering does not matter.

Goz
The problem is the general order, should DIFFUSE always be before NORMAL ? What about TEX1, TEX2, etc. ?I'm not using vertex declarations because the original file format is not using them. In fact I'm using the data in the file to draw the mesh with OpenGL :) .
Pierre Bourdon
The problem the OP is having is that in C/C++, the order of a struct is important when using FVF. The FVF has to be arranged correctly to work.
Andrew Keith
+2  A: 

here you are

FVF (OP says the information on this page is incorrect. I dont know, didnt check if FVF positioning is correct)

Generator

Andrew Keith
The first link does not really define the order of the fields in the structure (already read it before asking the question). However, the second link seems to be fairly complete, thanks a lot !
Pierre Bourdon