Sign in to follow this  

replacement for mesh.DrawSubset()

This topic is 4374 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In C++:

	
num_of_faces=mesh->GetNumFaces();
num_of_vertices=mesh->GetNumVertices();
mesh->GetIndexBuffer(&ib);
mesh->GetVertexBuffer(&vb);
fvf=mesh->GetFVF();
fvfsize=D3DXGetFVFVertexSize(fvf);

//render
g_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#

Share this post


Link to post
Share on other sites
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[i].Material3D;
device.SetTexture(0, mesh.GetTextures()[i]);
// 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);




}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 device
g_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[i].VertexStart, //MinIndex
pAttr[i].VertexCount,//NumVertices
pAttr[i].FaceStart * 3, //StartIndex
pAttr[i].FaceCount //NumPrimitives
);
}



hth
Jack

Share this post


Link to post
Share on other sites

This topic is 4374 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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