Sign in to follow this  
VitaliBR

CreateMeshContainer

Recommended Posts

I'm a little confused on how to load the textures of my skinned mesh, I am doing as follows:
but the model is white (does not load the textures) would like to load the textures are noted within. x (in the same folder as the mesh)
HRESULT BONE_HIERARCHY::CreateMeshContainer(LPCSTR Name,
CONST D3DXMESHDATA *pMeshData,
CONST D3DXMATERIAL *pMaterials,
CONST D3DXEFFECTINSTANCE *pEffectInstances,
DWORD NumMaterials,
CONST DWORD *pAdjacency,
LPD3DXSKININFO pSkinInfo,
LPD3DXMESHCONTAINER *ppNewMeshContainer)
{
//Create new Bone Mesh
BONEMESH *boneMesh = new BONEMESH;
memset(boneMesh, 0, sizeof(BONEMESH));

//Get mesh data
boneMesh->OriginalMesh = pMeshData->pMesh;
boneMesh->MeshData.pMesh = pMeshData->pMesh;
boneMesh->MeshData.Type = pMeshData->Type;
pMeshData->pMesh->AddRef(); //Add Reference so that the mesh isnt deallocated
IDirect3DDevice9 *m_pDevice = NULL;
pMeshData->pMesh->GetDevice(&m_pDevice); //Get m_pDevice ptr from mesh

//Copy materials and load textures (just like with a static mesh)
for(int i=0;i<NumMaterials;i++)
{
D3DXMATERIAL mtrl;
memcpy(&mtrl, &pMaterials[i], sizeof(D3DXMATERIAL));
boneMesh->materials.push_back(mtrl.MatD3D);

char textureFname[200];
strcpy(textureFname, "mesh/"); //Folder of mesh
strcat(textureFname, mtrl.pTextureFilename);

//Load texture
IDirect3DTexture9* newTexture = NULL;
D3DXCreateTextureFromFile(m_pDevice, textureFname, &newTexture);
boneMesh->textures.push_back(newTexture);
}

if(pSkinInfo != NULL)
{
//Get Skin Info
boneMesh->pSkinInfo = pSkinInfo;
pSkinInfo->AddRef(); //Add reference so that the SkinInfo isnt deallocated

//Clone mesh and store in boneMesh->MeshData.pMesh
pMeshData->pMesh->CloneMeshFVF(D3DXMESH_MANAGED, pMeshData->pMesh->GetFVF(),
m_pDevice, &boneMesh->MeshData.pMesh);

//Get Attribute Table
boneMesh->MeshData.pMesh->GetAttributeTable(NULL, &boneMesh->NumAttributeGroups);
boneMesh->attributeTable = new D3DXATTRIBUTERANGE[boneMesh->NumAttributeGroups];
boneMesh->MeshData.pMesh->GetAttributeTable(boneMesh->attributeTable, NULL);

//Create bone offset and current matrices
int NumBones = pSkinInfo->GetNumBones();
boneMesh->boneOffsetMatrices = new D3DXMATRIX[NumBones];
boneMesh->currentBoneMatrices = new D3DXMATRIX[NumBones];

//Get bone offset matrices
for(int i=0;i < NumBones;i++)
boneMesh->boneOffsetMatrices[i] = *(boneMesh->pSkinInfo->GetBoneOffsetMatrix(i));
}

//Set ppNewMeshContainer to the newly created boneMesh container
*ppNewMeshContainer = boneMesh;

return S_OK;
}




EDIT:
struct BONEMESH: public D3DXMESHCONTAINER
{
ID3DXMesh* OriginalMesh;
std::vector<D3DMATERIAL9> materials;
std::vector<IDirect3DTexture9*> textures;

DWORD NumAttributeGroups;
D3DXATTRIBUTERANGE* attributeTable;
D3DXMATRIX** boneMatrixPtrs;
D3DXMATRIX* boneOffsetMatrices;
D3DXMATRIX* currentBoneMatrices;
};


[Edited by - VitaliBR on December 1, 2010 9:36:04 AM]

Share this post


Link to post
Share on other sites
According to your code, you do load textures. There might be problem with your rendering code.
Could you show it?

Share this post


Link to post
Share on other sites

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