
#ifndef __WFX_SCENE_SCENEGRAPHSERIALIZER_H__
#define __WFX_SCENE_SCENEGRAPHSERIALIZER_H__

#include <WFX/WFXIncludes.h>
#include <WFX/scene/SceneGraphVisitor.h>
#include <WFX/io/OutputStream.h>

namespace WFX {

    namespace scene {

        /**
         * pretty-prints the SceneGraph
         */
        class SceneGraphSerializer : public SceneGraphVisitor {
            public:
                enum SceneGraphConstant {
                    SGC_VERSION             = 0x00000001,

                    SGC_TEXTURES            = 0x00000100,
                    SGC_MATERIALS           = 0x00000200,
                    
                    SGC_NODE                = 0x00010000,
                    SGC_TRIMESH             = 0x00020000,
                    SGC_OCTREENODE          = 0x00030000,
                    
                    SGC_SPATIALDATA         = 0x01000000,
                    SGC_BOUNDINGVOL         = 0x01000100,
                    SGC_SPHERE              = 0x01000101,
                    SGC_CUBE                = 0x01000102,
                    
                    SGC_GEOMNODEDATA        = 0x02000000,
                    SGC_VERTICES            = 0x02000001,
                    SGC_NORMALS             = 0x02000002,
                    SGC_COLORS              = 0x02000003,
                    SGC_TEXCOORDS           = 0x02000004,
                    SGC_MATERIAL            = 0x02000005,
                    SGC_GEOMNODEEND         = 0x0200000F,

                    SGC_MAGICNUMBER         = 0xDEADBEEF
                };
                /** Ctor */
                SceneGraphSerializer(WFX::io::OutputStream* o);

                /** visits a Node */
                void visitNode(Node& n);
                /** visits a TriMesh */
                void visitTriMesh(TriMesh& m);
                /** visits an OctreeNode */
                void visitOctreeNode(OctreeNode& o);
                /** visit a Sphere */
                void visitSphere(WFX::math::Sphere& s);
                /** visit a Cube */
                void visitCube(WFX::math::Cube& c);

            protected:
            
            private:
                /** output stream */
                WFX::io::OutputStream* Output;

                /** writes materials */
                void writeMaterials();
                
                /** writes spatial data */
                void writeSpatialData(Spatial& s);
                /** writes GeometryNode data */
                void writeGeomNodeData(GeometryNode& n);

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

    }

}


#endif //include guard


