MCPcopy Create free account
hub / github.com/assimp/assimp / ExportAnimations

Method ExportAnimations

code/AssetLib/glTF/glTFExporter.cpp:1001–1070  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

999}
1000
1001void glTFExporter::ExportAnimations()
1002{
1003 Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0));
1004
1005 for (unsigned int i = 0; i < mScene->mNumAnimations; ++i) {
1006 const aiAnimation* anim = mScene->mAnimations[i];
1007
1008 std::string nameAnim = "anim";
1009 if (anim->mName.length > 0) {
1010 nameAnim = anim->mName.C_Str();
1011 }
1012
1013 for (unsigned int channelIndex = 0; channelIndex < anim->mNumChannels; ++channelIndex) {
1014 const aiNodeAnim* nodeChannel = anim->mChannels[channelIndex];
1015
1016 // It appears that assimp stores this type of animation as multiple animations.
1017 // where each aiNodeAnim in mChannels animates a specific node.
1018 std::string name = nameAnim + "_" + ai_to_string(channelIndex);
1019 name = mAsset->FindUniqueID(name, "animation");
1020 Ref<Animation> animRef = mAsset->animations.Create(name);
1021
1022 /******************* Parameters ********************/
1023 ExtractAnimationData(*mAsset, name, animRef, bufferRef, nodeChannel, static_cast<float>(anim->mTicksPerSecond));
1024
1025 for (unsigned int j = 0; j < 3; ++j) {
1026 std::string channelType;
1027 int channelSize=0;
1028 switch (j) {
1029 case 0:
1030 channelType = "rotation";
1031 channelSize = nodeChannel->mNumRotationKeys;
1032 break;
1033 case 1:
1034 channelType = "scale";
1035 channelSize = nodeChannel->mNumScalingKeys;
1036 break;
1037 case 2:
1038 channelType = "translation";
1039 channelSize = nodeChannel->mNumPositionKeys;
1040 break;
1041 }
1042
1043 if (channelSize < 1) { continue; }
1044
1045 Animation::AnimChannel tmpAnimChannel;
1046 Animation::AnimSampler tmpAnimSampler;
1047
1048 tmpAnimChannel.sampler = name + "_" + channelType;
1049 tmpAnimChannel.target.path = channelType;
1050 tmpAnimSampler.output = channelType;
1051 tmpAnimSampler.id = name + "_" + channelType;
1052
1053 tmpAnimChannel.target.id = mAsset->nodes.Get(nodeChannel->mNodeName.C_Str());
1054
1055 tmpAnimSampler.input = "TIME";
1056 tmpAnimSampler.interpolation = "LINEAR";
1057
1058 animRef->Channels.push_back(tmpAnimChannel);

Callers

nothing calls this directly

Calls 5

ExtractAnimationDataFunction · 0.85
C_StrMethod · 0.80
GetMethod · 0.45
CreateMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected