Archived

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

loading meshes from .X files in dx8

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

Hi, could someone give me a small sample code for loading an .X file into my scene? I''m trying to load from D3DXLoadMeshFromX(); but it fails, I really need some help!

Share this post


Link to post
Share on other sites
Ok, here's an example... Let's say we have a structure that hold all our data:
      
typedef struct MESHSTRUCT
{

LPD3DXMESH mesh; //The mesh

D3DMATERIAL8* d3dm; //The material

LPDIRECT3DTEXTURE8* texture; //The texture

DWORD NumMaterials;//The number of materials



} MESH, *LPMESH;


Ok then, we load the model into this structure like this:

  
//Load the mesh

MESH mesh;
LPD3DXBUFFER lpd3dxb;

if (FAILED(D3DXLoadMeshFromX("THE_FILE.X", D3DXMESH_SYSTEMMEM, lpd3dd, NULL, &lpd3dxb, &mesh.NumMaterials, &mesh.mesh)))
return(0);

//Get the material into the mesh structure

D3DXMATERIAL* d3dxm = (D3DXMATERIAL*) lpd3dxb->GetBufferPointer();

mesh.d3dm = new D3DMATERIAL8[mesh.NumMaterials];
mesh.texture = new LPDIRECT3DTEXTURE8[mesh.NumMaterials];

for (i=0;i<mesh.NumMaterials;i++)
{
mesh.d3dm[i] = d3dxm[i].MatD3D;
mesh.d3dm[i].Ambient = mesh.d3dm[i].Diffuse;

if (FAILED(D3DXCreateTextureFromFile(lpd3dd, d3dxm[i].pTextureFilename, &mesh.texture[i])))
mesh.texture[i] = NULL;
}

//Release lpd3dxb because we don't need it anymore

lpd3dxb->Release();


If you want to know how to draw it on the screen, just ask me...

Edited by - Strange Monkey on August 1, 2001 11:23:21 PM

Share this post


Link to post
Share on other sites
You could look at the sample in the SDK. Its fairly well explained except I could never get lighting to properly work with it.

Share this post


Link to post
Share on other sites
here's what i have...
pad is a Class that holds the structures (mesh, materials, num_materials, etc.)


// Draw from the mesh we loaded from x file ///////////////////////////////////////

// Meshes are divided into subsets, one for each material. Render them in
// a loop
for( DWORD j=0; j<pad.dwNumMaterials; j++ )
{
// Set the material and texture for this subset
g_pd3dDevice->SetMaterial( &pad.lp_MeshMaterials[j] );
g_pd3dDevice->SetTexture( 0, pad.lp_MeshTextures[j] );

// Draw the mesh subset
pad.mesh->DrawSubset( j );
}


riz

[edited by - riz on May 2, 2002 3:52:36 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Strange Monkey


If you want to know how to draw it on the screen, just ask me...

Edited by - Strange Monkey on August 1, 2001 11:23:21 PM


Perhaps you could tell me how to animate an xfile, or where i can find out for myself? Or is the skinned mesh example the only source around? Thanks.

"Sweetie! Get Mommy''s bazooka!"

Share this post


Link to post
Share on other sites