Jump to content
  • Advertisement

Archived

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

lincsimp

Load Mesh Tutorial

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

Advertisement
the function that load a mesh changes in relation to the type of model...
which model you want to use? md2, md3, x, 3ds???

Share this post


Link to post
Share on other sites
In the DirectX9 docs, use the following path:
DirectX Graphics -> Tutorials and Samples -> Tutorials -> Direct3D Tutorials -> Tutorial 6

Share this post


Link to post
Share on other sites
mesh class, made from the tutorial

class DMesh {
private:
LPDIRECT3DDEVICE9 lp_Device;
LPD3DXMESH lp_Mesh;
D3DMATERIAL9* lp_MeshMaterials;
LPDIRECT3DTEXTURE9* lp_MeshTextures;
DWORD lp_NumMaterials;
bool useMaterial;
public:
DMesh()
{
dsetUseMaterial(true);
}

~DMesh()
{
if( lp_Mesh != NULL )
{
lp_Mesh->Release();
lp_Mesh=NULL;
}

if( lp_MeshTextures )
{
for(DWORD i = 0; i < lp_NumMaterials; i++ )
if( lp_MeshTextures[i] )
{
lp_MeshTextures[i]->Release();
}
}
}
void load(LPDIRECT3DDEVICE9 d3dDevice,string filename)
{
lp_Device = d3dDevice;
lp_Mesh=NULL;
LPD3DXBUFFER pD3DXMtrlBuffer;
D3DXLoadMeshFromX( filename.c_str(), D3DXMESH_SYSTEMMEM, lp_Device, NULL, &pD3DXMtrlBuffer, NULL, &lp_NumMaterials, &lp_Mesh ) ;
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
lp_MeshMaterials = new D3DMATERIAL9[lp_NumMaterials];
lp_MeshTextures = new LPDIRECT3DTEXTURE9[lp_NumMaterials];

for(DWORD i=0; i<lp_NumMaterials; i++ )
{
lp_MeshMaterials[i] = d3dxMaterials[i].MatD3D;
lp_MeshMaterials[i].Ambient = lp_MeshMaterials[i].Diffuse;
lp_MeshTextures[i] = NULL;
if( d3dxMaterials[i].pTextureFilename != NULL && lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )
D3DXCreateTextureFromFile(lp_Device, d3dxMaterials[i].pTextureFilename, &lp_MeshTextures[i] ) ;
}

pD3DXMtrlBuffer->Release();
DWORD fvf = ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_SPECULAR | D3DFVF_TEX1 );
lp_Mesh->CloneMeshFVF( D3DXMESH_MANAGED, fvf, lp_Device, &lp_Mesh);
D3DXComputeNormals( lp_Mesh, 0);
}

void dsetUseMaterial(bool enable)
{
useMaterial = enable;
}
void draw()
{
for( int i=0; i<lp_NumMaterials; i++ )
{
if (!useMaterial)
lp_Device->SetMaterial( &lp_MeshMaterials[i] );

lp_Device->SetTexture( 0, lp_MeshTextures[i] );
lp_Mesh->DrawSubset( i );
}
}
};



edit:
eg

DMesh tiger;

//init
tiger.load("tiger.x");

//render
tiger.draw();

[edited by - johnnyBravo on February 22, 2004 6:43:16 PM]

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!