Loading a different SkinnedMesh

Started by
6 comments, last by Anddos 13 years, 7 months ago
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();}
Advertisement
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?
Use the Debug and put it here where it gives the error
http://mateusvitali.wordpress.com/
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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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.
There's no "hard", and "the impossible" takes just a little time.
@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.
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]

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

When i render an exported model from 3dsmax , i just see a bone , the hip joint bone and thats it ....
:)

This topic is closed to new replies.

Advertisement