Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DangerDave

Learning meshes

This topic is 5461 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

I''m just looking into meshes now and I cant find any good tutorials or documentation on .X meshes. Loading a mesh isnt that big a problem going off the good ''ole DX9 tutorial, but what about when it comes to collision detection and whatnot? How do you find the normal of a face, or the vertices that make up that face? Do meshes use triangle strips or lists or indexed, and if indexed how is texturing done? I cant find any good sources for learning the intricacies of meshes anywhere, anyone any good links? Dave.

Share this post


Link to post
Share on other sites
Advertisement
the "pick" tutorial in the SDK is good as far as mesh breakdown.

the "skinned mesh" tutorial is brainheavy but good once you digest it.

and finally Jim Adams has a good tutorial on parsing .X files when your ready to get into the heavy lifting here on gamedev.

Share this post


Link to post
Share on other sites
Meshes are a bitch to learn

heres 2 functions that i made load and draw. By the way it is setup for lighting but should work normally without it.

its from the sdk basically modified. The "5" means theres 0 -4 spaces for models in the array. I modified it to take an array of meshes.



normal declarations like every other dx9 stuff
quote:

LPD3DXMESH myMesh[5];
D3DMATERIAL9* myMeshMaterials[5];
LPDIRECT3DTEXTURE9* myMeshTextures[5];
DWORD myNumMaterials[5];



draw mesh
quote:

void DrawMesh(int index=0, int keyFrame =-1)
{
for( DWORD i=0; i {
myDevice->SetMaterial( &myMeshMaterials[index] );
myDevice->SetTexture( 0, myMeshTextures[index][i] );
myMesh[index]->DrawSubset( i );
}
}




load mesh
quote:

void LoadMesh(char mesh[],int index=0)
{

LPD3DXBUFFER pD3DXMtrlBuffer;
D3DXLoadMeshFromX( mesh, D3DXMESH_SYSTEMMEM, myDevice, NULL, &pD3DXMtrlBuffer, NULL, &myNumMaterials[index], &myMesh[index] ) ;
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
myMeshMaterials[index] = new D3DMATERIAL9[myNumMaterials[index]];
myMeshTextures[index] = new LPDIRECT3DTEXTURE9[myNumMaterials[index]];

for( DWORD i=0; i {
myMeshMaterials[index][i] = d3dxMaterials[i].MatD3D;
myMeshMaterials[index][i].Ambient = myMeshMaterials[index][i].Diffuse;

myMeshTextures[index][i] = NULL;
if( d3dxMaterials[i].pTextureFilename != NULL && lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )
D3DXCreateTextureFromFile( myDevice, d3dxMaterials[i].pTextureFilename, &myMeshTextures[index][i] ) ;
}
pD3DXMtrlBuffer->Release();

DWORD fvf = ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_SPECULAR | D3DFVF_TEX1 );

myMesh[index]->CloneMeshFVF( D3DXMESH_MANAGED, fvf, myDevice, &myMesh[index]);
D3DXComputeNormals( myMesh[index], 0);

}






and clean up code is
quote:

for(int g=0;g<5;g++)
{
if( myMesh[g] != NULL )
myMesh[g]->Release();

if( myMeshMaterials[g] != NULL )
delete[] myMeshMaterials[g];

if( myMeshTextures[g] )
{
for( DWORD i = 0; i < myNumMaterials[g]; i++ )
{
if( myMeshTextures[g][i] )
myMeshTextures[g][i]->Release();
}
delete[] myMeshTextures[g];
}
}



Its to hard to bother understanding properly i reakon. If you need to modify something, just learn enough to do that.


also note that ive renamed the usual device etc to things like myDevice


[edited by - johnnyBravo on August 7, 2003 7:56:37 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!