1 | #ifndef __mIVReader_H__
|
---|
2 | #define __mIVReader_H__
|
---|
3 |
|
---|
4 |
|
---|
5 | #include "ivnode.h"
|
---|
6 | #include "ivmeshdata.h"
|
---|
7 | #include "ivmanualmeshloader.h"
|
---|
8 | #include "ogre.h"
|
---|
9 |
|
---|
10 | #define COMMENTCHAR '#'
|
---|
11 | #define BLOCKSIZE 150
|
---|
12 | #define BUFFERSIZE 256
|
---|
13 |
|
---|
14 |
|
---|
15 | static const int validIVHeaderCnt = 2;
|
---|
16 |
|
---|
17 | static const char *validIVHeader[2] = {
|
---|
18 | { "#Inventor V2.1 ascii\n" },
|
---|
19 | { "#VRML V1.0 ascii\n" },
|
---|
20 | };
|
---|
21 |
|
---|
22 |
|
---|
23 | enum IVTokenType
|
---|
24 | {
|
---|
25 | IV_TOKEN_INVALID = -1,
|
---|
26 | IV_TOKEN_STRING = 0,
|
---|
27 | IV_TOKEN_INT = 1,
|
---|
28 | IV_TOKEN_REAL = 2,
|
---|
29 | IV_TOKEN_BRACEOPEN = 3, // {
|
---|
30 | IV_TOKEN_BRACECLOSE = 4, // }
|
---|
31 | IV_TOKEN_BRACKETOPEN = 5, // [
|
---|
32 | IV_TOKEN_BRACKETCLOSE = 6, // ]
|
---|
33 | IV_TOKEN_PARENTHESISOPEN = 7, // (
|
---|
34 | IV_TOKEN_PARENTHESISCLOSE = 8, // )
|
---|
35 | IV_TOKEN_DEF = 9, // DEF
|
---|
36 | IV_TOKEN_USE = 10, // USE
|
---|
37 | };
|
---|
38 |
|
---|
39 | class __declspec(dllexport) IVMeshListNode
|
---|
40 | {
|
---|
41 | public:
|
---|
42 | IVMeshListNode(std::string name, IVManualMeshLoader *loader);
|
---|
43 | ~IVMeshListNode();
|
---|
44 |
|
---|
45 | void attachNewNode(std::string name, IVManualMeshLoader *loader);
|
---|
46 |
|
---|
47 | IVManualMeshLoader *getManualMeshLoader(std::string name);
|
---|
48 |
|
---|
49 | IVMeshListNode *next;
|
---|
50 |
|
---|
51 | private:
|
---|
52 | std::string name;
|
---|
53 | IVManualMeshLoader *loader;
|
---|
54 | };
|
---|
55 |
|
---|
56 | class __declspec(dllexport) IVDefListNode
|
---|
57 | {
|
---|
58 | public:
|
---|
59 | IVDefListNode(std::string name, IVNode *node);
|
---|
60 | ~IVDefListNode();
|
---|
61 |
|
---|
62 | void attachNewNode(std::string name, IVNode *node);
|
---|
63 |
|
---|
64 | IVNode *getDef(std::string name);
|
---|
65 |
|
---|
66 | IVDefListNode *next;
|
---|
67 |
|
---|
68 | private:
|
---|
69 | std::string name;
|
---|
70 | IVNode *node;
|
---|
71 |
|
---|
72 | };
|
---|
73 |
|
---|
74 | class __declspec(dllexport) IVReader
|
---|
75 | {
|
---|
76 | public:
|
---|
77 | IVReader();
|
---|
78 | ~IVReader();
|
---|
79 |
|
---|
80 | void setLog(Ogre::Log *IVLog = NULL);
|
---|
81 |
|
---|
82 | bool loadFile(const char* filename);
|
---|
83 | void print();
|
---|
84 | // IVNode *getNode(const char* name);
|
---|
85 |
|
---|
86 |
|
---|
87 | void buildTree(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *sceneNodeRoot);
|
---|
88 |
|
---|
89 | void collapse();
|
---|
90 |
|
---|
91 | static std::string intToStr(int num);
|
---|
92 | static std::string realToStr(Ogre::Real num);
|
---|
93 |
|
---|
94 | static Ogre::Log *IVLog;
|
---|
95 |
|
---|
96 | private:
|
---|
97 | bool checkHeader(const char *string);
|
---|
98 | char buf[BUFFERSIZE];
|
---|
99 | int bufOffset;
|
---|
100 | bool getNextElement(char *token, IVTokenType *type);
|
---|
101 | void classify(char *token, IVTokenType *type);
|
---|
102 |
|
---|
103 | bool isSpace(char c);
|
---|
104 | bool isNewline(char c);
|
---|
105 | bool eof;
|
---|
106 | bool isDigit(char c);
|
---|
107 | bool isHexDigit(char c);
|
---|
108 |
|
---|
109 | IVNode *root;
|
---|
110 | FILE* infile;
|
---|
111 |
|
---|
112 | static IVMeshListNode *meshList;
|
---|
113 | static void addMeshToList(std::string name, IVManualMeshLoader *loader);
|
---|
114 |
|
---|
115 | static int instanceCnt;
|
---|
116 |
|
---|
117 | int treeCnt, nodeCnt, matCnt;
|
---|
118 | char *fileName;
|
---|
119 |
|
---|
120 | Ogre::Entity *createEntity(Ogre::SceneManager* sceneMgr, std::string name, IVMeshData *mData, Ogre::Vector3 *translation = NULL);
|
---|
121 |
|
---|
122 | void buildTree(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *sceneNodeRoot, IVNode *mIVReaderoot, IVMeshData *mData = NULL, Ogre::Material *material = NULL);
|
---|
123 |
|
---|
124 | IVDefListNode *defList;
|
---|
125 | void addDefToList(std::string name, IVNode *node);
|
---|
126 |
|
---|
127 | };
|
---|
128 |
|
---|
129 |
|
---|
130 | #endif |
---|