|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
A collection of Mesh objects loaded from an OBJ file. More...
#include <model.hpp>
Public Member Functions | |
| Model ()=default | |
| Default constructor. | |
| ~Model ()=default | |
| Destructor — calls cleanup on all meshes. | |
| Model (const std::string &filename) | |
| Load an OBJ file synchronously. | |
| Model (const Model &m)=delete | |
| Model & | operator= (const Model &m)=delete |
| Model (Model &&m) noexcept | |
| Move constructor. | |
| Model & | operator= (Model &&m) noexcept |
| Move-assign operator. | |
| void | dumpMeshStats (const Mesh &m, size_t meshIndex, bool didCompress, bool compressRequested) |
| Print mesh statistics to a stream. | |
| bool | openCompressedModel (const std::string &filename) |
| Load a pre-compressed binary model format. | |
| bool | openModelString (const std::string &filename, const std::string &text, bool compress=true) |
| Parse an OBJ model from an in-memory string. | |
| bool | openModel (const std::string &filename, bool compress=true) |
| Load an OBJ file from disk. | |
| void | drawArrays () |
| Draw all meshes using stored bindings. | |
| void | drawArraysWithTexture (GLuint texture, const std::string texture_name) |
| Draw all meshes with a texture override. | |
| void | drawArraysWithCubemap (GLuint cubemap, const std::string texture_name) |
| Draw all meshes with a cubemap. | |
| void | printData (std::ostream &out) |
| Print per-mesh vertex/index statistics. | |
| void | setShaderProgram (gl::ShaderProgram *shader_program, const std::string texture_name="texture1") |
| Assign a shader program to be used for all draw calls. | |
| void | setTextures (const std::vector< GLuint > &textures) |
| Assign a pre-loaded list of GL texture IDs to meshes in order. | |
| void | setTextures (gl::GLWindow *win, const std::string &filename, std::string prefix) |
| Load and assign textures from a directory using a file prefix. | |
| void | setTexturesFromMTL (gl::GLWindow *win, const std::string &objDir="") |
| Load textures using map_Kd paths from parsed MTL materials. | |
| const std::vector< MXMaterial > & | materials () const |
| const std::string & | mtlLibPath () const |
| void | saveOriginal () |
| Take a snapshot of all mesh geometries. | |
| void | resetToOriginal () |
| Restore all meshes from the last saveOriginal() snapshot. | |
| void | updateBuffers () |
| Push all mesh geometry changes to the GPU. | |
| void | recalculateNormals () |
| Recompute normals for all meshes. | |
| void | scale (float factor) |
| Uniformly scale all meshes. | |
| void | scale (float sx, float sy, float sz) |
| Non-uniformly scale all meshes. | |
| void | bend (DeformAxis axis, float angle, float center=0.0f, float range=1.0f) |
| Bend all meshes. | |
| void | twist (DeformAxis axis, float angle, float center=0.0f) |
| Twist all meshes. | |
| void | wave (DeformAxis axis, float amplitude, float frequency, float phase=0.0f) |
| Wave-deform all meshes. | |
| void | ripple (float amplitude, float frequency, float phase=0.0f, float cx=0.0f, float cy=0.0f, float cz=0.0f) |
| Ripple-deform all meshes. | |
| void | noise (float amplitude, unsigned int seed=12345) |
| Add noise to all meshes. | |
| void | taper (DeformAxis axis, float factor, float center=0.0f) |
| Taper all meshes. | |
| void | bulge (float factor, float cx=0.0f, float cy=0.0f, float cz=0.0f, float radius=1.0f) |
| Bulge all meshes. | |
| void | morph (float t) |
| Morph all meshes. | |
| void | translate (float tx, float ty, float tz) |
| Translate all meshes. | |
| void | rotate (DeformAxis axis, float angle) |
| Rotate all meshes. | |
| void | setNormalMap (GLuint normalMapTexture) |
| Set the normal map for all meshes. | |
| void | setParallaxMap (GLuint heightMapTexture) |
| Set the parallax map for all meshes. | |
| void | setDisplacementMap (GLuint displacementMapTexture) |
| Set the displacement map for all meshes. | |
| void | setAmbientOcclusionMap (GLuint aoMapTexture) |
| Set the ambient-occlusion map for all meshes. | |
| void | generateTangentBitangent () |
| Generate tangent/bitangent for all meshes. | |
| void | uvScroll (float uOffset, float vOffset) |
| Scroll UVs for all meshes. | |
| void | uvScale (float uScale, float vScale) |
| Scale UVs for all meshes. | |
| void | uvRotate (float angle) |
| Rotate UVs for all meshes. | |
| void | applyChromaticAberration (float intensity) |
| Apply chromatic aberration to all meshes. | |
| void | applyColorGrading (const glm::vec3 &colorShift) |
| Apply colour grading to all meshes. | |
| void | applyHSV (float hueShift, float saturation, float value) |
| Apply HSV adjustment to all meshes. | |
| void | setCubemapBlending (GLuint cubemap1, GLuint cubemap2, float blendFactor) |
| Set cubemap blending for all meshes. | |
Public Attributes | |
| std::vector< Mesh > | meshes |
| All sub-meshes in load order. | |
Private Member Functions | |
| void | parseLine (const std::string &line, Mesh ¤tMesh, int &type, size_t &count) |
| Parse a single MXMOD line and accumulate into currentMesh. | |
| bool | openOBJ (const std::string &filename, bool compress) |
| Load a Wavefront OBJ file into meshes. | |
| void | loadMTL (const std::string &path) |
| Parse a Wavefront .mtl file and populate materials_. | |
Private Attributes | |
| gl::ShaderProgram * | program = nullptr |
| Active shader program. | |
| std::string | tex_name |
| Sampler uniform name. | |
| std::vector< MXMaterial > | materials_ |
| Parsed MTL materials. | |
| std::string | mtlLibPath_ |
| Path to .mtl file from OBJ mtllib. | |
A collection of Mesh objects loaded from an OBJ file.
Model is the top-level scene node. It opens an OBJ file (optionally with index compression), provides shader and texture bindings, and proxies every deformation and map operation to all contained meshes.
|
default |
Default constructor.
Referenced by Model(), Model(), operator=(), and operator=().
|
default |
Destructor — calls cleanup on all meshes.
| mx::Model::Model | ( | const std::string & | filename | ) |
Load an OBJ file synchronously.
| filename | Path to the .obj file. |
Definition at line 592 of file model.cpp.
References openModel().
|
delete |
References Model().
|
noexcept |
| void mx::Model::applyChromaticAberration | ( | float | intensity | ) |
| void mx::Model::applyColorGrading | ( | const glm::vec3 & | colorShift | ) |
| void mx::Model::applyHSV | ( | float | hueShift, |
| float | saturation, | ||
| float | value ) |
| void mx::Model::bend | ( | DeformAxis | axis, |
| float | angle, | ||
| float | center = 0.0f, | ||
| float | range = 1.0f ) |
| void mx::Model::bulge | ( | float | factor, |
| float | cx = 0.0f, | ||
| float | cy = 0.0f, | ||
| float | cz = 0.0f, | ||
| float | radius = 1.0f ) |
| void mx::Model::drawArrays | ( | ) |
| void mx::Model::drawArraysWithCubemap | ( | GLuint | cubemap, |
| const std::string | texture_name ) |
| void mx::Model::drawArraysWithTexture | ( | GLuint | texture, |
| const std::string | texture_name ) |
| void mx::Model::dumpMeshStats | ( | const Mesh & | m, |
| size_t | meshIndex, | ||
| bool | didCompress, | ||
| bool | compressRequested ) |
Print mesh statistics to a stream.
| m | Mesh to inspect. |
| meshIndex | Zero-based mesh number. |
| didCompress | Whether compression was performed. |
| compressRequested | Whether compression was requested. |
Definition at line 656 of file model.cpp.
References mx::Mesh::bitangent, mx::Mesh::indices, mx::Mesh::norm, mx::system_out, mx::Mesh::tangent, mx::Mesh::tex, and mx::Mesh::vert.
Referenced by openModelString(), and openOBJ().
| void mx::Model::generateTangentBitangent | ( | ) |
|
private |
Parse a Wavefront .mtl file and populate materials_.
Definition at line 1228 of file model.cpp.
References mx::MXMaterial::d, mx::MXMaterial::illum, mx::MXMaterial::ka, mx::MXMaterial::kd, mx::MXMaterial::ks, mx::MXMaterial::map_kd, materials_, mx::MXMaterial::name, mx::MXMaterial::ns, and mx::system_out.
Referenced by openOBJ().
|
inline |
Definition at line 431 of file model.hpp.
References materials_.
| void mx::Model::morph | ( | float | t | ) |
Morph all meshes.
|
inline |
Definition at line 433 of file model.hpp.
References mtlLibPath_.
| void mx::Model::noise | ( | float | amplitude, |
| unsigned int | seed = 12345 ) |
Add noise to all meshes.
| bool mx::Model::openCompressedModel | ( | const std::string & | filename | ) |
Load a pre-compressed binary model format.
| filename | Path to the compressed model file. |
true on success. | bool mx::Model::openModel | ( | const std::string & | filename, |
| bool | compress = true ) |
Load an OBJ file from disk.
| filename | Path to the .obj file. |
| compress | Apply index compression if true. |
true on success. Definition at line 615 of file model.cpp.
References mx::decompressString(), mx::ends_with(), meshes, openModelString(), openOBJ(), mx::readFile(), and mx::Exception::text().
Referenced by Model().
| bool mx::Model::openModelString | ( | const std::string & | filename, |
| const std::string & | text, | ||
| bool | compress = true ) |
Parse an OBJ model from an in-memory string.
| filename | Path (used only for error messages). |
| text | OBJ content as a string. |
| compress | Apply index compression if true. |
true on success. Definition at line 669 of file model.cpp.
References mx::Mesh::bitangent, mx::Mesh::compressIndices(), dumpMeshStats(), mx::Mesh::generateBuffers(), mx::Mesh::generateTangentBitangent(), mx::Mesh::indices, meshes, mx::Mesh::norm, parseLine(), mx::Mesh::recalculateNormals(), mx::Mesh::setShapeType(), mx::system_out, mx::Mesh::tangent, mx::Mesh::tex, mx::Mesh::texture, and mx::Mesh::vert.
Referenced by openModel().
|
private |
Load a Wavefront OBJ file into meshes.
Definition at line 934 of file model.cpp.
References mx::Mesh::bitangent, mx::Mesh::compressIndices(), dumpMeshStats(), mx::Mesh::generateBuffers(), mx::Mesh::generateTangentBitangent(), mx::Mesh::indices, loadMTL(), mx::Mesh::materialName, materials_, meshes, mtlLibPath_, mx::Mesh::norm, mx::Mesh::recalculateNormals(), mx::Mesh::setShapeType(), mx::system_out, mx::Mesh::tangent, mx::Mesh::tex, mx::Mesh::texture, and mx::Mesh::vert.
Referenced by openModel().
|
private |
Parse a single MXMOD line and accumulate into currentMesh.
Definition at line 795 of file model.cpp.
References mx::Mesh::bitangent, mx::Mesh::indices, mx::Mesh::norm, mx::Mesh::normIndex, mx::Mesh::tangent, mx::Mesh::tex, mx::Mesh::texIndex, mx::Mesh::vert, and mx::Mesh::vertIndex.
Referenced by openModelString().
| void mx::Model::printData | ( | std::ostream & | out | ) |
Print per-mesh vertex/index statistics.
| out | Output stream. |
| void mx::Model::recalculateNormals | ( | ) |
| void mx::Model::resetToOriginal | ( | ) |
Restore all meshes from the last saveOriginal() snapshot.
Definition at line 1317 of file model.cpp.
References meshes.
| void mx::Model::ripple | ( | float | amplitude, |
| float | frequency, | ||
| float | phase = 0.0f, | ||
| float | cx = 0.0f, | ||
| float | cy = 0.0f, | ||
| float | cz = 0.0f ) |
Ripple-deform all meshes.
Definition at line 1327 of file model.cpp.
References meshes.
| void mx::Model::rotate | ( | DeformAxis | axis, |
| float | angle ) |
Rotate all meshes.
| void mx::Model::saveOriginal | ( | ) |
| void mx::Model::scale | ( | float | factor | ) |
| void mx::Model::scale | ( | float | sx, |
| float | sy, | ||
| float | sz ) |
| void mx::Model::setAmbientOcclusionMap | ( | GLuint | aoMapTexture | ) |
Set cubemap blending for all meshes.
| void mx::Model::setDisplacementMap | ( | GLuint | displacementMapTexture | ) |
| void mx::Model::setNormalMap | ( | GLuint | normalMapTexture | ) |
| void mx::Model::setParallaxMap | ( | GLuint | heightMapTexture | ) |
| void mx::Model::setShaderProgram | ( | gl::ShaderProgram * | shader_program, |
| const std::string | texture_name = "texture1" ) |
| void mx::Model::setTextures | ( | const std::vector< GLuint > & | textures | ) |
Assign a pre-loaded list of GL texture IDs to meshes in order.
| textures | Vector of GL texture IDs. |
Definition at line 1119 of file model.cpp.
References meshes.
Referenced by setTextures(), and setTexturesFromMTL().
| void mx::Model::setTextures | ( | gl::GLWindow * | win, |
| const std::string & | filename, | ||
| std::string | prefix ) |
Load and assign textures from a directory using a file prefix.
| win | Owner window (for asset path). |
| filename | Base filename. |
| prefix | Directory prefix. |
Definition at line 1128 of file model.cpp.
References gl::loadTexture(), setTextures(), mx::system_err, mx::system_out, and mx::Exception::text().
| void mx::Model::setTexturesFromMTL | ( | gl::GLWindow * | win, |
| const std::string & | objDir = "" ) |
Load textures using map_Kd paths from parsed MTL materials.
| win | Owner window. |
| objDir | Directory containing the OBJ (for resolving texture paths), or empty to use mtl dir. |
Definition at line 1269 of file model.cpp.
References gl::loadTexture(), materials_, mtlLibPath_, setTextures(), mx::system_err, and mx::system_out.
| void mx::Model::taper | ( | DeformAxis | axis, |
| float | factor, | ||
| float | center = 0.0f ) |
Taper all meshes.
| void mx::Model::translate | ( | float | tx, |
| float | ty, | ||
| float | tz ) |
| void mx::Model::twist | ( | DeformAxis | axis, |
| float | angle, | ||
| float | center = 0.0f ) |
| void mx::Model::updateBuffers | ( | ) |
| void mx::Model::uvRotate | ( | float | angle | ) |
Rotate UVs for all meshes.
| void mx::Model::uvScale | ( | float | uScale, |
| float | vScale ) |
Scale UVs for all meshes.
| void mx::Model::uvScroll | ( | float | uOffset, |
| float | vOffset ) |
| void mx::Model::wave | ( | DeformAxis | axis, |
| float | amplitude, | ||
| float | frequency, | ||
| float | phase = 0.0f ) |
Wave-deform all meshes.
Definition at line 1326 of file model.cpp.
References meshes.
|
private |
Parsed MTL materials.
Definition at line 503 of file model.hpp.
Referenced by loadMTL(), materials(), openOBJ(), and setTexturesFromMTL().
| std::vector<Mesh> mx::Model::meshes |
All sub-meshes in load order.
Definition at line 327 of file model.hpp.
Referenced by applyChromaticAberration(), applyColorGrading(), applyHSV(), bend(), bulge(), drawArrays(), drawArraysWithCubemap(), drawArraysWithTexture(), generateTangentBitangent(), Model(), openModel(), openModelString(), openOBJ(), operator=(), recalculateNormals(), resetToOriginal(), ripple(), saveOriginal(), scale(), scale(), setAmbientOcclusionMap(), setDisplacementMap(), setNormalMap(), setParallaxMap(), setTextures(), translate(), twist(), updateBuffers(), uvScroll(), and wave().
|
private |
Path to .mtl file from OBJ mtllib.
Definition at line 504 of file model.hpp.
Referenced by mtlLibPath(), openOBJ(), and setTexturesFromMTL().
|
private |
Active shader program.
Definition at line 501 of file model.hpp.
Referenced by drawArrays(), drawArraysWithCubemap(), drawArraysWithTexture(), Model(), operator=(), and setShaderProgram().
|
private |
Sampler uniform name.
Definition at line 502 of file model.hpp.
Referenced by drawArrays(), Model(), operator=(), and setShaderProgram().