Bugfix: collada loader now preserves empty data arrays to work around stupid exporters writing empty animation channels
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1246 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/5/head
parent
7cb9438522
commit
6d2857ed4a
|
@ -926,7 +926,7 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
|
|||
const Collada::AnimationChannel& srcChannel = *cit;
|
||||
Collada::ChannelEntry entry;
|
||||
|
||||
// we except the animation target to be of type "nodeName/transformID.subElement". Ignore all others
|
||||
// we expect the animation target to be of type "nodeName/transformID.subElement". Ignore all others
|
||||
// find the slash that separates the node name - there should be only one
|
||||
std::string::size_type slashPos = srcChannel.mTarget.find( '/');
|
||||
if( slashPos == std::string::npos)
|
||||
|
@ -995,18 +995,23 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
|
|||
if( e.mTimeAccessor->mCount != e.mValueAccessor->mCount)
|
||||
throw DeadlyImportError( boost::str( boost::format( "Time count / value count mismatch in animation channel \"%s\".") % e.mChannel->mTarget));
|
||||
|
||||
if( e.mTimeAccessor->mCount > 0 )
|
||||
{
|
||||
// find bounding times
|
||||
startTime = std::min( startTime, ReadFloat( *e.mTimeAccessor, *e.mTimeData, 0, 0));
|
||||
endTime = std::max( endTime, ReadFloat( *e.mTimeAccessor, *e.mTimeData, e.mTimeAccessor->mCount-1, 0));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<aiMatrix4x4> resultTrafos;
|
||||
if( !entries.empty() && entries.front().mTimeAccessor->mCount > 0 )
|
||||
{
|
||||
// create a local transformation chain of the node's transforms
|
||||
std::vector<Collada::Transform> transforms = srcNode->mTransforms;
|
||||
|
||||
// now for every unique point in time, find or interpolate the key values for that time
|
||||
// and apply them to the transform chain. Then the node's present transformation can be calculated.
|
||||
float time = startTime;
|
||||
std::vector<aiMatrix4x4> resultTrafos;
|
||||
while( 1)
|
||||
{
|
||||
for( std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it)
|
||||
|
@ -1084,11 +1089,14 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
|
|||
// else construct next keyframe at this following time point
|
||||
time = nextTime;
|
||||
}
|
||||
}
|
||||
|
||||
// there should be some keyframes
|
||||
ai_assert( resultTrafos.size() > 0);
|
||||
// there should be some keyframes, but we aren't that fixated on valid input data
|
||||
// ai_assert( resultTrafos.size() > 0);
|
||||
|
||||
// build an animation channel for the given node out of these trafo keys
|
||||
if( !resultTrafos.empty() )
|
||||
{
|
||||
aiNodeAnim* dstAnim = new aiNodeAnim;
|
||||
dstAnim->mNodeName = nodeName;
|
||||
dstAnim->mNumPositionKeys = resultTrafos.size();
|
||||
|
@ -1111,6 +1119,10 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
|
|||
}
|
||||
|
||||
anims.push_back( dstAnim);
|
||||
} else
|
||||
{
|
||||
DefaultLogger::get()->warn( "Collada loader: found empty animation channel, ignored. Please check your exporter.");
|
||||
}
|
||||
}
|
||||
|
||||
if( !anims.empty())
|
||||
|
|
|
@ -1647,6 +1647,7 @@ void ColladaParser::ReadDataArray()
|
|||
{
|
||||
std::string elmName = mReader->getNodeName();
|
||||
bool isStringArray = (elmName == "IDREF_array" || elmName == "Name_array");
|
||||
bool isEmptyElement = mReader->isEmptyElement();
|
||||
|
||||
// read attributes
|
||||
int indexID = GetAttribute( "id");
|
||||
|
@ -1654,13 +1655,15 @@ void ColladaParser::ReadDataArray()
|
|||
int indexCount = GetAttribute( "count");
|
||||
unsigned int count = (unsigned int) mReader->getAttributeValueAsInt( indexCount);
|
||||
const char* content = TestTextContent();
|
||||
if (content) { // some exporters write empty data arrays, silently skip over them
|
||||
|
||||
// read values and store inside an array in the data library
|
||||
mDataLibrary[id] = Data();
|
||||
Data& data = mDataLibrary[id];
|
||||
data.mIsStringArray = isStringArray;
|
||||
|
||||
// some exporters write empty data arrays, but we need to conserve them anyways because others might reference them
|
||||
if (content)
|
||||
{
|
||||
if( isStringArray)
|
||||
{
|
||||
data.mStrings.reserve( count);
|
||||
|
@ -1695,10 +1698,11 @@ void ColladaParser::ReadDataArray()
|
|||
SkipSpacesAndLineEnd( &content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test for closing tag
|
||||
if( !isEmptyElement )
|
||||
TestClosing( elmName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue