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

#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< ObjModelgetSubModel (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< ObjModelallocWithInfo (const std::shared_ptr< ModelInfo > &info, Uint32 depth=3)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ObjModel()

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.

◆ ~ObjModel()

cugl::scene3::ObjModel::~ObjModel ( )
inline

Deletes this mesh, disposing all resources

Member Function Documentation

◆ allocWithInfo()

static std::shared_ptr< ObjModel > cugl::scene3::ObjModel::allocWithInfo ( const std::shared_ptr< ModelInfo > &  info,
Uint32  depth = 3 
)
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.

Parameters
infoThe AST for this model
depthThe detail depth of the construction process
Returns
a newly allocated model with the given AST.

◆ dispose()

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.

◆ draw() [1/2]

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

Draws this model with the provided shader

Parameters
shaderThe shader program to use

◆ draw() [2/2]

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

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

◆ getMeshes()

const std::vector< std::shared_ptr< ObjMesh > > & cugl::scene3::ObjModel::getMeshes ( ) const
inline

Returns the meshes that make up this object.

Returns
the meshes that make up this object.

◆ getName()

const std::string cugl::scene3::ObjModel::getName ( ) const
inline

Returns the name of this model

Returns
the name of this model

◆ getSubModel()

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.

Parameters
tagThe tag identifying the submodel
Returns
a submodel consisting of meshes that match the given tag.

◆ initWithInfo()

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.

Parameters
infoThe AST for this model
depthThe detail depth of the construction process
Returns
true if initialization was successful.

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