#ifndef __mIVReader_H__ #define __mIVReader_H__ #include "ivnode.h" #include "ivmeshdata.h" #include "ivmanualmeshloader.h" #include "ogre.h" #define COMMENTCHAR '#' #define BLOCKSIZE 150 #define BUFFERSIZE 256 static const int validIVHeaderCnt = 2; static const char *validIVHeader[2] = { { "#Inventor V2.1 ascii\n" }, { "#VRML V1.0 ascii\n" }, }; enum IVTokenType { IV_TOKEN_INVALID = -1, IV_TOKEN_STRING = 0, IV_TOKEN_INT = 1, IV_TOKEN_REAL = 2, IV_TOKEN_BRACEOPEN = 3, // { IV_TOKEN_BRACECLOSE = 4, // } IV_TOKEN_BRACKETOPEN = 5, // [ IV_TOKEN_BRACKETCLOSE = 6, // ] IV_TOKEN_PARENTHESISOPEN = 7, // ( IV_TOKEN_PARENTHESISCLOSE = 8, // ) IV_TOKEN_DEF = 9, // DEF IV_TOKEN_USE = 10, // USE }; class __declspec(dllexport) IVMeshListNode { public: IVMeshListNode(std::string name, IVManualMeshLoader *loader); ~IVMeshListNode(); void attachNewNode(std::string name, IVManualMeshLoader *loader); IVManualMeshLoader *getManualMeshLoader(std::string name); IVMeshListNode *next; private: std::string name; IVManualMeshLoader *loader; }; class __declspec(dllexport) IVDefListNode { public: IVDefListNode(std::string name, IVNode *node); ~IVDefListNode(); void attachNewNode(std::string name, IVNode *node); IVNode *getDef(std::string name); IVDefListNode *next; private: std::string name; IVNode *node; }; class __declspec(dllexport) IVReader { public: IVReader(); ~IVReader(); void setLog(Ogre::Log *IVLog = NULL); bool loadFile(const char* filename); void print(); // IVNode *getNode(const char* name); void buildTree(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *sceneNodeRoot); void collapse(); static std::string intToStr(int num); static std::string realToStr(Ogre::Real num); static Ogre::Log *IVLog; private: bool checkHeader(const char *string); char buf[BUFFERSIZE]; int bufOffset; bool getNextElement(char *token, IVTokenType *type); void classify(char *token, IVTokenType *type); bool isSpace(char c); bool isNewline(char c); bool eof; bool isDigit(char c); bool isHexDigit(char c); IVNode *root; FILE* infile; static IVMeshListNode *meshList; static void addMeshToList(std::string name, IVManualMeshLoader *loader); static int instanceCnt; int treeCnt, nodeCnt, matCnt; char *fileName; Ogre::Entity *createEntity(Ogre::SceneManager* sceneMgr, std::string name, IVMeshData *mData, Ogre::Vector3 *translation = NULL); void buildTree(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *sceneNodeRoot, IVNode *mIVReaderoot, IVMeshData *mData = NULL, Ogre::Material *material = NULL); IVDefListNode *defList; void addDefToList(std::string name, IVNode *node); }; #endif