OBJParser
OBJ File Parser Powered by Boost Spirit
|
#include <OBJState.hpp>
Public Member Functions | |
void | clearState () |
void | reserve (uint32_t spatial, uint32_t texture=0, uint32_t normal=0, uint32_t groupFaces=0, uint32_t groupFreeForms=0) |
OBJFreeFormState * | getFreeFormState () |
OBJRenderState | getRenderState (uint32_t index) const |
void | getGroups (std::vector< OBJGroup const * > &groups) const |
std::vector< OBJVector4 > const * | getSpatialData () const |
std::vector< OBJVector2 > const * | getTextureData () const |
std::vector< OBJVector3 > const * | getNormalData () const |
std::vector< std::string > const * | getMaterialLibraries () const |
void | getMaterials (std::vector< OBJMaterial const * > &materials) const |
void | clearActiveGroups () |
void | addActiveGroup (std::string const &name) |
void | addVertexSpatial (OBJVector4 const &vector) |
void | addVertexTexture (OBJVector2 const &vector) |
void | addVertexNormal (OBJVector3 const &vector) |
void | addVertexParameter (OBJVector3 const &vector) |
void | addFace (OBJFace face) |
void | addLine (std::vector< OBJVertexGroup > &line) |
void | addPointCollection (std::vector< OBJVertexGroup > &points) |
void | addFreeFormCurve (OBJCurve const &curve) |
void | addFreeFormCurve2D (std::vector< int32_t > const &points) |
void | addFreeFormSurface (OBJSurface const &surface) |
void | addFreeFormConnection (OBJSurfaceConnection connection) |
void | addFreeFormParameterU (std::vector< float > const ¶meters) |
void | addFreeFormParameterV (std::vector< float > const ¶meters) |
void | addFreeFormTrim (OBJSimpleCurve const &trim) |
void | addFreeFormHole (OBJSimpleCurve const &hole) |
void | addFreeFormSpecialCurve (OBJSimpleCurve const &scurve) |
void | addFreeFormSpecialPoints (std::vector< int32_t > const &points) |
void | setSmoothingGroup (uint32_t group) |
void | setLevelOfDetail (uint32_t lod) |
void | setBevelInterp (bool on) |
void | setColorInterp (bool on) |
void | setDissolveInterp (bool on) |
void | setMaterial (std::string const &name) |
void | setMaterial (std::string const &name, OBJMaterial const &material) |
void | addMaterialLibrary (std::string const &path) |
void | setTextureMap (std::string const &name) |
void | addTextureMapLibrary (std::string const &path) |
void | setShadowObject (std::string const &name) |
void | setTracingObject (std::string const &name) |
void | setTechniqueParametric (float res) |
void | setTechniqueParametricA (OBJVector2 const &vec) |
void | setTechniqueParametricB (float res) |
void | setTechniqueSpatialCurve (float length) |
void | setTechniqueSpatialSurface (float length) |
void | setTechniqueCurvatureCurve (OBJVector2 const &vec) |
void | setTechniqueCurvatureSurface (OBJVector2 const &vec) |
void | setFreeFormType (OBJFreeFormType type) |
void | setFreeFormRational (bool rational) |
void | setFreeFormDegreeU (int32_t degree) |
void | setFreeFormDegreeV (int32_t degree) |
void | setFreeFormStepU (int32_t step) |
void | setFreeFormStepV (int32_t step) |
void | setFreeFormBasisMatrixU (std::vector< float > const &matrix) |
void | setFreeFormBasisMatrixV (std::vector< float > const &matrix) |
void | setFreeFormMergeGroupNumber (int32_t id) |
void | setFreeFormMergeGroupResolution (float res) |
Protected Member Functions | |
void | resetAuxiliaryStates () |
void | transformVertexGroup (OBJVertexGroup &source) const |
Protected Attributes | |
uint32_t | m_GroupFacesReservedSize |
uint32_t | m_GroupFreeFormReservedSize |
OBJFreeFormState | m_FreeFormState |
bool | m_FreeFormRational |
std::unordered_map < std::string, OBJGroup > | m_GroupMap |
std::unordered_map < std::string, OBJMaterial > | m_MaterialMap |
std::vector< OBJGroup * > | m_ActiveGroups |
std::vector< OBJVector4 > | m_VertexSpatialData |
std::vector< OBJVector2 > | m_VertexTextureData |
std::vector< OBJVector3 > | m_VertexNormalData |
std::vector< std::string > | m_MaterialLibraries |
std::vector< std::string > | m_TextureMapLibraries |
std::vector< OBJRenderState > | m_RenderStates |
OBJ is a state-based file format, and this class represents that state. It keeps track of all groups and their associated data.
After parsing, this data can then be retrieved from the state object.
void OBJState::addActiveGroup | ( | std::string const & | name | ) |
Adds an additional active group. If the group has not been added before, then a new group is created.
[in] | name | Group name. |
void OBJState::addFace | ( | OBJFace | face | ) |
Adds a new face element.
[in] | face | Face to add. |
void OBJState::addFreeFormConnection | ( | OBJSurfaceConnection | connection | ) |
Adds a new OBJSurfaceConnection to the internal OBJFreeFormState.
[in] | connection |
void OBJState::addFreeFormCurve | ( | OBJCurve const & | curve | ) |
Adds a new OBJCurve to the internal OBJFreeFormState.
[in] | curve |
void OBJState::addFreeFormCurve2D | ( | std::vector< int32_t > const & | points | ) |
Adds a new OBJCurve2D to the internal OBJFreeFormState.
[in] | points |
void OBJState::addFreeFormHole | ( | OBJSimpleCurve const & | hole | ) |
Adds hole values to the newest OBJFreeForm in the internal OBJFreeFormState.
[in] | hole |
void OBJState::addFreeFormParameterU | ( | std::vector< float > const & | parameters | ) |
Adds parameter u values to the newest OBJFreeForm in the internal OBJFreeFormState.
[in] | parameters |
void OBJState::addFreeFormParameterV | ( | std::vector< float > const & | parameters | ) |
Adds parameter v values to the newest OBJFreeForm in the internal OBJFreeFormState.
[in] | parameters |
void OBJState::addFreeFormSpecialCurve | ( | OBJSimpleCurve const & | scurve | ) |
Adds scurve values to the newest OBJFreeForm in the internal OBJFreeFormState.
[in] | scurve |
void OBJState::addFreeFormSpecialPoints | ( | std::vector< int32_t > const & | points | ) |
Adds points values to the newest OBJFreeForm in the internal OBJFreeFormState.
[in] | points |
void OBJState::addFreeFormSurface | ( | OBJSurface const & | surface | ) |
Adds a new OBJSurface to the internal OBJFreeFormState.
[in] | surface |
void OBJState::addFreeFormTrim | ( | OBJSimpleCurve const & | trim | ) |
Adds trim values to the newest OBJFreeForm in the internal OBJFreeFormState.
[in] | trim |
void OBJState::addLine | ( | std::vector< OBJVertexGroup > & | line | ) |
Adds a new line element.
[in] | line | Line to add. |
void OBJState::addMaterialLibrary | ( | std::string const & | path | ) |
Adds a new material library to create materials from.
[in] | path | Relative path, including extension, from the current OBJ file. |
void OBJState::addPointCollection | ( | std::vector< OBJVertexGroup > & | points | ) |
Adds a new point element.
[in] | points | Points to add. |
void OBJState::addTextureMapLibrary | ( | std::string const & | path | ) |
Adds a new texture library to create textures from.
[in] | path | Relative path, including extension, from the current OBJ file. |
void OBJState::addVertexNormal | ( | OBJVector3 const & | vector | ) |
Adds a new normal (x, y, z) vertex element.
[in] | vector | Normal vertex to add. |
void OBJState::addVertexParameter | ( | OBJVector3 const & | vector | ) |
Adds a new free-form parameter (u, v, w) vertex element.
[in] | vector | Free-Form parameter vertex to add. |
void OBJState::addVertexSpatial | ( | OBJVector4 const & | vector | ) |
Adds a new spatial (x, y, z, w) vertex element.
[in] | vector | Spatial vertex to add. |
void OBJState::addVertexTexture | ( | OBJVector2 const & | vector | ) |
Adds a new texture (u, v) vertex element.
[in] | vector | Texture vertex to add. |
void OBJState::clearActiveGroups | ( | ) |
Clears all active groups.
void OBJState::clearState | ( | ) |
Resets the state back to a default setting. Typically called automatically prior to starting a new parse.
OBJFreeFormState * OBJState::getFreeFormState | ( | ) |
Returns a pointer to the internal OBJFreeForm state. This state defines all free-form geometries, connections, and most of their attributes.
void OBJState::getGroups | ( | std::vector< OBJGroup const * > & | groups | ) | const |
Fills a vector with pointers to all OBJGroups stored in the state.
If the state is cleared (whether explicitly or upon a new parse action), then all group pointers will become invalidated.
[out] | groups |
std::vector< std::string > const * OBJState::getMaterialLibraries | ( | ) | const |
Returns a pointer to the container of all material libraries (accompanying .mtl files).
std::vector< OBJVector3 > const * OBJState::getNormalData | ( | ) | const |
Returns a pointer to the container of all parsed normal vertex data.
OBJRenderState OBJState::getRenderState | ( | uint32_t | index | ) | const |
Retrieves the specified state of the render attributes.
Each face and free-form has an associated render attributes state detailing extra state settings that were active upon it's creation (such as material, lod, smoothing, etc.).
[in] | index | Render attribute state index. If invalid, will return the default state. |
std::vector< OBJVector4 > const * OBJState::getSpatialData | ( | ) | const |
Returns a pointer to the container of all parsed spatial vertex data.
std::vector< OBJVector2 > const * OBJState::getTextureData | ( | ) | const |
Returns a pointer to the container of all parsed texture coordinate vertex data.
void OBJState::reserve | ( | uint32_t | spatial, |
uint32_t | texture = 0 , |
||
uint32_t | normal = 0 , |
||
uint32_t | groupFaces = 0 , |
||
uint32_t | groupFreeForms = 0 |
||
) |
Allows the ability to specify the amount of space to reserve for the various containers used by the state. If one knows in advance the general size of the parsed objects, then reserving an adequate amount of space in advance may produce performance improvements.
Reserved size can only ever be increased and may not be decreased.
By default, the state will not reserve any space in advance.
[in] | spatial | Number of spatial vertex elements to reserve for. |
[in] | texture | Number of texture vertex elements to reserve for. |
[in] | normal | Number of normals vertex elements to reserve for. |
[in] | groupFaces | Number of faces to reserve in each new group. |
[in] | groupFreeForms | Number of free-forms to reserve in each new group. |
void OBJState::setBevelInterp | ( | bool | on | ) |
Enables/disables bevel interpolation for the current auxiliary state.
[in] | on |
void OBJState::setColorInterp | ( | bool | on | ) |
Enables/disables color interpolation for the current auxiliary state.
[in] | on |
void OBJState::setDissolveInterp | ( | bool | on | ) |
Enables/disables dissolve interpolation for the current auxiliary state.
[in] | on |
void OBJState::setFreeFormBasisMatrixU | ( | std::vector< float > const & | matrix | ) |
Sets an attribute on the current OBJFreeFormAttributeState
[in] | matrix |
void OBJState::setFreeFormBasisMatrixV | ( | std::vector< float > const & | matrix | ) |
Sets an attribute on the current OBJFreeFormAttributeState
[in] | matrix |
void OBJState::setFreeFormDegreeU | ( | int32_t | degree | ) |
Sets an attribute on the current OBJFreeFormAttributeState
[in] | degree |
void OBJState::setFreeFormDegreeV | ( | int32_t | degree | ) |
Sets an attribute on the current OBJFreeFormAttributeState
[in] | degree |
void OBJState::setFreeFormMergeGroupNumber | ( | int32_t | id | ) |
Sets an attribute on the current OBJFreeFormAttributeState
[in] | id |
void OBJState::setFreeFormMergeGroupResolution | ( | float | res | ) |
Sets an attribute on the current OBJFreeFormAttributeState
[in] | res |
void OBJState::setFreeFormRational | ( | bool | rational | ) |
Sets an attribute on the current OBJFreeFormAttributeState
[in] | rational |
void OBJState::setFreeFormStepU | ( | int32_t | step | ) |
Sets an attribute on the current OBJFreeFormAttributeState
[in] | step |
void OBJState::setFreeFormStepV | ( | int32_t | step | ) |
Sets an attribute on the current OBJFreeFormAttributeState
[in] | step |
void OBJState::setFreeFormType | ( | OBJFreeFormType | type | ) |
Sets an attribute on the current OBJFreeFormAttributeState
[in] | type |
void OBJState::setLevelOfDetail | ( | uint32_t | lod | ) |
Sets the level-of-detail for the current auxiliary state.
[in] | lod |
void OBJState::setMaterial | ( | std::string const & | name | ) |
Sets the bound material for the current auxiliary state.
[in] | name |
void OBJState::setMaterial | ( | std::string const & | name, |
OBJMaterial const & | material | ||
) |
Sets the material data for the specified material name.
[in] | name | |
[in] | material |
void OBJState::setShadowObject | ( | std::string const & | name | ) |
Sets the bound shadow object for the current auxiliary state.
[in] | name |
void OBJState::setSmoothingGroup | ( | uint32_t | group | ) |
Sets the smoothing group for the current auxiliary state.
[in] | group |
void OBJState::setTechniqueCurvatureCurve | ( | OBJVector2 const & | vec | ) |
Sets a technique attribute on the current RenderState.
[in] | vec |
void OBJState::setTechniqueCurvatureSurface | ( | OBJVector2 const & | vec | ) |
Sets a technique attribute on the current RenderState.
[in] | vec |
void OBJState::setTechniqueParametric | ( | float | res | ) |
Sets a technique attribute on the current RenderState.
[in] | res |
void OBJState::setTechniqueParametricA | ( | OBJVector2 const & | vec | ) |
Sets a technique attribute on the current RenderState.
[in] | vec |
void OBJState::setTechniqueParametricB | ( | float | res | ) |
Sets a technique attribute on the current RenderState.
[in] | res |
void OBJState::setTechniqueSpatialCurve | ( | float | length | ) |
Sets a technique attribute on the current RenderState.
[in] | length |
void OBJState::setTechniqueSpatialSurface | ( | float | length | ) |
Sets a technique attribute on the current RenderState.
[in] | length |
void OBJState::setTextureMap | ( | std::string const & | name | ) |
Sets the bound texture for the current auxiliary state.
[in] | name |
void OBJState::setTracingObject | ( | std::string const & | name | ) |
Sets the bound tracing object for the current auxiliary state.
[in] | name |