
#ifndef __WFX_SCENE_WFXLOADER_H__
#define __WFX_SCENE_WFXLOADER_H__

#include <WFX/WFXIncludes.h>
#include <WFX/scene/GeometryLoader.h>
#include <WFX/scene/Node.h>
#include <WFX/scene/OctreeNode.h>
#include <WFX/io/InputStream.h>

namespace WFX {

    namespace scene {

        /**
         * Loads files written by SceneGraphSerializer
         */
        class WFXLoader : public GeometryLoader {
            public:
                /** Ctor */
                WFXLoader();
                virtual ~WFXLoader();

                /**
                 * tries to parse the given File and returns a Node*
                 * Implementations must implement this method
                 */
                Node* loadFromFile(const WFX::io::File& f, bool r = false);

            protected:
                /** Input Stream */
                WFX::io::InputStream* Input;
                /** Rotation? */
                bool Rotate;
            
            private:
                /** output node */
                Node* Output;

                /** starts parsing */
                void parse();
                /** reads a subtree */
                Spatial* parseTree();
                /** parses a Node */
                Node* parseNode();
                /** parses a TriMesh */
                TriMesh* parseTriMesh();
                /** parses an OctreeNode */
                OctreeNode* parseOctreeNode();
               
                /** reads materials */
                void readMaterials();
                
                /** parses Spatial Data */
                void readSpatialData(Spatial* s);
                /** parses GeomentrNode Data */
                void readGeomNodeData(GeometryNode* s);

                /** read helper functions */
                void read(WFX::math::Matrix3& m);
                void read(WFX::math::Vector3& v);
                void read(WFX::math::Vector2& v);
                void read(WFX::scene::Color& c);
                void read(WFX::math::Vector3* v, UInt n);
                void read(WFX::math::Vector2* v, UInt n);
                void read(WFX::scene::Color* c, UInt n);
        };

    }

}


#endif //include guard


