Simply put...how do I combine a bunch of quads (billboards) into a single mesh?

Started by
3 comments, last by Supernat02 19 years, 7 months ago
Simply put...how do I combine a bunch of quads (billboards) into a single mesh? Thanks a lot.
Advertisement
Just lock the vertex buffer, copy each vertex from the billboards into the buffer, then unlock it. It's just like filling 1 vertex buffer for 1 billboard, but now you fill 1 vertex buffer for more than one billboard. Everything must be in triangle lists, unless you want to use degenerate triangles, but then that gets complicated and is frankly a waste of time for the "possible" increase in speed you might get. Most cards like triangle lists now days (or so I've heard.) anyway. Any questions?

Chris
Chris ByersMicrosoft DirectX MVP - 2005
Thanks Chris. You at least confirm that I'm barking up the right tree...however, it still doesn't work, and since you asked, I do have some questions on the DX mechanics of doing this.

Up til now all of my meshes were loaded from X files using D3DXLoadMeshFromX, or something like that, which takes as arguements the number of materials in the mesh and pointers to the materials and Texture buffers.

To combine my quads into a mesh I'm trying to use D3DXCreateMeshFVF, which doesn't take any arguements regarding materials or textures. So how do I associate the texture buffer with the mesh? I.e., to render the mesh with DrawSubset(attrib), how does the mesh know how many subsets to draw? Also, after creating the mesh, how would I load it?

Hope this makes sense. Thanks again.
Maybe you should start to use vertex and index buffers directly instead of using the D3DX helper classes. They really aren't that complicated and give you way more control over what you are doing. Writing your own CMesh class shouldn't take that long.
First, to load the mesh, you would lock the vertex buffer and fill it like any other vertex buffer, then unlock it.

Next, you need to fill the attribute table. It basically declares which vertices will be separate from others. The number of entries in the attribute table define the number of subsets. See the following example:

#define FVF (D3DFVF_XYZ)ID3DXMesh *pMesh;struct FVFStruct{  D3DXVector3 Position;}FVFStruct *Data;FVFStruct Vertices[30] {//Initialize to something}; // 10 triangles, 5 quadsD3DXATTRIBUTERANGE Attributes[5]; // 5 Attributes from 10 triangles, so 5 quads are using separate textures, render states, etc.Attributes[0].AttribId = 0;Attributes[0].FaceStart = 0;Attributes[0].FaceCount = 1;Attributes[0].VertexStart = 0;Attributes[0].VertexCount = 3;Attributes[1].AttribId = 1;Attributes[1].FaceStart = 1;Attributes[1].FaceCount = 1;Attributes[1].VertexStart = 3;Attributes[1].VertexCount = 3;// repeat for all 5.D3DXCreateMeshFVF(..., FVF, pDevice, &pMesh);pMesh->LockVertexBuffer(D3DLOCK_NOOVERWRITE, (VOID*)&Data);// Fill the 10 structures here, I'm skipping that part.pMesh->UnlockVertexBuffer();pMesh->SetAttributeTable(Attributes, 5/*Num Attributes*/);


Chris
Chris ByersMicrosoft DirectX MVP - 2005

This topic is closed to new replies.

Advertisement