
#include "../include/WFXConvert.h"
#include <WFX/lang/WFXSystem.h>

using namespace WFX;
using namespace WFX::io;
using namespace WFX::scene;
using namespace WFX::lang;
using namespace std;


WFXConvert::WFXConvert(Int argc, Char *argv[]) : WFXCLIApplication(argc, argv) {
    //we need some singletons...
    SYS.getTextureManager(true);
    SYS.getTimeTask();
    MaterialManager* mm = new MaterialManager();
    //SceneGraph object
    ListSceneGraph sg;
    OctreeBuilder ob;

    
    //find input and output files
    for (UInt i=0; i<Params.getFileCount()-1; i++) {
        File file(Params.getFile(i));
        if (Params.hasOption("-ot"))
            ob.addSource(GeometryLoader::load(file, true));
        else 
            sg.add(GeometryLoader::load(file, true));
    }

    if (Params.hasOption("-ot")) {
        ob.build();
        sg.add(ob.getOctree());
    }

    //output file
    File oFile = Params.getFile(Params.getFileCount()-1);
    EndianAwareOutputStream out(new FileOutputStream(oFile, ios::out | ios::binary));
   
    LOGN("writing " << oFile.toString() << " ... ");
    SceneGraphSerializer sgs(&out);
    sg.accept(sgs);
    LOG("done");

    //print
    //SceneGraphPrinter p;
    //sg.accept(p);

    delete mm;
}

WFXConvert::~WFXConvert() {
}

void WFXConvert::run() {
}

void WFXConvert::exit() {
}

