CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cugl::scene3::ObjMesh Class Reference

#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< MaterialgetMaterial () 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< ObjMeshallocWithInfo (const std::shared_ptr< ModelInfo > &root, const std::shared_ptr< GroupInfo > &info, bool buffer=true)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ObjMesh()

cugl::scene3::ObjMesh::ObjMesh ( )
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.

◆ ~ObjMesh()

cugl::scene3::ObjMesh::~ObjMesh ( )
inline

Deletes this mesh, disposing all resources

Member Function Documentation

◆ allocWithInfo()

static std::shared_ptr< ObjMesh > cugl::scene3::ObjMesh::allocWithInfo ( const std::shared_ptr< ModelInfo > &  root,
const std::shared_ptr< GroupInfo > &  info,
bool  buffer = true 
)
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).

Parameters
rootThe AST root
infoThe AST for this particular mesh
bufferWhether to construct the OpenGL buffer
Returns
a newly allocated mesh with the given AST.

◆ createBuffer()

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.

Returns
true if an OpenGL buffer was successfully built for this mesh.

◆ dispose()

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.

◆ draw() [1/2]

void cugl::scene3::ObjMesh::draw ( const std::shared_ptr< ObjShader > &  shader)

Draws this mesh with the provided shader

Parameters
shaderThe shader program to use

◆ draw() [2/2]

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).

Parameters
shaderThe shader program to use
materialThe material to use as a default

◆ getIndex()

GLuint cugl::scene3::ObjMesh::getIndex ( ) const
inline

Returns the smoothing index for this mesh.

As per the OBJ specification, this value is 0 by default.

Returns
the smoothing index for this mesh.

◆ getMaterial()

std::shared_ptr< Material > cugl::scene3::ObjMesh::getMaterial ( ) const
inline

Returns the material associated with this mesh.

If the mesh has no material, it will drawn using a default white color.

Returns
the material associated with this mesh.

◆ getMaterialName()

std::string cugl::scene3::ObjMesh::getMaterialName ( ) const
inline

Returns the name of the material associated with this mesh.

If the mesh has no material, this will return the empty string.

Returns
the name of the material associated with this mesh.

◆ getMesh()

const graphics::Mesh< OBJVertex > & cugl::scene3::ObjMesh::getMesh ( ) const
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.

Returns
the CUGL mesh for storing the drawing data

◆ getObject() [1/2]

std::string cugl::scene3::ObjMesh::getObject ( ) const
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.

Returns
the object that this mesh is associated with.

◆ getObject() [2/2]

void cugl::scene3::ObjMesh::getObject ( const std::string  value)
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.

Parameters
valueThe object that this mesh is associated with.

◆ getTags() [1/2]

std::unordered_set< std::string > & cugl::scene3::ObjMesh::getTags ( )
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.

Returns
the group tags associated with this mesh.

◆ getTags() [2/2]

const std::unordered_set< std::string > & cugl::scene3::ObjMesh::getTags ( ) const
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.

Returns
the group tags associated with this mesh.

◆ hasTag()

bool cugl::scene3::ObjMesh::hasTag ( const std::string  tag)

Returns true if this mesh has the given tag.

Parameters
tagThe tag to query
Returns
true if this mesh has the given tag.

◆ initWithInfo()

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).

Parameters
rootThe AST root
infoThe AST for this particular mesh
bufferWhether to construct the OpenGL buffer
Returns
true if initialization was successful.

◆ setIndex()

void cugl::scene3::ObjMesh::setIndex ( GLuint  value)
inline

Sets the smoothing index for this mesh.

As per the OBJ specification, this value is 0 by default.

Parameters
valueThe smoothing index for this mesh.

◆ setMaterial()

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.

Parameters
materialThe material associated with this mesh.

◆ setMaterialName()

void cugl::scene3::ObjMesh::setMaterialName ( const std::string  name)
inline

Sets the name of the material associated with this mesh.

If the mesh has no material, this will return the empty string.

Parameters
nameThe name of the material associated with this mesh.

The documentation for this class was generated from the following file: