Skip to main content
GameDev.net gamedev.net
🔒 Locked

replacement for mesh.DrawSubset()

Started by jad_salloum Dec 17, 2005 at 4:17 AM 11 replies 3.4k views
Original Post
jad_salloum
jad_salloum
hi guys is there any way to draw a mesh without using mesh.drawsubset ??? i think that it can be drawn using device.drawPrimitives but am not sure about it and how to do it ,with what mesh.drawsubset can be replaced ??
gymisi
gymisi
In C++:

	num_of_faces=mesh->GetNumFaces();num_of_vertices=mesh->GetNumVertices();mesh->GetIndexBuffer(&ib);mesh->GetVertexBuffer(&vb);fvf=mesh->GetFVF();fvfsize=D3DXGetFVFVertexSize(fvf);//renderg_device->SetFVF(fvf);g_device->SetIndices(ib);g_device->SetStreamSource(0,vb,0,fvfsize);g_device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,num_of_vertices,0,num_of_faces);


msdn: In C#
Blog(Hungarian)MDX - C# - C++
jad_salloum
jad_salloum
thanx for ur reply , look i am converting it to c# but there is no mesh.getFVF

do u know with what i can replace these lines ?
fvf=mesh->GetFVF();
fvfsize=D3DXGetFVFVertexSize(fvf);
g_device->SetFVF(fvf);
jad_salloum
jad_salloum
this is my source but i am not getting any thing on the screen when i run the game please tell me where is the error in it


	device.Transform.World = AllMatrix;					///mesh is the MeshContainer				ExtendedMaterial[] materials = mesh.GetMaterials();				for (int i = 0; i < materials.Length; ++i)				{					device.Material = materials.Material3D;					device.SetTexture(0, mesh.GetTextures());				//	mesh.MeshData.Mesh.DrawSubset(i);								int numFaces = mesh.MeshData.Mesh.NumberFaces;					int numVertexs = mesh.MeshData.Mesh.NumberVertices;					IndexBuffer ib = mesh.MeshData.Mesh.IndexBuffer;					VertexBuffer vb = mesh.MeshData.Mesh.VertexBuffer;					VertexFormats fvf= mesh.MeshData.Mesh.VertexFormat;					device.VertexFormat=fvf;					device.Indices=ib;					device.SetStreamSource(0,vb,0);					device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,numVertexs,0,numFaces);		


}
jollyjeffers
jollyjeffers
Your code wont properly work for a mesh with more than 1 material [smile]

For each material you're drawing the entire mesh - so for multiple materials you'll basically get a complete mess where it attempts to combine all the materials together.

You need to customize the draw call such that it only renders the correct part for that subset. That is, you need to examine the attribute table.

I'm not a C# programmer, so I don't know exactly what it'll look like... but try Mesh.GetAttributeTable() to get an array of AttributeRange structures. For each subset, you need to use the corresponding values from the AttributeRange.

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
jad_salloum
jad_salloum
ya it works if i use mesh.drawsubset .
Quote:

For each material you're drawing the entire mesh - so for multiple materials you'll basically get a complete mess where it attempts to combine all the materials together.


ya i didnot pay attention to this material error but should't it draw it with messy material ?? at least something should appear on the screen

Quote:

you need to examine the attribute table

i didnot work with it before is there any SDK or any sample that demonstrates this tecnique ?

rate +++ for u guys
jad_salloum
jad_salloum
is there any other advice ??
jollyjeffers
jollyjeffers
Have you tried using the debug runtimes? I can't see any mention of that in the thread?

If you get the params to DIP() wrong then it's likely to ignore the whole call - thus not rendering anything. If this is the case you'll often get 100's if not 1000's of messages from the debug runtime screaming-and-shouting about what it doesn't like [smile]

I'm running under Vista right now which doesn't pick up my RAID array, but when I get back to XP I'll see about digging up my re-implementation of DrawSubset() - it's in C++, but it should be trivial enough to convert.

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
jollyjeffers
jollyjeffers
LPDIRECT3DVERTEXBUFFER9 pVB = NULL;LPDIRECT3DINDEXBUFFER9  pIB = NULL;g_pMesh->GetVertexBuffer( &pVB );g_pMesh->GetIndexBuffer( &pIB );DWORD attrSize = 0;g_pMesh->GetAttributeTable( NULL, &attrSize );D3DXATTRIBUTERANGE *pAttr = new D3DXATTRIBUTERANGE[ attrSize ];g_pMesh->GetAttributeTable( pAttr, &attrSize );// Configure the deviceg_pd3dDevice->SetFVF( g_pMesh->GetFVF() );g_pd3dDevice->SetStreamSource( 0, pVB, 0, D3DXGetFVFVertexSize( g_pMesh->GetFVF() ) );g_pd3dDevice->SetIndices( pIB );for( int i = 0; i < g_dwNumMaterials; i++ ){    g_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,                                         0,//BaseVertexIndex                                        pAttr.VertexStart, //MinIndex                                        pAttr.VertexCount,//NumVertices                                        pAttr.FaceStart * 3, //StartIndex                                        pAttr.FaceCount //NumPrimitives                                      );}


hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
jad_salloum
jad_salloum
thanks alot man i will try to convert it
TheMaskedFace
TheMaskedFace
when I try to invert it to c#, I can not see anything on render screen
wake up your sleepin' brains...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.