// Copyright (C) 2002-2007 Nikolaus Gebhardt // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CSceneNodeAnimatorTexture.h" #include "ITexture.h" namespace irr { namespace scene { //! constructor CSceneNodeAnimatorTexture::CSceneNodeAnimatorTexture(const core::array& textures, s32 timePerFrame, bool loop, u32 now) : TimePerFrame(timePerFrame), StartTime(now), Loop(loop) { #ifdef _DEBUG setDebugName("CSceneNodeAnimatorTexture"); #endif for (u32 i=0; igrab(); Textures.push_back(textures[i]); } EndTime = now + (timePerFrame * Textures.size()); } //! destructor CSceneNodeAnimatorTexture::~CSceneNodeAnimatorTexture() { clearTextures(); } void CSceneNodeAnimatorTexture::clearTextures() { for (u32 i=0; idrop(); } //! animates a scene node void CSceneNodeAnimatorTexture::animateNode(ISceneNode* node, u32 timeMs) { if (Textures.size()) { u32 t = (timeMs-StartTime); s32 idx = 0; if (!Loop && timeMs >= EndTime) idx = Textures.size() - 1; else idx = (t/TimePerFrame) % Textures.size(); if (idx < (s32)Textures.size()) node->setMaterialTexture(0, Textures[idx]); } } //! Writes attributes of the scene node animator. void CSceneNodeAnimatorTexture::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) { out->addInt("TimePerFrame", TimePerFrame); out->addBool("Loop", Loop); // add one texture in addition when serializing for editors // to make it easier to add textures quickly u32 count = Textures.size(); if ( options && (options->Flags & io::EARWF_FOR_EDITOR)) count += 1; for (u32 i=0; iaddTexture(tname.c_str(), igetAttributeAsInt("TimePerFrame"); Loop = in->getAttributeAsBool("Loop"); clearTextures(); for(u32 i=1; true; ++i) { core::stringc tname = "Texture"; tname += (int)i; if (in->existsAttribute(tname.c_str())) { video::ITexture* tex = in->getAttributeAsTexture(tname.c_str()); if (tex) { tex->grab(); Textures.push_back(tex); } } else break; } } } // end namespace scene } // end namespace irr