Sign in to follow this  
akaitora

FVF question

Recommended Posts

Once I load a 3d asset and get a pointer to its vertex buffer, I would like to draw lines which represent each vertices normal. In order to do that, I need information such as the order that the vertex attributes are defined so that I can decode the data. What is the best way to do this? I can call the getFVF() method on the mesh and I am assuming I can do some bit masking to get the orders but I would like to know how you guys would normally do it. Thanks!

Share this post


Link to post
Share on other sites
Thanks Buckeye! If it wouldn't be too much trouble, could you please show me an example on how to use the GetDeclaration method? I am not really sure how to use the d3dvertexelement structure to get the information I need. Thanks in advance!

Share this post


Link to post
Share on other sites
Modified from DXNut's post in the thread solenoidz mentions. Off the top of my head, so look for errors! By the way, if you want to display normals, you'll need the vertex position for each instance also. The line you want to draw will be from vertex_pos to vertex_pos + normal.
D3DVERTEXELEMENT9 elems[MAX_FVF_DECL_SIZE];
BOOL hasVerts = FALSE, hasNormals = FALSE;
WORD normalOffset, vertOffset;
hr = ObjectMesh->GetDeclaration(elems);
if (SUCCEEDED(hr))
{
for(int i = 0; i < MAX_FVF_DECL_SIZE; ++i)
{
// Did we reach D3DDECL_END() {0xFF,0,D3DDECLTYPE_UNUSED, 0,0,0}?
if(elems[i].Stream == 0xff)
break;

if( elems[i].Type == D3DDECLTYPE_FLOAT3 &&
elems[i].Usage == D3DDECLUSAGE_NORMAL &&
elems[i].UsageIndex == 0 )
{
hasNormals = TRUE;
normalOffset = elems[i].Offset;

}
if( elems[i].Type == D3DDECLTYPE_FLOAT3 &&
elems[i].Usage == D3DDECLUSAGE_POSITION &&
elems[i].UsageIndex == 0 )
{
hasVerts = TRUE;
vertOffset = elems[i].Offset;
}
}
}
if( !hasNormals || !hasVerts ) { .. process some error message .. }



Then vertOffset and normalOffset will be the offset in bytes from the beginning of each vertex in the buffer.

Share this post


Link to post
Share on other sites
Thanks for your help Buckeye. I am using your method to extract the position information. The following is a initial draft approach.


pVertBuf->Lock(0, 0, (void **) &pVoid, 0);
char *pTemp = (char *)&pVoid;
pTemp += wPositionOffset;
float *fTemp = (float *)pTemp;
float x = *fTemp;
float y = *++fTemp;
float z = *++fTemp;

m_pRenderEngine->drawLine(D3DXVECTOR3(x,y,z), D3DXVECTOR3(0,1000,0), D3DXCOLOR(1,0,0,1));


Unfortunately, I am getting faulty values for the x, y, z components. I am sure I am doing something wrong but not sure what. Could you give me a pointer? Thanks.

Share this post


Link to post
Share on other sites
Quote:
The line you want to draw will be from vertex_pos to vertex_pos + normal.

The buffer is comprised of a bunch of vertex structures in series in memory. You're using the first vertex in the buffer, and that's fine for your demonstration.

It appears you're getting the vertex position from that first vertex. You also need to get the normal, if that's what you want to draw.

Create a vector (vertex_pos) with the vertex position from the buffer. Create another vector (normal) with the normal from the buffer.

Draw a line from vertex_pos to vertex_pos + normal - from one point to another. I'm not sure what your drawLine function does.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this