FVF question
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!
You can use bitmasks to determine the vertex format. However, mesh->GetDeclaration(..) would probably be easier.
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!
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.
Then vertOffset and normalOffset will be the offset in bytes from the beginning of each vertex in the buffer.
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.Stream == 0xff) break; if( elems.Type == D3DDECLTYPE_FLOAT3 && elems.Usage == D3DDECLUSAGE_NORMAL && elems.UsageIndex == 0 ) { hasNormals = TRUE; normalOffset = elems.Offset; } if( elems.Type == D3DDECLTYPE_FLOAT3 && elems.Usage == D3DDECLUSAGE_POSITION && elems.UsageIndex == 0 ) { hasVerts = TRUE; vertOffset = elems.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.
Thanks for your help Buckeye. I am using your method to extract the position information. The following is a initial draft approach.
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.
pVertBuf->Lock(0, 0, (void **) &pVoid, 0);char *pTemp = (char *)&pVoidpTemp += 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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement