Jump to content
  • Advertisement
Sign in to follow this  
Helo7777

Help needed for .x files

This topic is 3883 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 all Im trying to use the code provided by this site "http://toymaker.info/Games/html/load_x_hierarchy.html" to load .x file with animations but the code ive witten seems to crash in this class "HRESULT MeshHierarchy::CreateMeshContainer" and at this point: "if(FAILED(D3DXCreateTextureFromFile(pDevice, texturePath.c_str(), &newMeshContainer->exTextures)))" It can find the texture but wont load it and i have not been able to figure out why. Any help would be great! Heres part of the code ive written: HRESULT MeshHierarchy::CreateMeshContainer( LPCSTR Name, CONST D3DXMESHDATA *meshData, CONST D3DXMATERIAL *materials, CONST D3DXEFFECTINSTANCE *effectInstance, DWORD numMaterials, CONST DWORD *adjacency, LPD3DXSKININFO skinInfo, LPD3DXMESHCONTAINER *retNewMeshContainer) { //create a mesh container D3DXMESHCONTAINER_EXTENDED *newMeshContainer = new D3DXMESHCONTAINER_EXTENDED; ZeroMemory(newMeshContainer, sizeof(D3DXMESHCONTAINER_EXTENDED)); //init return pointer *retNewMeshContainer = 0; if (Name && strlen(Name)) { size_t len=strlen(Name) + 1; char *newString = new char[len]; memcpy(newString, Name, len*sizeof(char)); newMeshContainer->Name = newString; } if (meshData->Type != D3DXMESHTYPE_MESH) { DestroyMeshContainer(newMeshContainer); return E_FAIL; } newMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH; //adjaceny data - holds information about triangle adjacency, required by the ID3DMESH object DWORD dwFaces = meshData->pMesh->GetNumFaces(); newMeshContainer->pAdjacency = new DWORD[dwFaces*3]; memcpy(newMeshContainer->pAdjacency, adjacency, sizeof(DWORD) * dwFaces*3); //get the direct3d device, this is held within the mesh itself LPDIRECT3DDEVICE9 device = 0; meshData->pMesh->GetDevice(&device); newMeshContainer->MeshData.pMesh = meshData->pMesh; newMeshContainer->MeshData.pMesh->AddRef(); //create material and texture arrays. newMeshContainer->NumMaterials = max(numMaterials, 1); newMeshContainer->exMaterials = new D3DMATERIAL9[newMeshContainer->NumMaterials]; newMeshContainer->exTextures = new LPDIRECT3DTEXTURE9[newMeshContainer->NumMaterials]; ZeroMemory(newMeshContainer->exTextures, sizeof(LPDIRECT3DTEXTURE9) * newMeshContainer->NumMaterials); if (numMaterials > 0) { //load all the textures and copy the materials over for (DWORD i = 0; i < numMaterials; ++i) { newMeshContainer->exTextures = 0; newMeshContainer->exMaterials = materials.MatD3D; if (materials.pTextureFilename) { std::string texturePath(materials.pTextureFilename); XFileMesh name(device); if (name.FindFile(&texturePath)) { if (FAILED(D3DXCreateTextureFromFile(device, texturePath.c_str(), &newMeshContainer->exTextures))); { MessageBox(NULL,"Could not load texture ", "Meshes.exe", MB_OK); return false; } } else { MessageBox(NULL,"Could not find texture ", "Meshes.exe", MB_OK); return false; } } } } thanks.

Share this post


Link to post
Share on other sites
Advertisement
I've recently done the very same thing you are trying to do, but with one difference. Try using it like this:

if (FAILED(D3DXCreateTextureFromFile(device, materials.pTextureFilename,
&newMeshContainer->exTextures)));

Due to conversion problems that I had I've prefered to use directly the filename from the material...

Hope it works, that worked for me... =)

Share this post


Link to post
Share on other sites
Thanks for the help, but that still didnt work :(

Been working on it for hours and the code looks identical to the one off "toymaker". Think it might be time to start from scratch.

Share this post


Link to post
Share on other sites
Ok well my code will work fine if there are no materials. But materials would be nice too.
Anyway, now the model loads but its as if some sort of culling is turned on? So..it kind of looks like the model is in an invisable box and if it moves to far in any direction it starts to disappear. I know this is probably some simple setting somewhere ive missed but any ideas on what it would be?

Share this post


Link to post
Share on other sites
That is probably because your frustum is clipping your model. When you create your projection matrix through something like D3DXMatrixPerspectiveFovLH, you must specify the near and far clipping planes which define your frustum. Anything that is out of this planes won't be rendered.

D3DXMATRIX * D3DXMatrixPerspectiveFovLH(
D3DXMATRIX * pOut,
FLOAT fovy,
FLOAT Aspect,
FLOAT zn, //Near clipping plane
FLOAT zf //Far clipping plane
);

Try to increase your zf value to a bigger value. Clipping will always occur, but not so close to your viewpoint. =)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!