Replaying an animation using the data manager

// Access the cluster's resource manager:
RED::Object* resmgr = RED::Factory::CreateInstance( CID_REDResourceManager );
RED::IResourceManager* iresmgr = resmgr->As< RED::IResourceManager >();
const RED::State& state = iresmgr->BeginState();

// Access the data manager:
RED::Object* datamgr = iresmgr->GetDataManager();
RED::IDataManager* idatamgr = datamgr->As< RED::IDataManager >();

// Load a file ('ifile' is our RED::IREDFile handler, assuming we have saved one animated scene graph in it):
RED::StreamingPolicy policy;
RED::FileHeader fheader;
RED::FileInfo finfo;
RED::Vector< unsigned int > context;
RC_TEST( ifile->Load( "./", iresmgr->GetState(), policy, fheader, finfo, context ) );

// Access the scene graph at frame 0, and add it to a camera:
RED::Object* root;
RC_TEST( idatamgr->GetSceneRoot( root, context[0], 0, state, 0 ) );
RC_TEST( icamera->AddShape( root, state ) );

// Query the length of the animation:
unsigned int frames_count;
RC_TEST( idatamgr->GetFramesCount( frames_count, context[0] ) );

// Access the scene graph for each frame of the animation. 'root' is modified in-place and does not
// need to be reassigned into 'icamera'. The engine will update the scene graph automatically:
for( unsigned int i = 1; i < frames_count; i++ )
  RC_TEST( idatamgr->GetSceneRoot( root, context[0], 0, state, i ) );

The loaded .red file returns the context number to be used by the application. In the example, we assume that we have one context in 'context[0]' that corresponds to our loaded animated scene graph. Once the scene graph root has been retrieved and added to a viewpoint for the display, updating the animated scene graph is simply performed by accessing the scene graph root again, but using another frame counter indicator.