
#include <WFX/scene/GeometryLoader.h>
#include <WFX/kernel/TimeTask.h>
#include <WFX/lang/WFXException.h>
#include <WFX/scene/StudioLoader.h>
#include <WFX/scene/WFXLoader.h>


using namespace WFX;
using namespace WFX::lang;
using namespace WFX::scene;
using namespace WFX::kernel;


Node* GeometryLoader::load(const WFX::io::File& f, bool r) {
    LOG("Loading file " << f.toString());
    ULong start = TimeTask::getInstance().getTicks();
    Node* ret = NULL;

    GeometryLoader* l;

    //set TextureManager BaseDir


    //find appropriate loader
    std::string ext = f.getExt();
    if (ext == "3ds") {
        l = new StudioLoader(); 
    } else if (ext == "wsg") {
        l = new WFXLoader();
    } else {
        THROW("Unknown File Extension: " << ext);
    }
   
    try {
        ret = l->loadFromFile(f, r); 
    } catch (WFXException& e) {
        RETHROW(e, "unable to load File: " << f.toString());
    }
    
    ULong stop = TimeTask::getInstance().getTicks();
    LOG("Time taken: " << stop-start);
    delete l;
    return ret;
}

