当前位置: 首页>>代码示例>>C++>>正文


C++ USkeleton::GetSkeletonBoneIndexFromMeshBoneIndex方法代码示例

本文整理汇总了C++中USkeleton::GetSkeletonBoneIndexFromMeshBoneIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ USkeleton::GetSkeletonBoneIndexFromMeshBoneIndex方法的具体用法?C++ USkeleton::GetSkeletonBoneIndexFromMeshBoneIndex怎么用?C++ USkeleton::GetSkeletonBoneIndexFromMeshBoneIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在USkeleton的用法示例。


在下文中一共展示了USkeleton::GetSkeletonBoneIndexFromMeshBoneIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ExportAnimSequenceToFbx

void FFbxExporter::ExportAnimSequenceToFbx(const UAnimSequence* AnimSeq,
									 const USkeletalMesh* SkelMesh,
									 TArray<FbxNode*>& BoneNodes,
									 FbxAnimLayer* InAnimLayer,
									 float AnimStartOffset,
									 float AnimEndOffset,
									 float AnimPlayRate,
									 float StartTime)
{
	USkeleton* Skeleton = AnimSeq->GetSkeleton();

	if (AnimSeq->SequenceLength == 0.f)
	{
		// something is wrong
		return;	
	}

	const float FrameRate			=  AnimSeq->NumFrames / AnimSeq->SequenceLength;

	// set time correctly
	FbxTime ExportedStartTime, ExportedStopTime;
	if ( FMath::IsNearlyEqual(FrameRate, DEFAULT_SAMPLERATE, 1.f) )
	{
		ExportedStartTime.SetGlobalTimeMode(FbxTime::eFrames30);
		ExportedStopTime.SetGlobalTimeMode(FbxTime::eFrames30);
	}
	else
	{
		ExportedStartTime.SetGlobalTimeMode(FbxTime::eCustom, FrameRate);
		ExportedStopTime.SetGlobalTimeMode(FbxTime::eCustom, FrameRate);
	}

	ExportedStartTime.SetSecondDouble(0.f);
	ExportedStopTime.SetSecondDouble(AnimSeq->SequenceLength);

	FbxTimeSpan ExportedTimeSpan;
	ExportedTimeSpan.Set(ExportedStartTime, ExportedStopTime);
	AnimStack->SetLocalTimeSpan(ExportedTimeSpan);
	
	// Add the animation data to the bone nodes
	for(int32 BoneIndex = 0; BoneIndex < BoneNodes.Num(); ++BoneIndex)
	{
		FbxNode* CurrentBoneNode = BoneNodes[BoneIndex];

		// Create the AnimCurves
		FbxAnimCurve* Curves[6];
		Curves[0] = CurrentBoneNode->LclTranslation.GetCurve(InAnimLayer, FBXSDK_CURVENODE_COMPONENT_X, true);
		Curves[1] = CurrentBoneNode->LclTranslation.GetCurve(InAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y, true);
		Curves[2] = CurrentBoneNode->LclTranslation.GetCurve(InAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z, true);

		Curves[3] = CurrentBoneNode->LclRotation.GetCurve(InAnimLayer, FBXSDK_CURVENODE_COMPONENT_X, true);
		Curves[4] = CurrentBoneNode->LclRotation.GetCurve(InAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y, true);
		Curves[5] = CurrentBoneNode->LclRotation.GetCurve(InAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z, true);

		float AnimTime					= AnimStartOffset;
		float AnimEndTime				= (AnimSeq->SequenceLength - AnimEndOffset);
		// Subtracts 1 because NumFrames includes an initial pose for 0.0 second
		double TimePerKey				= (AnimSeq->SequenceLength / (AnimSeq->NumFrames-1));
		const float AnimTimeIncrement	= TimePerKey * AnimPlayRate;

		FbxTime ExportTime;
		ExportTime.SetSecondDouble(StartTime);

		FbxTime ExportTimeIncrement;
		ExportTimeIncrement.SetSecondDouble( TimePerKey );

		int32 BoneTreeIndex = Skeleton->GetSkeletonBoneIndexFromMeshBoneIndex(SkelMesh, BoneIndex);
		int32 BoneTrackIndex = Skeleton->GetAnimationTrackIndex(BoneTreeIndex, AnimSeq);
		if(BoneTrackIndex == INDEX_NONE)
		{
			// If this sequence does not have a track for the current bone, then skip it
			continue;
		}

		for(int32 i = 0; i < 6; ++i)
		{
			Curves[i]->KeyModifyBegin();
		}

		bool bLastKey = false;
		// Step through each frame and add the bone's transformation data
		while (!bLastKey)
		{
			FTransform BoneAtom;
			AnimSeq->GetBoneTransform(BoneAtom, BoneTrackIndex, AnimTime, true);

			FbxVector4 Translation = Converter.ConvertToFbxPos(BoneAtom.GetTranslation());

			FbxVector4 Rotation = Converter.ConvertToFbxRot(BoneAtom.GetRotation().Euler());
		
			int32 lKeyIndex;

			bLastKey = AnimTime >= AnimEndTime;
			for(int32 i = 0, j=3; i < 3; ++i, ++j)
			{
				lKeyIndex = Curves[i]->KeyAdd(ExportTime);
				Curves[i]->KeySetValue(lKeyIndex, Translation[i]);
				Curves[i]->KeySetInterpolation(lKeyIndex, bLastKey ? FbxAnimCurveDef::eInterpolationConstant : FbxAnimCurveDef::eInterpolationCubic);

				if( bLastKey )
//.........这里部分代码省略.........
开发者ID:Codermay,项目名称:Unreal4,代码行数:101,代码来源:FbxAnimationExport.cpp


注:本文中的USkeleton::GetSkeletonBoneIndexFromMeshBoneIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。