Esempio n. 1
0
void FBXSceneInstance::InitInstance()
{
	// Bounding Box
	m_BoundingBox = mScene->m_BoundingBox;

	// Models
	for(unsigned int i = 0; i < mScene->GetModelCount(); i++)
	{
		Model* srcModel = mScene->GetModel(i);
		m_Models.Add(srcModel->GetName(), new Model(srcModel));
	}

	// Copy Skeleton
	if ( mScene->GetSkeleton() )
	{
		Skeleton* newSkeleton = new Skeleton();
		
		for( unsigned int x = 0; x < mScene->GetSkeleton()->GetBoneCount(); ++x )
		{
			SkeletonBone* sourceBone = mScene->GetSkeleton()->GetSkeletonBone(x);

			SkeletonBone* targetBone = new SkeletonBone(
				sourceBone->GetName(), 
				sourceBone->GetParentBoneIndex(), 
				newSkeleton);

			newSkeleton->AddSkeletonBone( targetBone );
		}

		newSkeleton->BuildBoneHierarchy();

		for( unsigned int x = 0; x < newSkeleton->GetBoneCount(); ++x )
		{
			SkeletonBone* sourceBone = mScene->GetSkeleton()->GetSkeletonBone(x);
			SkeletonBone* targetBone = newSkeleton->GetSkeletonBone(x);
			targetBone->SetBindPoseTransform2(sourceBone->GetBindPoseTransform2());
			targetBone->SetBoneReferenceTransform2(sourceBone->GetBoneReferenceTransform2());
			targetBone->m_AnimationKeyFrames = sourceBone->m_AnimationKeyFrames;
			targetBone->SetBoundingBoxData(sourceBone->m_AABB);
		}

		// Update My Skeleton
		m_pSkeleton = newSkeleton;

		// Update My Animation
		m_pAnimationController = new AnimationController(mScene->m_pAnimationController);
	}

	// Curves
	m_Curves = &mScene->m_Curves;
}
Esempio n. 2
0
//--------------------------------------------------------------------------------------
void FBXScene::ProcessBoneWeights(FbxSkin* pFBXSkin, std::vector<BoneWeights>& meshBoneWeights)
{
	FbxCluster::ELinkMode linkMode = FbxCluster::eNormalize; //Default link mode

	std::vector<BoneWeights> skinBoneWeights(meshBoneWeights.size(), BoneWeights());
	unsigned int nClusterCount = pFBXSkin->GetClusterCount();

	for( unsigned int i = 0; i < nClusterCount; ++i )
	{
		FbxCluster* pFBXCluster = pFBXSkin->GetCluster(i);

		if( !pFBXCluster )
			continue;

		linkMode = pFBXCluster->GetLinkMode();
		FbxNode* pLinkNode = pFBXCluster->GetLink();

		if( !pLinkNode )
			continue;
		
		int nBoneIndex = m_pSkeleton->FindBoneIndex(pLinkNode->GetName());
		if( nBoneIndex < 0 )
			continue;

		SkeletonBone* pSkeletonBone = m_pSkeleton->GetSkeletonBone(nBoneIndex);

		FbxAMatrix matClusterTransformMatrix;
		FbxAMatrix matClusterLinkTransformMatrix;
		pFBXCluster->GetTransformMatrix(matClusterTransformMatrix);
		pFBXCluster->GetTransformLinkMatrix(matClusterLinkTransformMatrix);

		pSkeletonBone->SetBindPoseTransform2(matClusterLinkTransformMatrix);
		pSkeletonBone->SetBoneReferenceTransform2(matClusterTransformMatrix);

		int* indices = pFBXCluster->GetControlPointIndices();
		double* weights = pFBXCluster->GetControlPointWeights();

		for( int j = 0; j < pFBXCluster->GetControlPointIndicesCount(); ++j )
		{
			skinBoneWeights[indices[j]].AddBoneWeight(nBoneIndex, (float)weights[j]);
		}
	}

	switch(linkMode)
	{
	case FbxCluster::eNormalize: //Normalize so weight sum is 1.0.
		for( unsigned int i = 0; i < skinBoneWeights.size(); ++i )
		{
			skinBoneWeights[i].Normalize();
		}
	break;

	case FbxCluster::eAdditive:	//Not supported yet. Do nothing
	break;

	case FbxCluster::eTotalOne:
		//The weight sum should already be 1.0. Do nothing.
	break;
	}

	for( unsigned int i = 0; i < meshBoneWeights.size(); ++i )
	{
		meshBoneWeights[i].AddBoneWeights(skinBoneWeights[i]);
	}	
}