Add timescale for collada

pull/3169/head
Inho Lee 2020-04-27 11:52:04 +02:00
parent 0a66a2c670
commit 629320a3a0
2 changed files with 9 additions and 5 deletions

View File

@ -1314,6 +1314,8 @@ void ColladaExporter::WriteSceneLibrary()
// ------------------------------------------------------------------------------------------------
void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
{
static const float kSecondsFromMilliseconds = .001f;
const aiAnimation * anim = mScene->mAnimations[pIndex];
if ( anim->mNumChannels == 0 && anim->mNumMeshChannels == 0 && anim->mNumMorphMeshChannels ==0 )
@ -1351,7 +1353,7 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
std::vector<ai_real> frames;
for( size_t i = 0; i < nodeAnim->mNumPositionKeys; ++i) {
frames.push_back(static_cast<ai_real>(nodeAnim->mPositionKeys[i].mTime));
frames.push_back(static_cast<ai_real>(nodeAnim->mPositionKeys[i].mTime) * kSecondsFromMilliseconds);
}
WriteFloatArray(cur_node_idstr, FloatType_Time, (const ai_real *)frames.data(), frames.size());

View File

@ -107,6 +107,8 @@ ColladaLoader::~ColladaLoader() {
// empty
}
static const float kMillisecondsFromSeconds = 1000.f;
// ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file.
bool ColladaLoader::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const {
@ -1420,9 +1422,9 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
double time = double(mat.d4); // remember? time is stored in mat.d4
mat.d4 = 1.0f;
dstAnim->mPositionKeys[a].mTime = time;
dstAnim->mRotationKeys[a].mTime = time;
dstAnim->mScalingKeys[a].mTime = time;
dstAnim->mPositionKeys[a].mTime = time * kMillisecondsFromSeconds ;
dstAnim->mRotationKeys[a].mTime = time * kMillisecondsFromSeconds ;
dstAnim->mScalingKeys[a].mTime = time * kMillisecondsFromSeconds ;
mat.Decompose(dstAnim->mScalingKeys[a].mValue, dstAnim->mRotationKeys[a].mValue, dstAnim->mPositionKeys[a].mValue);
}
@ -1484,7 +1486,7 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
morphAnim->mKeys[key].mValues = new unsigned int[morphChannels.size()];
morphAnim->mKeys[key].mWeights = new double[morphChannels.size()];
morphAnim->mKeys[key].mTime = morphTimeValues[key].mTime;
morphAnim->mKeys[key].mTime = morphTimeValues[key].mTime * kMillisecondsFromSeconds ;
for (unsigned int valueIndex = 0; valueIndex < morphChannels.size(); valueIndex++)
{
morphAnim->mKeys[key].mValues[valueIndex] = valueIndex;