NS_CC_BEGIN Animation3D* Animation3D::create(const std::string& fileName, const std::string& animationName) { std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName); std::string key = fullPath + "#" + animationName; auto animation = Animation3DCache::getInstance()->getAnimation(key); if (animation != nullptr) return animation; //load animation here animation = new (std::nothrow) Animation3D(); auto bundle = Bundle3D::createBundle(); Animation3DData animationdata; if (bundle->load(fullPath) && bundle->loadAnimationData(animationName, &animationdata) && animation->init(animationdata)) { Animation3DCache::getInstance()->addAnimation(key, animation); animation->autorelease(); } else { CC_SAFE_DELETE(animation); animation = nullptr; } Bundle3D::destroyBundle(bundle); return animation; }
bool Animation3D::initWithFile(const std::string& filename, const std::string& animationName) { std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename); //load animation here auto bundle = Bundle3D::createBundle(); Animation3DData animationdata; if (bundle->load(fullPath) && bundle->loadAnimationData(animationName, &animationdata) && init(animationdata)) { std::string key = fullPath + "#" + animationName; Animation3DCache::getInstance()->addAnimation(key, this); Bundle3D::destroyBundle(bundle); return true; } Bundle3D::destroyBundle(bundle); return false; }
int readAnimationState(FILE *fin, Animation *anim) { anim->currentBlockIdx = readInt(fin); anim->currentFrame = readInt(fin); anim->currentLoops = readInt(fin); anim->lastUpdate = readInt(fin); int totalBlocks = readInt(fin); if(( totalBlocks != anim->totalBlocks) || (anim->currentBlockIdx >= anim->totalBlocks)) { dout << "ERROR- animation out of sync or is modified." << endl; exit(1); } anim->useVideoMemory = (readInt(fin) > 0); anim->isImageDataLoaded = (readInt(fin) > 0); if(anim->isImageDataLoaded) { loadAnimationData(anim); } anim->currentBlock = anim->blocks[anim->currentBlockIdx]; dout << "LoadAnimState currentFrame: " << anim->currentFrame << ", last update: " << anim->lastUpdate << ", current time: " << current_time << endl; readAnimationTransformState(fin, anim); return 0; }