Merge pull request #160 from lvlonggame/v3

modify read animation.
This commit is contained in:
XiaoYang 2014-11-19 08:52:06 +07:00
commit 1d31df9970
2 changed files with 33 additions and 12 deletions

View File

@ -1404,10 +1404,24 @@ bool Bundle3D::loadAnimationDataJson(const std::string& id, Animation3DData* ani
bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* animationdata) bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* animationdata)
{ {
if( _version == "0.1"|| _version == "0.2" || _version == "0.3"|| _version == "0.4")
{
if (!seekToFirstType(BUNDLE_TYPE_ANIMATIONS)) if (!seekToFirstType(BUNDLE_TYPE_ANIMATIONS))
return false; return false;
}
else
{
// if id is not a null string, we need to add a suffix of "animation" for seeding.
std::string id_ = id;
if(id != "") id_ = id + "animation";
if (!seekToFirstType(BUNDLE_TYPE_ANIMATIONS, id_))
return false;
}
unsigned int animNum = 1; unsigned int animNum = 1;
if( _version == "0.3"|| _version == "0.4") if( _version == "0.1"|| _version == "0.2" || _version == "0.3"|| _version == "0.4")
{ {
if (!_binaryReader.read(&animNum)) if (!_binaryReader.read(&animNum))
{ {
@ -1459,7 +1473,7 @@ bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* a
// transform flag // transform flag
unsigned char transformFlag(0); unsigned char transformFlag(0);
if (_version == "0.4") if (_version != "0.1" && _version != "0.2" && _version != "0.3")
{ {
if (!_binaryReader.read(&transformFlag)) if (!_binaryReader.read(&transformFlag))
{ {
@ -1470,7 +1484,7 @@ bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* a
// rotation // rotation
bool hasRotate = true; bool hasRotate = true;
if (_version == "0.4") if (_version != "0.1" && _version != "0.2" && _version != "0.3")
hasRotate = transformFlag & 0x01; hasRotate = transformFlag & 0x01;
if (hasRotate) if (hasRotate)
@ -1486,7 +1500,7 @@ bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* a
// scale // scale
bool hasScale = true; bool hasScale = true;
if (_version == "0.4") if (_version != "0.1" && _version != "0.2" && _version != "0.3")
hasScale = (transformFlag >> 1) & 0x01; hasScale = (transformFlag >> 1) & 0x01;
if (hasScale) if (hasScale)
@ -1502,7 +1516,7 @@ bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* a
// translation // translation
bool hasTranslation = true; bool hasTranslation = true;
if (_version == "0.4") if (_version != "0.1" && _version != "0.2" && _version != "0.3")
hasTranslation = (transformFlag >> 2) & 0x01; hasTranslation = (transformFlag >> 2) & 0x01;
if (hasTranslation) if (hasTranslation)
@ -1938,7 +1952,7 @@ void Bundle3D::getModelRelativePath(const std::string& path)
_modelPath = path.substr(0, index + 1); _modelPath = path.substr(0, index + 1);
} }
Reference* Bundle3D::seekToFirstType(unsigned int type) Reference* Bundle3D::seekToFirstType(unsigned int type, const std::string& id)
{ {
// for each Reference // for each Reference
for (unsigned int i = 0; i < _referenceCount; ++i) for (unsigned int i = 0; i < _referenceCount; ++i)
@ -1946,6 +1960,12 @@ Reference* Bundle3D::seekToFirstType(unsigned int type)
Reference* ref = &_references[i]; Reference* ref = &_references[i];
if (ref->type == type) if (ref->type == type)
{ {
// if id is not a null string, we also need to check the Reference's id.
if (id != "" && id != ref->id)
{
continue;
}
// Found a match // Found a match
if (_binaryReader.seek(ref->offset, SEEK_SET) == false) if (_binaryReader.seek(ref->offset, SEEK_SET) == false)
{ {

View File

@ -146,8 +146,9 @@ protected:
/* /*
* set the read position in buffer to the target type * set the read position in buffer to the target type
* @param The data type * @param The data type
* @param The data id
*/ */
Reference* seekToFirstType(unsigned int type); Reference* seekToFirstType(unsigned int type, const std::string& id = "");
CC_CONSTRUCTOR_ACCESS: CC_CONSTRUCTOR_ACCESS:
Bundle3D(); Bundle3D();