• Advertisement
Sign in to follow this  

FBX, mesh convert & bones

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

Good day,

 

Currently i am trying to create a mesh converter for an old game but so far it hasn't turned out that well.

The actual mesh is fine, but the problem is bones.

 

I'm looking at how wowmodelviewer (https://bitbucket.org/wowmodelviewer/wowmodelviewer/src/1a3a6a51944be4679964b3dc280efa421464cd97/src/modelexport_fbx.cpp?at=default) added bones as reference.

 

This is what i've come up with;

void CreateSkeleton(FbxManager *sdk_mgr, FbxScene *scene, Z3DLODMesh *m, FbxNode *pMeshNode)
{
	// Get the scene root node.
	FbxNode* root_node = scene->GetRootNode();

	// Get the mesh's node.
	FbxNode* bone_group_node = FbxNode::Create(scene, "crayfish");
	FbxSkeleton* bone_group_skeleton_attribute = FbxSkeleton::Create(scene, "crayfish");
	bone_group_skeleton_attribute->SetSkeletonType(FbxSkeleton::eRoot);
	//bone_group_skeleton_attribute->Size.Set(100.0);
	
	bone_group_node->SetNodeAttribute(bone_group_skeleton_attribute);
	root_node->AddChild(bone_group_node);
	//FbxMatrix matrix;

	FbxSkin* skin = FbxSkin::Create(scene, "");
	std::vector<FbxNode*> bone_nodes;
	std::vector<FbxCluster*> bone_clusters;
	std::vector<int> bone_types;

	int num_of_bones = g_Skel.GetSkeletonCount();

	// Set bone type.
	for ( int i = 0; i < num_of_bones; i++ ) 
	{
		long skelID = g_Skel.GetSkeletonHierarchy()[i];

		if (skelID == -1) 
		{
			bone_types.push_back(FbxSkeleton::eRoot);
		}
		else
		{
			bone_types.push_back(FbxSkeleton::eLimbNode);
		}
	}

	// Create bone.
	for ( int i = 0; i < num_of_bones; ++i) 
	{
		long skelID = g_Skel.GetSkeletonHierarchy()[i];
		matrix *z3dmatrix = g_Skel.GetLocMatrix(i);
		vector3 trans = z3dmatrix->GetLoc();

		FbxNode* skeleton_node = FbxNode::Create( scene, g_Skel.GetSkeletonName(i) );
		bone_nodes.push_back(skeleton_node);
		skeleton_node->LclTranslation.Set(FbxVector4(trans.x , trans.y, trans.z));
		FbxSkeleton* skeleton_attribute = FbxSkeleton::Create( scene, g_Skel.GetSkeletonName(i) );
		if (bone_types[i] == FbxSkeleton::eRoot) 
		{
			skeleton_attribute->SetSkeletonType(FbxSkeleton::eRoot);
			//skeleton_attribute->Size.Set(100.0);
			bone_group_node->AddChild(skeleton_node);
		}
		else 
		{
			skeleton_attribute->SetSkeletonType(FbxSkeleton::eLimbNode);
			//skeleton_attribute->Size.Set(100.0);
			bone_nodes[skelID]->AddChild(skeleton_node);
		}

		skeleton_node->SetNodeAttribute(skeleton_attribute);

		FbxCluster* cluster = FbxCluster::Create(scene, "");
		bone_clusters.push_back(cluster);
		cluster->SetLink(skeleton_node);
		cluster->SetLinkMode(FbxCluster::eTotalOne);

		FbxAMatrix matrix = scene->GetEvaluator()->GetNodeGlobalTransform(pMeshNode);
		cluster->SetTransformMatrix(matrix);
		matrix = scene->GetEvaluator()->GetNodeGlobalTransform(skeleton_node);
		cluster->SetTransformLinkMatrix(matrix);
		skin->AddCluster(bone_clusters[i]);
	}

	int num_of_vertices = m->nVertexCount;
	for (int i = 0; i < num_of_vertices; i++) 
	{
		Z3DVertex *vertex = &m->pVertices[i];

		bone_clusters[ vertex->MatrixId[0] ]->AddControlPointIndex( i, static_cast<double>(vertex->fWeight) );
		bone_clusters[ vertex->MatrixId[1] ]->AddControlPointIndex( i, static_cast<double>(vertex->fWeight) );
	}

	skin->SetGeometry(pMeshNode->GetMesh());
}

Running it and the outcome looks like:

 

QEygjlil.jpg

 

Too bad that i has no clue when it comes down to 3d stuff, so i hope anyone here could explain what is going on and how to correct it.

 

Thanks.

Share this post


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

  • Advertisement