Sign in to follow this  

Loading a different SkinnedMesh

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

Hello gamedev,

I am trying to load the "bones_all.x" file (from http://toymaker.info/) into my application. When I use the SkinnedMeshDemo fromt the SDK, it loads fine.
But if use the code from Frank D. Luna's SkinnedMeshDemo (Introduction to 3D Game Programming with DirextX 9.0c - A Shader Approach), which I use for my game, it fails.
In his code you try to find a frame which contains the mesh data (recursively through the hierarchy), but apparently this .x file does not contain that info in a frame.
How can I find the mesh data? Or is there some way to generate it?


...
// Load the skinned mesh and its texture.
mSkinnedMesh = new SkinnedMesh("bones_all.x");
...



SkinnedMesh::SkinnedMesh(std::string XFilename)
{
AllocMeshHierarchy allocMeshHierarchy;
HR(D3DXLoadMeshHierarchyFromX(XFilename.c_str(), D3DXMESH_SYSTEMMEM,
gd3dDevice, &allocMeshHierarchy, 0, /* ignore user data */
&mRoot, &mAnimCtrl));

// In this demo we assume that the input .X file contains only one
// mesh. So search for that one and only mesh.
D3DXFRAME* f = findNodeWithMesh(mRoot);
if( f == 0 ) HR(E_FAIL);
D3DXMESHCONTAINER* meshContainer = f->pMeshContainer;
mSkinInfo = meshContainer->pSkinInfo;
mSkinInfo->AddRef();

mNumBones = meshContainer->pSkinInfo->GetNumBones();
mFinalXForms.resize(mNumBones);
mToRootXFormPtrs.resize(mNumBones, 0);

mAnimSet = 0;

buildSkinnedMesh(meshContainer->MeshData.pMesh);
buildToRootXFormPtrArray();
}

Share this post


Link to post
Share on other sites
I couldn't actually find a copy of bones_all.x from the link you provided, but I found this link:

http://www.gamedev.net/community/forums/topic.asp?topic_id=556932

Which describes the same issue with the same file and the eventual solution is that the allocation hierarchy doesn't handle loading frames with no skin information.

It sounds like bones_all.x doesn't have any mesh at all, it's just bones and animations? But again I can't be sure because I can't find the file, perhaps you could give a more direct link to the file?

Share this post


Link to post
Share on other sites
Luna's skinned mesh code assumes a model with a single mesh. The "bones_all.x" model is actually several separate meshes, one for each modeled bone. That's why the bones_all model can implement an animation where the bones "fly" apart.

Share this post


Link to post
Share on other sites
There must be a vertex declaration problem.

Luna does not describe how to pass correct blend weights and indices to vertex shader. Because ID3DXSkinInfo::ConvertToIndexedBlendedMesh() returns a skinned mesh but sometimes blend indices/weights related problems occur due to type of indices and weights.

If you look at GenerateSkinnedMesh() function in SDK's skinnedMesh sample, you'll see an "if" block: else if( ( g_SkinningMethod == D3DINDEXEDVS ) || ( g_SkinningMethod == D3DINDEXEDHLSLVS ) ). There, they're cloning that mesh so that it contains correct indices and weights, then converts their types into D3DDECLUSAGE_COLOR and D3DDECLUSAGE_FLOAT4, respectively. And in vertex shader, they use D3DCOLORtoUBYTE4() HLSL function to obtain correct vertex blend indices.

Remaining work is simple, you know.

Share this post


Link to post
Share on other sites
@Steve_Segreto
http://www.filefront.com/17258947/BONES.zip

@VitaliBR
This is where I get my error (E_FAIL):

if( f == 0 ) HR(E_FAIL); 






@Buckeye
That sounds plausible, but why can't I find any mesh at all?
Here's the findNodeWithMesh code:


D3DXFRAME* SkinnedMesh::findNodeWithMesh(D3DXFRAME* frame)
{
if( frame->pMeshContainer )
if( frame->pMeshContainer->MeshData.pMesh != 0 )
return frame;

D3DXFRAME* f = 0;
if(frame->pFrameSibling)
if( f = findNodeWithMesh(frame->pFrameSibling) )
return f;

if(frame->pFrameFirstChild)
if( f = findNodeWithMesh(frame->pFrameFirstChild) )
return f;

return 0;
}





@programci_84
My program doesn't reach ID3DXSkinInfo::ConvertToIndexedBlendedMesh().
Also, the SDK's code begins with:


pMeshContainer->NumPaletteEntries = min( MaxMatrices, pMeshContainer->pSkinInfo->GetNumBones() );








but I don't even have the MeshContainer yet because f is 0 and
D3DXMESHCONTAINER* meshContainer = f->pMeshContainer;
does not give me a vald MeshContainer.

Share this post


Link to post
Share on other sites
What Steve_Segreto mentions points to the problem. However, it isn't that Luna's AllocateMeshHierarchy loads it incorrectly, it's that Luna's code uses only hierarchies which contain a single mesh and associated skininfo. "bones_all.x" is an animated mesh, but not a skinned animated mesh. That is, many of the frames in the hierarchy contain meshes*. Each of those frames orients and draws its associated mesh but without bone weighting. So there's no skininfo and Luna's methods support only x-files which have a single mesh and skininfo associated with that mesh.

// from Frank Luna's mlAllocMeshHierarchy.cpp
// Author: Frank Luna (C) All Rights Reserved
///////////////////////////////////////////////////////////////
// Only interested in meshes with skin info and regular meshes.
// If a given mesh does not satisfy these requirements we do
// not return an error, rather we simply skip loading anything
// for this mesh container.

if( pSkinInfo == 0 || pMeshData->Type != D3DXMESHTYPE_MESH)
return D3D_OK;










Conclusion: you can't use Luna's skinned mesh method to display "bones_all.x"

*EDIT: There are many meshes in bones_all.x. However, per the above code used in Luna's skinned mesh method, those frames are "thrown away" because pSkinInfo is NULL.

[Edited by - Buckeye on September 3, 2010 11:17:57 AM]

Share this post


Link to post
Share on other sites

This topic is 2657 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.

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