CUGL 3.0
Cornell University Game Library
|
#include <CUObjModel.h>
Public Member Functions | |
ObjModel () | |
~ObjModel () | |
void | dispose () |
bool | initWithInfo (const std::shared_ptr< ModelInfo > &info, Uint32 depth=3) |
const std::string | getName () const |
const std::vector< std::shared_ptr< ObjMesh > > & | getMeshes () const |
std::shared_ptr< ObjModel > | getSubModel (const std::string tag) const |
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< ObjModel > | allocWithInfo (const std::shared_ptr< ModelInfo > &info, Uint32 depth=3) |
This class represents an OBJ model.
An OBJ model is one or more meshes (surfaces) combined with a ModelView matrix specifying its coordinate system. It is possible to have multiple models that share the same meshes but with different ModelView matrices. Such models are clones of each other drawn in different orientations. Indeed, the ModelView matrix is what distinguishes an OBJ instance from an OBJ asset.
OBJ models typically correspond to a single OBJ file. However, it is possible to use groups and object names to extract a portion of an OBJ file as its own object. This is similar to the concept of texture atlases but for 3d models. In particular, this can be used to break up a model into articulated joints for animation. With that said, CUGL does not currently support any sort of bone animation.
All OBJ models are nodes in a 3d scene graph. As such, they can have children. However, there is no parent-child structure in an OBJ file. These relationships must be built manually.
cugl::scene3::ObjModel::ObjModel | ( | ) |
Creates an uninitialized model.
You must initialize this model before use.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate a model on the heap, use one of the static constructors instead.
|
inline |
Deletes this mesh, disposing all resources
|
inlinestatic |
Returns a newly allocated model with the given AST.
This method will build the model recursively. As the AST holds both OBJ and MTL information, the number and type of objects created depends upon the depth parameter
Depth 0: The meshes are created without OpenGL buffers or materials Depth 1: The meshes are created with OpenGL buffers but no materials Depth 2: Materials are created for the meshes, but without textures Depth 3: Textures are created for the materials as necessary
Note that only depth 0 is safe for off the main thread. Therefore, depth 0 is typically used by asset loaders while the latter depths are convenience methods meant to cut down on the number of steps to assemble the model.
info | The AST for this model |
depth | The detail depth of the construction process |
void cugl::scene3::ObjModel::dispose | ( | ) |
Disposes all of the resources used by this model.
A disposed model can be safely reinitialized. Any children owned by this node will be released. They will be deleted if no other object owns them.
It is unsafe to call this on a Node that is still currently inside of a scene graph.
void cugl::scene3::ObjModel::draw | ( | const std::shared_ptr< ObjShader > & | shader | ) |
Draws this model with the provided shader
shader | The shader program to use |
void cugl::scene3::ObjModel::draw | ( | const std::shared_ptr< ObjShader > & | shader, |
const std::shared_ptr< Material > & | material | ||
) |
Draws this model 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 meshes that make up this object.
|
inline |
Returns the name of this model
std::shared_ptr< ObjModel > cugl::scene3::ObjModel::getSubModel | ( | const std::string | tag | ) | const |
Returns a submodel consisting of meshes that match the given tag.
The tag can either be an object name or an group tag. Any mesh that matches either will be added to the new model. The meshes will be added by reference (not copied).
This method works very similar to a graphics::Texture
atlas. It allows you to break up a single OBJ model into several components. All components will share references to the same meshes.
tag | The tag identifying the submodel |
bool cugl::scene3::ObjModel::initWithInfo | ( | const std::shared_ptr< ModelInfo > & | info, |
Uint32 | depth = 3 |
||
) |
Initializes this model with the given AST.
This method will build the model recursively. As the AST holds both OBJ and MTL information, the number and type of objects created depends upon the depth parameter
Depth 0: The meshes are created without OpenGL buffers or materials Depth 1: The meshes are created with OpenGL buffers but no materials Depth 2: Materials are created for the meshes, but without textures Depth 3: Textures are created for the materials as necessary
Note that only depth 0 is safe for off the main thread. Therefore, depth 0 is typically used by asset loaders while the latter depths are convenience methods meant to cut down on the number of steps to assemble the model.
info | The AST for this model |
depth | The detail depth of the construction process |