OBJParser
OBJ File Parser Powered by Boost Spirit
 All Classes Functions Variables Enumerations Enumerator Pages
OBJStructs.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_STRUCTS__H__
18 #define __H__OBJ_PARSER_STRUCTS__H__
19 
20 #include <boost/fusion/adapted.hpp>
21 
22 #include <string>
23 #include <cstdint>
24 #include <vector>
25 
26 //------------------------------------------------------------------------------------------
27 
32 struct OBJVector2
33 {
34  OBJVector2();
35  OBJVector2 const& operator=(OBJVector2 const& rhs);
36 
37  union { float x, r, u, s; };
38  union { float y, g, v, t; };
39 };
40 
41 BOOST_FUSION_ADAPT_STRUCT(OBJVector2, (float, x), (float, y))
42 
43 //------------------------------------------------------------------------------------------
44 
45 
49 struct OBJVector3
50 {
51  OBJVector3();
52  OBJVector3 const& operator=(OBJVector3 const& rhs);
53 
54  union { float x, r, u, s; };
55  union { float y, g, v, t; };
56  union { float z, b, w; };
57 };
58 
59 BOOST_FUSION_ADAPT_STRUCT(OBJVector3, (float, x), (float, y), (float, z))
60 
61 //------------------------------------------------------------------------------------------
62 
63 
67  struct OBJVector4
68  {
69  OBJVector4();
70  OBJVector4 const& operator=(OBJVector4 const& rhs);
71 
72  union { float x, r, u, s; };
73  union { float y, g, v, t; };
74  union { float z, b, p; };
75  union { float w, a, q; };
76  };
77 
78 BOOST_FUSION_ADAPT_STRUCT(OBJVector4, (float, x), (float, y), (float, z), (float, w))
79 
80 //------------------------------------------------------------------------------------------
81 
82 
95 struct OBJVertexGroup
96 {
97  OBJVertexGroup();
98 
99  int32_t indexSpatial;
100  int32_t indexTexture;
101  int32_t indexNormal;
102 };
103 
104 BOOST_FUSION_ADAPT_STRUCT(OBJVertexGroup, (int32_t, indexSpatial), (int32_t, indexTexture), (int32_t, indexNormal))
105 
106 //------------------------------------------------------------------------------------------
107 
108 
123 struct OBJFace
124 {
125  OBJFace();
126 
127  //--------------------------------------------------------------------
128 
129  OBJVertexGroup group0;
130  OBJVertexGroup group1;
131  OBJVertexGroup group2;
132  OBJVertexGroup group3;
133 
134  uint32_t renderState;
135 };
136 
137 BOOST_FUSION_ADAPT_STRUCT(OBJFace, (OBJVertexGroup, group0), (OBJVertexGroup, group1), (OBJVertexGroup, group2), (OBJVertexGroup, group3), (uint32_t, renderState))
138 
139 //------------------------------------------------------------------------------------------
140 
141 
147 struct OBJLine
148 {
149  OBJLine();
150  OBJLine(std::vector<OBJVertexGroup> const& vector);
151 
152  std::vector<OBJVertexGroup> segments;
153 };
154 
155 BOOST_FUSION_ADAPT_STRUCT(OBJLine, (std::vector<OBJVertexGroup>, segments))
156 
157 //------------------------------------------------------------------------------------------
158 
159 
165 struct OBJPoint
166 {
167  OBJPoint();
168  OBJPoint(std::vector<OBJVertexGroup> const& vector);
169 
170  std::vector<OBJVertexGroup> points;
171 };
172 
173 BOOST_FUSION_ADAPT_STRUCT(OBJPoint, (std::vector<OBJVertexGroup>, points))
174 
175 //------------------------------------------------------------------------------------------
176 
177 
182 {
183  OBJSimpleCurve();
184 
185  float startParam;
186  float endParam;
187 
188  int32_t curve2DIndex;
189 };
190 
191 BOOST_FUSION_ADAPT_STRUCT(OBJSimpleCurve, (float, startParam), (float, endParam), (int32_t, curve2DIndex))
192 
193 //------------------------------------------------------------------------------------------
194 
195 
199 struct OBJFreeForm
200 {
201  OBJFreeForm();
202 
203  //--------------------------------------------------------------------
204 
205  uint32_t attributeState;
206 
207  std::vector<float> parametersU;
208  std::vector<float> parametersV;
209 
210  std::vector<OBJSimpleCurve> trims;
211  std::vector<OBJSimpleCurve> holes;
212  std::vector<OBJSimpleCurve> specialCurves;
213 
214  std::vector<int32_t> specialPoints;
215 };
216 
217 //------------------------------------------------------------------------------------------
218 
223 struct OBJCurve : public OBJFreeForm
224 {
225  OBJCurve();
226  OBJCurve(float start, float end, std::vector<OBJVertexGroup> const& points);
227 
228  //--------------------------------------------------------------------
229 
230  float startParam;
231  float endParam;
232 
233  std::vector<OBJVertexGroup> controlPoints;
234 };
235 
236 BOOST_FUSION_ADAPT_STRUCT(OBJCurve, (float, startParam), (float, endParam), (std::vector<OBJVertexGroup>, controlPoints))
237 
238 //------------------------------------------------------------------------------------------
239 
240 
244 struct OBJCurve2D : public OBJFreeForm
245 {
246  OBJCurve2D();
247  OBJCurve2D(std::vector<int32_t> const& points);
248 
249  //--------------------------------------------------------------------
250 
251  std::vector<int32_t> parameterVertexIndices;
252 };
253 
254 BOOST_FUSION_ADAPT_STRUCT(OBJCurve2D, (std::vector<int32_t>, parameterVertexIndices))
255 
256 //------------------------------------------------------------------------------------------
257 
258 
261 struct OBJSurface : public OBJFreeForm
262 {
263  OBJSurface();
264  OBJSurface(float startU, float endU, float startV, float endV, std::vector<OBJVertexGroup> const& points);
265 
266  //--------------------------------------------------------------------
267 
268  float startParamU;
269  float endParamU;
270 
271  float startParamV;
272  float endParamV;
273 
274  std::vector<OBJVertexGroup> controlPoints;
275 };
276 
277 BOOST_FUSION_ADAPT_STRUCT(OBJSurface, (float, startParamU), (float, endParamU), (float, startParamV), (float, endParamV), (std::vector<OBJVertexGroup>, controlPoints))
278 
279 //------------------------------------------------------------------------------------------
280 
281 
286 {
287  OBJSurfaceConnection();
288  OBJSurfaceConnection(int32_t surf1, float startParam1, float endParam1, int32_t curv2D1, int32_t surf2, float startParam2, float endParam2, int32_t curv2D2);
289 
290  //--------------------------------------------------------------------
291 
292  int32_t surfaceIndex0;
293  int32_t surfaceIndex1;
294 
295  int32_t curve2DIndex0;
296  int32_t curve2DIndex1;
297 
298  float startParam0;
299  float endParam0;
300 
301  float startParam1;
302  float endParam1;
303 };
304 
305 BOOST_FUSION_ADAPT_STRUCT(OBJSurfaceConnection,
306  (int32_t, surfaceIndex0), (float, startParam0), (float, endParam0), (int32_t, curve2DIndex0),
307  (int32_t, surfaceIndex1), (float, startParam1), (float, endParam1), (int32_t, curve2DIndex1))
308 
309 //------------------------------------------------------------------------------------------
310 
311 #endif
312 
A standard curve object.
Definition: OBJStructs.hpp:223
Simple two-component vector struct.
Definition: OBJStructs.hpp:32
int32_t curve2DIndex
Index of the OBJCurve2D special curve lying in the parameter space of the surface.
Definition: OBJStructs.hpp:188
Collection of vertex groups comprising a single face.
Definition: OBJStructs.hpp:104
Individual curve definition comprising a larger free-form object.
Definition: OBJStructs.hpp:181
float startParam
Starting parameter value for the trimming curve.
Definition: OBJStructs.hpp:185
float endParam
Ending parameter value for the trimming curve.
Definition: OBJStructs.hpp:186
Specifies connectivity between two different surfaces.
Definition: OBJStructs.hpp:277
Definition: OBJStructs.hpp:261
A 2D curve on a surface.
Definition: OBJStructs.hpp:236
Collection of vertex groups comprising a line.
Definition: OBJStructs.hpp:137
Simple three-component vector struct.
Definition: OBJStructs.hpp:41
Collection of vertex groups comprising a point collection.
Definition: OBJStructs.hpp:165
A free-form object in the form of a curve or surface.
Definition: OBJStructs.hpp:191
Index pairing comprising a single vertex of a face.
Definition: OBJStructs.hpp:78