OBJParser
OBJ File Parser Powered by Boost Spirit
 All Classes Functions Variables Enumerations Enumerator Pages
MTLGrammar.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_MTL_GRAMMAR__H__
18 #define __H__OBJ_PARSER_MTL_GRAMMAR__H__
19 
20 #include "MTLGrammarSkipper.hpp"
21 #include "OBJMaterial.hpp"
22 
24 
25 //------------------------------------------------------------------------------------------
26 
27 class OBJState;
28 
37 class MTLGrammar : public qi::grammar<OBJIterator, MTLSkipper>
38 {
39 public:
40 
41  MTLGrammar(OBJState* state);
42 
43  void resetCurrentTexture();
44  void finishCurrentMaterial();
45 
46 protected:
47 
48  //--------------------------------------------------------------------------------------
49  // Rule Setup Methods
50  //--------------------------------------------------------------------------------------
51 
52  void setupGeneralRules();
53  void setupNewMaterialRules();
54  void setupColorIlluminationRules();
55  void setupTextureMapRules();
56  void setupTextureMapFlagRules();
57  void setupReflectionMapRules();
58 
59  //--------------------------------------------------------------------------------------
60  // Member Variables
61  //--------------------------------------------------------------------------------------
62 
63  //--------------------------------------------------------------------
64  // Top-Level Rules
65 
66  qi::rule<OBJIterator, MTLSkipper> ruleStart;
67  qi::rule<OBJIterator, MTLSkipper> ruleNewMaterial;
68  qi::rule<OBJIterator, MTLSkipper> ruleColorIllumination;
69  qi::rule<OBJIterator, MTLSkipper> ruleTextureMap;
70  qi::rule<OBJIterator, MTLSkipper> ruleReflectionMap;
71 
72  //--------------------------------------------------------------------
73  // General Rules
74 
75  qi::rule<OBJIterator, std::string(), MTLSkipper> ruleString;
76  qi::rule<OBJIterator, std::string(), MTLSkipper> ruleStringNoSkip;
77  qi::rule<OBJIterator, OBJVector2(), MTLSkipper> ruleVector2Data;
78  qi::rule<OBJIterator, OBJVector3(), MTLSkipper> ruleVector3Data;
79  qi::rule<OBJIterator, bool(), MTLSkipper> ruleBoolOnOffTrue;
80  qi::rule<OBJIterator, bool(), MTLSkipper> ruleBoolOnOffFalse;
81 
82  //--------------------------------------------------------------------
83  // Color / Illumination Rules
84 
85  qi::rule<OBJIterator, MTLSkipper> ruleColor;
86  qi::rule<OBJIterator, MTLSkipper> ruleIllumination;
87  qi::rule<OBJIterator, OBJMaterialPropertyRFL(), MTLSkipper> ruleRFL;
88 
89  qi::rule<OBJIterator, MTLSkipper> ruleAmbientRGB;
90  qi::rule<OBJIterator, MTLSkipper> ruleAmbientSpectral;
91  qi::rule<OBJIterator, MTLSkipper> ruleAmbientXYZ;
92  qi::rule<OBJIterator, MTLSkipper> ruleAmbient;
93 
94  qi::rule<OBJIterator, MTLSkipper> ruleDiffuseRGB;
95  qi::rule<OBJIterator, MTLSkipper> ruleDiffuseSpectral;
96  qi::rule<OBJIterator, MTLSkipper> ruleDiffuseXYZ;
97  qi::rule<OBJIterator, MTLSkipper> ruleDiffuse;
98 
99  qi::rule<OBJIterator, MTLSkipper> ruleSpecularRGB;
100  qi::rule<OBJIterator, MTLSkipper> ruleSpecularSpectral;
101  qi::rule<OBJIterator, MTLSkipper> ruleSpecularXYZ;
102  qi::rule<OBJIterator, MTLSkipper> ruleSpecular;
103 
104  qi::rule<OBJIterator, MTLSkipper> ruleEmissiveRGB;
105  qi::rule<OBJIterator, MTLSkipper> ruleEmissiveSpectral;
106  qi::rule<OBJIterator, MTLSkipper> ruleEmissiveXYZ;
107  qi::rule<OBJIterator, MTLSkipper> ruleEmissive;
108 
109  qi::rule<OBJIterator, MTLSkipper> ruleTransmissionRGB;
110  qi::rule<OBJIterator, MTLSkipper> ruleTransmissionSpectral;
111  qi::rule<OBJIterator, MTLSkipper> ruleTransmissionXYZ;
112  qi::rule<OBJIterator, MTLSkipper> ruleTransmission;
113 
114  qi::rule<OBJIterator, bool(), MTLSkipper> ruleDissolveHalo;
115  qi::rule<OBJIterator, OBJMaterialDissolve(), MTLSkipper> ruleDissolveData;
116  qi::rule<OBJIterator, MTLSkipper> ruleDissolve;
117 
118  qi::rule<OBJIterator, MTLSkipper> ruleTransparency;
119 
120  qi::rule<OBJIterator, MTLSkipper> ruleSpecularExponent;
121  qi::rule<OBJIterator, MTLSkipper> ruleSharpness;
122  qi::rule<OBJIterator, MTLSkipper> ruleOpticalDensity;
123 
124  //--------------------------------------------------------------------
125  // Texture Map Rules
126 
127  // Top Texture Rules
128 
129  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlags;
130  qi::rule<OBJIterator, MTLSkipper> ruleTextureMapBody;
131  qi::rule<OBJIterator, MTLSkipper> ruleTextureAntiAliasing;
132 
133  // Individual Texture Map Rules
134 
135  qi::rule<OBJIterator, MTLSkipper> ruleTextureMapAmbient;
136  qi::rule<OBJIterator, MTLSkipper> ruleTextureMapDiffuse;
137  qi::rule<OBJIterator, MTLSkipper> ruleTextureMapSpecular;
138  qi::rule<OBJIterator, MTLSkipper> ruleTextureMapSpecularExponent;
139  qi::rule<OBJIterator, MTLSkipper> ruleTextureMapEmissive;
140  qi::rule<OBJIterator, MTLSkipper> ruleTextureMapDissolve;
141  qi::rule<OBJIterator, MTLSkipper> ruleTextureMapDecal;
142  qi::rule<OBJIterator, MTLSkipper> ruleTextureMapDisplacement;
143  qi::rule<OBJIterator, MTLSkipper> ruleTextureMapBump;
144 
145  // Optional Flags
146 
147  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagBlendU;
148  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagBlendV;
149  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagColorCorrection;
150  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagClamp;
151  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagOffset;
152  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagScale;
153  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagTurbulence;
154  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagRangeMod;
155  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagResolution;
156  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagBumpMultiplier;
157  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagBoost;
158  qi::rule<OBJIterator, MTLSkipper> ruleTextureFlagimfchan;
159 
160  //--------------------------------------------------------------------
161  // Reflection Map Rules
162 
163  qi::rule<OBJIterator, MTLSkipper> ruleReflectionMapSphere;
164  qi::rule<OBJIterator, MTLSkipper> ruleReflectionMapCubeTop;
165  qi::rule<OBJIterator, MTLSkipper> ruleReflectionMapCubeBottom;
166  qi::rule<OBJIterator, MTLSkipper> ruleReflectionMapCubeFront;
167  qi::rule<OBJIterator, MTLSkipper> ruleReflectionMapCubeBack;
168  qi::rule<OBJIterator, MTLSkipper> ruleReflectionMapCubeLeft;
169  qi::rule<OBJIterator, MTLSkipper> ruleReflectionMapCubeRight;
170 
171  //--------------------------------------------------------------------
172  // Non-Rule Members
173 
174  OBJState* m_pOBJState;
176  OBJTextureDescriptor m_CurrentTexture;
177 
178 private:
179 
180 };
181 
182 //------------------------------------------------------------------------------------------
183 
184 #endif
Definition: MTLGrammar.hpp:37
qi::rule< OBJIterator, bool(), MTLSkipper > ruleBoolOnOffFalse
Parses flag value "on" and "off". If none specified, returns FALSE by default.
Definition: MTLGrammar.hpp:80
qi::rule< OBJIterator, bool(), MTLSkipper > ruleBoolOnOffTrue
Parses flag value "on" and "off". If none specified, returns TRUE by default.
Definition: MTLGrammar.hpp:79
Definition: OBJTextureDescriptor.hpp:46
Definition: OBJMaterial.hpp:122
OBJMaterial m_CurrentMaterial
The current material being built by the parser.
Definition: MTLGrammar.hpp:175
Definition: MTLGrammarSkipper.hpp:30
Definition: OBJState.hpp:37