- Bugfix: Collada-Loader now also reads animations containing multiple channels

- Bugfix: Collada-Loader new resolves subelement animation channels correctly
- silenced some warnings in the B3DImporter code. There are a lot more over there, though.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@459 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
ulfjorensen 2009-08-01 13:57:29 +00:00
parent 99a6ed1bb9
commit 3f2fa97f18
3 changed files with 52 additions and 13 deletions

View File

@ -123,6 +123,7 @@ void B3DImporter::Fail( string str ){
int B3DImporter::ReadByte(){ int B3DImporter::ReadByte(){
if( _pos<_buf.size() ) return _buf[_pos++]; if( _pos<_buf.size() ) return _buf[_pos++];
Fail( "EOF" ); Fail( "EOF" );
return 0;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -133,6 +134,7 @@ int B3DImporter::ReadInt(){
return n; return n;
} }
Fail( "EOF" ); Fail( "EOF" );
return 0;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -143,6 +145,7 @@ float B3DImporter::ReadFloat(){
return n; return n;
} }
Fail( "EOF" ); Fail( "EOF" );
return 0.0f;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -178,6 +181,7 @@ string B3DImporter::ReadString(){
str+=c; str+=c;
} }
Fail( "EOF" ); Fail( "EOF" );
return string();
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -844,8 +844,8 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
continue; continue;
if( srcChannel.mTarget.find( '/', slashPos+1) != std::string::npos) if( srcChannel.mTarget.find( '/', slashPos+1) != std::string::npos)
continue; continue;
std::string targetName = srcChannel.mTarget.substr( 0, slashPos); std::string targetID = srcChannel.mTarget.substr( 0, slashPos);
if( targetName != nodeName) if( targetID != srcNode->mID)
continue; continue;
// find the dot that separates the transformID - there should be only one or zero // find the dot that separates the transformID - there should be only one or zero
@ -860,6 +860,12 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
std::string subElement = srcChannel.mTarget.substr( dotPos+1); std::string subElement = srcChannel.mTarget.substr( dotPos+1);
if( subElement == "ANGLE") if( subElement == "ANGLE")
entry.mSubElement = 3; // last number in an Axis-Angle-Transform is the angle entry.mSubElement = 3; // last number in an Axis-Angle-Transform is the angle
else if( subElement == "X")
entry.mSubElement = 0;
else if( subElement == "Y")
entry.mSubElement = 1;
else if( subElement == "Z")
entry.mSubElement = 2;
else else
DefaultLogger::get()->warn( boost::str( boost::format( "Unknown anim subelement \"%s\". Ignoring") % subElement)); DefaultLogger::get()->warn( boost::str( boost::format( "Unknown anim subelement \"%s\". Ignoring") % subElement));
} else } else

View File

@ -270,8 +270,9 @@ void ColladaParser::ReadAnimationLibrary()
void ColladaParser::ReadAnimation( Collada::Animation* pParent) void ColladaParser::ReadAnimation( Collada::Animation* pParent)
{ {
// an <animation> element may be a container for grouping sub-elements or an animation channel // an <animation> element may be a container for grouping sub-elements or an animation channel
// this is the channel we're writing to, in case it's a channel // this is the channel collection by ID, in case it has channels
AnimationChannel channel; typedef std::map<std::string, AnimationChannel> ChannelMap;
ChannelMap channels;
// this is the anim container in case we're a container // this is the anim container in case we're a container
Animation* anim = NULL; Animation* anim = NULL;
@ -311,8 +312,13 @@ void ColladaParser::ReadAnimation( Collada::Animation* pParent)
} }
else if( IsElement( "sampler")) else if( IsElement( "sampler"))
{ {
// have it read into our channel // read the ID to assign the corresponding collada channel afterwards.
ReadAnimationSampler( channel); int indexID = GetAttribute( "id");
std::string id = mReader->getAttributeValue( indexID);
ChannelMap::iterator newChannel = channels.insert( std::make_pair( id, AnimationChannel())).first;
// have it read into a channel
ReadAnimationSampler( newChannel->second);
} }
else if( IsElement( "channel")) else if( IsElement( "channel"))
{ {
@ -320,7 +326,13 @@ void ColladaParser::ReadAnimation( Collada::Animation* pParent)
// Thanks, Collada! A directly posted information would have been too simple, I guess. // Thanks, Collada! A directly posted information would have been too simple, I guess.
// Better add another indirection to that! Can't have enough of those. // Better add another indirection to that! Can't have enough of those.
int indexTarget = GetAttribute( "target"); int indexTarget = GetAttribute( "target");
channel.mTarget = mReader->getAttributeValue( indexTarget); int indexSource = GetAttribute( "source");
const char* sourceId = mReader->getAttributeValue( indexSource);
if( sourceId[0] == '#')
sourceId++;
ChannelMap::iterator cit = channels.find( sourceId);
if( cit != channels.end())
cit->second.mTarget = mReader->getAttributeValue( indexTarget);
if( !mReader->isEmptyElement()) if( !mReader->isEmptyElement())
SkipElement(); SkipElement();
@ -340,9 +352,26 @@ void ColladaParser::ReadAnimation( Collada::Animation* pParent)
} }
} }
// it turned out to be a channel - add it // it turned out to have channels - add them
if( !channel.mTarget.empty()) if( !channels.empty())
pParent->mChannels.push_back( channel); {
// special filtering for stupid exporters packing each channel into a separate animation
if( channels.size() == 1)
{
pParent->mChannels.push_back( channels.begin()->second);
} else
{
// else create the animation, if not done yet, and store the channels
if( !anim)
{
anim = new Animation;
anim->mName = animName;
pParent->mSubAnims.push_back( anim);
}
for( ChannelMap::const_iterator it = channels.begin(); it != channels.end(); ++it)
anim->mChannels.push_back( it->second);
}
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -2364,10 +2393,10 @@ void ColladaParser::ReadNodeGeometry( Node* pNode)
int attrMaterial = GetAttribute( "target"); int attrMaterial = GetAttribute( "target");
const char* urlMat = mReader->getAttributeValue( attrMaterial); const char* urlMat = mReader->getAttributeValue( attrMaterial);
Collada::SemanticMappingTable s; Collada::SemanticMappingTable s;
if( urlMat[0] != '#') if( urlMat[0] == '#')
ThrowException( "Unknown reference format"); urlMat++;
s.mMatName = urlMat+1; s.mMatName = urlMat;
// resolve further material details + THIS UGLY AND NASTY semantic mapping stuff // resolve further material details + THIS UGLY AND NASTY semantic mapping stuff
if( !mReader->isEmptyElement()) if( !mReader->isEmptyElement())