OBJParser
OBJ File Parser Powered by Boost Spirit
 All Classes Functions Variables Enumerations Enumerator Pages
OBJState.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_STATE__H__
18 #define __H__OBJ_PARSER_STATE__H__
19 
20 #include "OBJFreeFormState.hpp"
21 #include "OBJGroup.hpp"
22 #include "OBJRenderState.hpp"
23 #include "OBJMaterial.hpp"
24 
25 #include <unordered_map>
26 
27 //------------------------------------------------------------------------------------------
28 
37 class OBJState
38 {
39 public:
40 
41  OBJState();
42  ~OBJState();
43 
44  //--------------------------------------------------------------------
45 
50  void clearState();
51 
68  void reserve(uint32_t spatial, uint32_t texture = 0, uint32_t normal = 0, uint32_t groupFaces = 0, uint32_t groupFreeForms = 0);
69 
77 
87  OBJRenderState getRenderState(uint32_t index) const;
88 
99  void getGroups(std::vector<OBJGroup const*>& groups) const;
100 
105  std::vector<OBJVector4> const* getSpatialData() const;
106 
111  std::vector<OBJVector2> const* getTextureData() const;
112 
117  std::vector<OBJVector3> const* getNormalData() const;
118 
122  std::vector<std::string> const* getMaterialLibraries() const;
123 
124  void getMaterials(std::vector<OBJMaterial const*>& materials) const;
125 
126  //--------------------------------------------------------------------
127  // OBJ Parser/Grammar Methods
128  //--------------------------------------------------------------------
129 
135  void clearActiveGroups();
136 
145  void addActiveGroup(std::string const& name);
146 
147  //--------------------------------------------------------------------
148  // Vertex Data Methods
149  //--------------------------------------------------------------------
150 
158  void addVertexSpatial(OBJVector4 const& vector);
159 
167  void addVertexTexture(OBJVector2 const& vector);
168 
176  void addVertexNormal(OBJVector3 const& vector);
177 
185  void addVertexParameter(OBJVector3 const& vector);
186 
187  //--------------------------------------------------------------------
188  // Geometry Creation Methods
189  //--------------------------------------------------------------------
190 
198  void addFace(OBJFace face);
199 
207  void addLine(std::vector<OBJVertexGroup>& line);
208 
216  void addPointCollection(std::vector<OBJVertexGroup>& points);
217 
222  void addFreeFormCurve(OBJCurve const& curve);
223 
228  void addFreeFormCurve2D(std::vector<int32_t> const& points);
229 
234  void addFreeFormSurface(OBJSurface const& surface);
235 
241 
242  //--------------------------------------------------------------------
243  // Free-Form Body Methods
244  //--------------------------------------------------------------------
245 
250  void addFreeFormParameterU(std::vector<float> const& parameters);
251 
256  void addFreeFormParameterV(std::vector<float> const& parameters);
257 
262  void addFreeFormTrim(OBJSimpleCurve const& trim);
263 
268  void addFreeFormHole(OBJSimpleCurve const& hole);
269 
274  void addFreeFormSpecialCurve(OBJSimpleCurve const& scurve);
275 
280  void addFreeFormSpecialPoints(std::vector<int32_t> const& points);
281 
282  //--------------------------------------------------------------------
283  // Render State Setting Methods
284  //--------------------------------------------------------------------
285 
293  void setSmoothingGroup(uint32_t group);
294 
302  void setLevelOfDetail(uint32_t lod);
303 
311  void setBevelInterp(bool on);
312 
320  void setColorInterp(bool on);
321 
329  void setDissolveInterp(bool on);
330 
338  void setMaterial(std::string const& name);
339 
348  void setMaterial(std::string const& name, OBJMaterial const& material);
349 
357  void addMaterialLibrary(std::string const& path);
358 
366  void setTextureMap(std::string const& name);
367 
375  void addTextureMapLibrary(std::string const& path);
376 
384  void setShadowObject(std::string const& name);
385 
393  void setTracingObject(std::string const& name);
394 
395  //--------------------------------------------------------------------
396  // Free-Form Technique Methods
397  //--------------------------------------------------------------------
398 
404  void setTechniqueParametric(float res);
405 
411  void setTechniqueParametricA(OBJVector2 const& vec);
412 
418  void setTechniqueParametricB(float res);
419 
425  void setTechniqueSpatialCurve(float length);
426 
432  void setTechniqueSpatialSurface(float length);
433 
439  void setTechniqueCurvatureCurve(OBJVector2 const& vec);
440 
446  void setTechniqueCurvatureSurface(OBJVector2 const& vec);
447 
448  //--------------------------------------------------------------------
449  // Free-Form Attribute State Methods
450  //--------------------------------------------------------------------
451 
457  void setFreeFormType(OBJFreeFormType type);
458 
464  void setFreeFormRational(bool rational);
465 
471  void setFreeFormDegreeU(int32_t degree);
472 
478  void setFreeFormDegreeV(int32_t degree);
479 
485  void setFreeFormStepU(int32_t step);
486 
492  void setFreeFormStepV(int32_t step);
493 
499  void setFreeFormBasisMatrixU(std::vector<float> const& matrix);
500 
506  void setFreeFormBasisMatrixV(std::vector<float> const& matrix);
507 
513  void setFreeFormMergeGroupNumber(int32_t id);
514 
520  void setFreeFormMergeGroupResolution(float res);
521 
522 protected:
523 
524  void resetAuxiliaryStates();
525  void transformVertexGroup(OBJVertexGroup& source) const;
526 
527  //--------------------------------------------------------------------
528 
529  uint32_t m_GroupFacesReservedSize;
530  uint32_t m_GroupFreeFormReservedSize;
531 
532  OBJFreeFormState m_FreeFormState;
533  bool m_FreeFormRational;
534 
535  std::unordered_map<std::string, OBJGroup> m_GroupMap;
536  std::unordered_map<std::string, OBJMaterial> m_MaterialMap;
537 
538  std::vector<OBJGroup*> m_ActiveGroups;
539 
540  std::vector<OBJVector4> m_VertexSpatialData;
541  std::vector<OBJVector2> m_VertexTextureData;
542  std::vector<OBJVector3> m_VertexNormalData;
543 
544  std::vector<std::string> m_MaterialLibraries;
545  std::vector<std::string> m_TextureMapLibraries;
546 
547  std::vector<OBJRenderState> m_RenderStates;
548 
549 private:
550 };
551 
552 //------------------------------------------------------------------------------------------
553 
554 #endif
std::vector< OBJVector4 > const * getSpatialData() const
Definition: OBJState.cpp:94
void setFreeFormDegreeU(int32_t degree)
Definition: OBJState.cpp:583
void addVertexTexture(OBJVector2 const &vector)
Definition: OBJState.cpp:174
void setLevelOfDetail(uint32_t lod)
Definition: OBJState.cpp:366
OBJFreeFormState * getFreeFormState()
Definition: OBJState.cpp:66
void addVertexParameter(OBJVector3 const &vector)
Definition: OBJState.cpp:184
void setTechniqueParametricA(OBJVector2 const &vec)
Definition: OBJState.cpp:487
A standard curve object.
Definition: OBJStructs.hpp:223
void getGroups(std::vector< OBJGroup const * > &groups) const
Definition: OBJState.cpp:83
void clearActiveGroups()
Definition: OBJState.cpp:125
Simple two-component vector struct.
Definition: OBJStructs.hpp:32
void setColorInterp(bool on)
Definition: OBJState.cpp:395
void addFreeFormCurve(OBJCurve const &curve)
Definition: OBJState.cpp:234
void addLine(std::vector< OBJVertexGroup > &line)
Definition: OBJState.cpp:208
OBJRenderState getRenderState(uint32_t index) const
Definition: OBJState.cpp:71
void setFreeFormType(OBJFreeFormType type)
Definition: OBJState.cpp:567
void setTechniqueSpatialSurface(float length)
Definition: OBJState.cpp:525
Collection of vertex groups comprising a single face.
Definition: OBJStructs.hpp:104
Struct of optional state settings.
Definition: OBJRenderState.hpp:100
Individual curve definition comprising a larger free-form object.
Definition: OBJStructs.hpp:181
void setFreeFormStepU(int32_t step)
Definition: OBJState.cpp:593
void setFreeFormBasisMatrixV(std::vector< float > const &matrix)
Definition: OBJState.cpp:611
void addPointCollection(std::vector< OBJVertexGroup > &points)
Definition: OBJState.cpp:221
void addActiveGroup(std::string const &name)
Definition: OBJState.cpp:135
void setTextureMap(std::string const &name)
Definition: OBJState.cpp:432
void setTechniqueParametric(float res)
Definition: OBJState.cpp:475
void addFreeFormSpecialCurve(OBJSimpleCurve const &scurve)
Definition: OBJState.cpp:352
void addFreeFormSurface(OBJSurface const &surface)
Definition: OBJState.cpp:267
void reserve(uint32_t spatial, uint32_t texture=0, uint32_t normal=0, uint32_t groupFaces=0, uint32_t groupFreeForms=0)
Definition: OBJState.cpp:56
Definition: OBJFreeFormState.hpp:28
std::vector< OBJVector3 > const * getNormalData() const
Definition: OBJState.cpp:104
void setFreeFormMergeGroupResolution(float res)
Definition: OBJState.cpp:624
void setTechniqueCurvatureSurface(OBJVector2 const &vec)
Definition: OBJState.cpp:550
Definition: OBJMaterial.hpp:122
void addFreeFormSpecialPoints(std::vector< int32_t > const &points)
Definition: OBJState.cpp:357
void setFreeFormRational(bool rational)
Definition: OBJState.cpp:578
void setTracingObject(std::string const &name)
Definition: OBJState.cpp:458
void addVertexSpatial(OBJVector4 const &vector)
Definition: OBJState.cpp:169
void clearState()
Definition: OBJState.cpp:40
void setFreeFormBasisMatrixU(std::vector< float > const &matrix)
Definition: OBJState.cpp:603
std::vector< std::string > const * getMaterialLibraries() const
Definition: OBJState.cpp:109
Specifies connectivity between two different surfaces.
Definition: OBJStructs.hpp:277
Definition: OBJStructs.hpp:261
void setMaterial(std::string const &name)
Definition: OBJState.cpp:411
void setTechniqueSpatialCurve(float length)
Definition: OBJState.cpp:513
void addFreeFormParameterV(std::vector< float > const &parameters)
Definition: OBJState.cpp:338
void addFace(OBJFace face)
Definition: OBJState.cpp:193
void addMaterialLibrary(std::string const &path)
Definition: OBJState.cpp:427
void addVertexNormal(OBJVector3 const &vector)
Definition: OBJState.cpp:179
void setSmoothingGroup(uint32_t group)
Definition: OBJState.cpp:379
void setTechniqueCurvatureCurve(OBJVector2 const &vec)
Definition: OBJState.cpp:537
void addFreeFormParameterU(std::vector< float > const &parameters)
Definition: OBJState.cpp:333
Simple three-component vector struct.
Definition: OBJStructs.hpp:41
void setBevelInterp(bool on)
Definition: OBJState.cpp:387
void setFreeFormStepV(int32_t step)
Definition: OBJState.cpp:598
std::vector< OBJVector2 > const * getTextureData() const
Definition: OBJState.cpp:99
void addFreeFormTrim(OBJSimpleCurve const &trim)
Definition: OBJState.cpp:342
void addFreeFormCurve2D(std::vector< int32_t > const &points)
Definition: OBJState.cpp:249
void addFreeFormConnection(OBJSurfaceConnection connection)
Definition: OBJState.cpp:282
void setFreeFormDegreeV(int32_t degree)
Definition: OBJState.cpp:588
void setDissolveInterp(bool on)
Definition: OBJState.cpp:403
void addTextureMapLibrary(std::string const &path)
Definition: OBJState.cpp:440
void addFreeFormHole(OBJSimpleCurve const &hole)
Definition: OBJState.cpp:347
Definition: OBJState.hpp:37
void setFreeFormMergeGroupNumber(int32_t id)
Definition: OBJState.cpp:619
Index pairing comprising a single vertex of a face.
Definition: OBJStructs.hpp:78
void setShadowObject(std::string const &name)
Definition: OBJState.cpp:445
void setTechniqueParametricB(float res)
Definition: OBJState.cpp:500