OBJParser
OBJ File Parser Powered by Boost Spirit
 All Classes Functions Variables Enumerations Enumerator Pages
OBJGrammar.hpp
1 /*
2  * Copyright 2016 Steven T Sell (ssell@vertexfragment.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __H__OBJ_PARSER_GRAMMAR__H__
18 #define __H__OBJ_PARSER_GRAMMAR__H__
19 
20 #include "OBJGrammarSkipper.hpp"
21 #include "OBJStructs.hpp"
22 
24 
25 //------------------------------------------------------------------------------------------
26 
27 class OBJState;
28 
37 class OBJGrammar : public qi::grammar<OBJIterator, OBJSkipper>
38 {
39 public:
40 
41  OBJGrammar(OBJState* state);
42 
43 private:
44 
45  //--------------------------------------------------------------------------------------
46  // Rule Setup Methods
47  //--------------------------------------------------------------------------------------
48 
49  void setupDataRules();
50  void setupGroupRules();
51  void setupVertexRules();
52  void setupFaceRules();
53  void setupFreeFormRules();
54  void setupFreeFormStart();
55  void setupFreeFormBody();
56  void setupFreeFormEnd();
57  void setupFreeFormAttributes();
58  void setupFreeFormConnections();
59  void setupMaterialRules();
60  void setupRenderStateRules();
61 
62  //--------------------------------------------------------------------------------------
63  // Member Variables
64  //--------------------------------------------------------------------------------------
65 
66  //--------------------------------------------------------------------
67  // Top-Level Rules
68  //--------------------------------------------------------------------
69 
70  qi::rule<OBJIterator, OBJSkipper> ruleStart;
71  qi::rule<OBJIterator, OBJSkipper> ruleVertices;
72  qi::rule<OBJIterator, OBJSkipper> ruleFaces;
73  qi::rule<OBJIterator, OBJSkipper> ruleFreeForms;
74  qi::rule<OBJIterator, OBJSkipper> ruleMaterials;
75  qi::rule<OBJIterator, OBJSkipper> ruleRenderState;
76  qi::rule<OBJIterator, OBJSkipper> ruleEmptyLine;
77 
78  //--------------------------------------------------------------------
79  // Group Rules
80  //--------------------------------------------------------------------
81 
82  qi::rule<OBJIterator, OBJSkipper> ruleGroup;
83  qi::rule<OBJIterator, std::string(), OBJSkipper> ruleGroupName;
84 
85  //--------------------------------------------------------------------
86  // Misc Data Rules
87  //--------------------------------------------------------------------
88 
89  qi::rule<OBJIterator, OBJVector2(), OBJSkipper> ruleVector2Data;
90  qi::rule<OBJIterator, OBJVector3(), OBJSkipper> ruleVector3Data;
91  qi::rule<OBJIterator, OBJVector4(), OBJSkipper> ruleVector4Data;
92  qi::rule<OBJIterator, OBJVertexGroup(), OBJSkipper> ruleVertexGroupData;
93  qi::rule<OBJIterator, int32_t(), OBJSkipper> ruleIndexValue;
94  qi::rule<OBJIterator, std::vector<OBJVertexGroup>(), OBJSkipper> ruleIndexList;
95  qi::rule<OBJIterator, std::string(), OBJSkipper> ruleName;
96 
97  //--------------------------------------------------------------------
98  // Vertex Rules
99  //--------------------------------------------------------------------
100 
101  qi::rule<OBJIterator, OBJSkipper> ruleVertexSpatial;
102  qi::rule<OBJIterator, OBJSkipper> ruleVertexTexture;
103  qi::rule<OBJIterator, OBJSkipper> ruleVertexNormal;
104  qi::rule<OBJIterator, OBJSkipper> ruleVertexParameter;
105 
106  //--------------------------------------------------------------------
107  // Face Rules
108  //--------------------------------------------------------------------
109 
110  qi::rule<OBJIterator, OBJFace(), OBJSkipper> ruleFaceData;
111  qi::rule<OBJIterator, OBJSkipper> ruleFace;
112 
113  qi::rule<OBJIterator, OBJSkipper> ruleLine;
114  qi::rule<OBJIterator, OBJSkipper> rulePoint;
115 
116  //--------------------------------------------------------------------
117  // Free-Form Rules
118  //--------------------------------------------------------------------
119 
120  // start statements
121 
122  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormStart;
123 
124  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormCurve;
125  qi::rule<OBJIterator, OBJCurve(), OBJSkipper> ruleFreeFormCurveData;
126 
127  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormCurve2D;
128  qi::rule<OBJIterator, std::vector<int32_t>(), OBJSkipper> ruleFreeFormCurve2DData;
129 
130  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormSurface;
131  qi::rule<OBJIterator, OBJSurface(), OBJSkipper> ruleFreeFormSurfaceData;
132 
133  // body statements (may only appear between start and end statements)
134 
135  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormBody;
136 
137  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormParameter; // parm
138  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormTrim; // trim
139  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormHole; // hole
140  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormSpecialCurve; // scrv
141  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormSpecialPoint; // sp
142 
143  // end statement
144 
145  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormEnd;
146 
147  // attribute statements
148 
149  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormAttributes;
150 
151  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormType; // cstype
152  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormDegree; // deg
153  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormStep; // step
154  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormBasisMatrix; // bmat
155  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormMergeGroup; // mg
156 
157  // connections
158 
159  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormConnection; // con
160 
161  //--------------------------------------------------------------------
162  // Material Rules
163  //--------------------------------------------------------------------
164 
165  qi::rule<OBJIterator, OBJSkipper> ruleMaterialLibrary;
166  qi::rule<OBJIterator, OBJSkipper> ruleMaterialUse;
167 
168  //--------------------------------------------------------------------
169  // Render Attribute Rules
170  //--------------------------------------------------------------------
171 
172  // polygon only
173 
174  qi::rule<OBJIterator, OBJSkipper> ruleBevelInterp;
175  qi::rule<OBJIterator, OBJSkipper> ruleColorInterp;
176  qi::rule<OBJIterator, OBJSkipper> ruleDissolveInterp;
177 
178  // all
179 
180  qi::rule<OBJIterator, OBJSkipper> ruleSmoothing;
181  qi::rule<OBJIterator, OBJSkipper> ruleLOD;
182  qi::rule<OBJIterator, OBJSkipper> ruleTextureMapLibrary;
183  qi::rule<OBJIterator, OBJSkipper> ruleTextureMap;
184  qi::rule<OBJIterator, OBJSkipper> ruleShadowObj;
185  qi::rule<OBJIterator, OBJSkipper> ruleTraceObj;
186 
187  // free-form only
188 
189  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormCurveTech;
190  qi::rule<OBJIterator, OBJSkipper> ruleFreeFormSurfaceTech;
191 
192  //--------------------------------------------------------------------
193  // Non-Rule Members
194  //--------------------------------------------------------------------
195 
196  OBJState* m_pOBJState;
197 
198 private:
199 
200 };
201 
202 //------------------------------------------------------------------------------------------
203 
204 #endif
205 
Definition: OBJGrammarSkipper.hpp:30
Definition: OBJGrammar.hpp:37
Definition: OBJState.hpp:37