![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUObjModel.h>
Public Member Functions | |
ObjMesh () | |
~ObjMesh () | |
void | dispose () |
bool | initWithInfo (const std::shared_ptr< ModelInfo > &root, const std::shared_ptr< GroupInfo > &info, bool buffer=true) |
bool | createBuffer () |
GLuint | getIndex () const |
void | setIndex (GLuint value) |
std::string | getObject () const |
void | getObject (const std::string value) |
std::unordered_set< std::string > & | getTags () |
const std::unordered_set< std::string > & | getTags () const |
bool | hasTag (const std::string tag) |
const graphics::Mesh< OBJVertex > & | getMesh () const |
std::string | getMaterialName () const |
void | setMaterialName (const std::string name) |
std::shared_ptr< Material > | getMaterial () const |
void | setMaterial (const std::shared_ptr< Material > &material) |
void | draw (const std::shared_ptr< ObjShader > &shader) |
void | draw (const std::shared_ptr< ObjShader > &shader, const std::shared_ptr< Material > &material) |
Static Public Member Functions | |
static std::shared_ptr< ObjMesh > | allocWithInfo (const std::shared_ptr< ModelInfo > &root, const std::shared_ptr< GroupInfo > &info, bool buffer=true) |
This class represents a single mesh or surface in an OBJ file.
A OBJ surface is a single unit of rendering. A new mesh is created any time an OBJ file issues face commands after declaring a new object, group, or material. Meshes doe not have their own ModelView matrix. That is stored in the ObjModel
that groups them together.
We currently only support fully specified polygonal meshes. We do not support any freeform drawing commands, even though those are included in the OBJ specification.
|
inline |
Creates an uninitialized mesh.
You must initialize this mesh before use.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate a mesh on the heap, use one of the static constructors instead.
|
inline |
Deletes this mesh, disposing all resources
|
inlinestatic |
Returns a newly allocated mesh with the given AST.
This method will build the vertices and mesh information for the mesh. However, it will only create the OpenGL buffer if the parameter buffer is true. This allows us to create meshes off of the main thread (and allocate the buffer once back on the main thread).
root | The AST root |
info | The AST for this particular mesh |
buffer | Whether to construct the OpenGL buffer |
bool cugl::scene3::ObjMesh::createBuffer | ( | ) |
Returns true if an OpenGL buffer was successfully built for this mesh.
If the mesh is already built this method will return true. Otherwise, it will attempt to build the mesh and return true on success. This method should only be called on the main thread. It exists to support asset loading off the main thread.
void cugl::scene3::ObjMesh::dispose | ( | ) |
Disposes all of the resources used by this mesh.
A disposed mesh can be safely reinitialized. It is unsafe to call this method on a mesh that is still inside of an active ObjModel
.
void cugl::scene3::ObjMesh::draw | ( | const std::shared_ptr< ObjShader > & | shader | ) |
Draws this mesh with the provided shader
shader | The shader program to use |
void cugl::scene3::ObjMesh::draw | ( | const std::shared_ptr< ObjShader > & | shader, |
const std::shared_ptr< Material > & | material | ||
) |
Draws this mesh with the provided shader and material.
The material will only be used on meshes that do not already have a material assigned (e.g. it works as a default material).
shader | The shader program to use |
material | The material to use as a default |
|
inline |
Returns the smoothing index for this mesh.
As per the OBJ specification, this value is 0 by default.
|
inline |
Returns the material associated with this mesh.
If the mesh has no material, it will drawn using a default white color.
|
inline |
Returns the name of the material associated with this mesh.
If the mesh has no material, this will return the empty string.
|
inline |
Returns the CUGL mesh for storing the drawing data
CUGL meshes store the geometry but are independent of any OpenGL buffer. This method is read-only, as it is unsafe to modify the mesh without updating the associated OpenGL buffer.
|
inline |
Returns the object that this mesh is associated with.
Objects are defined with the o command in OBJ files. This value is the empty string by default.
|
inline |
Sets the object that this mesh is associated with.
Objects are defined with the o command in OBJ files. This value is the empty string by default.
value | The object that this mesh is associated with. |
|
inline |
Returns the group tags associated with this mesh.
This tag set is returned by reference. That means modifying this set will modify the associated tags.
|
inline |
Returns the group tags associated with this mesh.
This tag set is returned by reference. This version of the method prevents the tag set from being modified, so that it can safely be used in read-only settings.
bool cugl::scene3::ObjMesh::hasTag | ( | const std::string | tag | ) |
Returns true if this mesh has the given tag.
tag | The tag to query |
bool cugl::scene3::ObjMesh::initWithInfo | ( | const std::shared_ptr< ModelInfo > & | root, |
const std::shared_ptr< GroupInfo > & | info, | ||
bool | buffer = true |
||
) |
Initializes this mesh with the given AST.
This method will build the vertices and mesh information for the mesh. However, it will only create the OpenGL buffer if the parameter buffer is true. This allows us to create meshes off of the main thread (and allocate the buffer once back on the main thread).
root | The AST root |
info | The AST for this particular mesh |
buffer | Whether to construct the OpenGL buffer |
|
inline |
Sets the smoothing index for this mesh.
As per the OBJ specification, this value is 0 by default.
value | The smoothing index for this mesh. |
void cugl::scene3::ObjMesh::setMaterial | ( | const std::shared_ptr< Material > & | material | ) |
Sets the material associated with this mesh.
If the mesh has no material, it will drawn using a default white color.
material | The material associated with this mesh. |
|
inline |
Sets the name of the material associated with this mesh.
If the mesh has no material, this will return the empty string.
name | The name of the material associated with this mesh. |