![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUObjParser.h>
Public Member Functions | |
ObjParser () | |
~ObjParser () | |
void | dispose () |
std::shared_ptr< ModelInfo > | parseObj (const std::string source, bool recurse) |
std::shared_ptr< ModelInfo > | parseJson (const std::shared_ptr< JsonValue > &json) |
std::shared_ptr< ModelInfo > | parseObj (const std::string key, const std::string source, bool recurse) |
std::shared_ptr< ModelInfo > | getObj (const std::string key) const |
std::shared_ptr< MaterialLib > | parseMtl (const std::string source) |
std::shared_ptr< MaterialLib > | parseMtl (const std::string key, const std::string source) |
std::shared_ptr< MaterialLib > | getMtl (const std::string key) const |
void | clear () |
Public Attributes | |
bool | debug |
std::unordered_map< std::string, std::shared_ptr< TextureInfo > > | textures |
std::unordered_map< std::string, std::shared_ptr< MaterialLib > > | materials |
std::unordered_map< std::string, std::shared_ptr< ModelInfo > > | models |
This class generates an AST for an OBJ file (and its associated MTL files).
This parse only provides limited support for OBJ and MTL files. We only support polygonal objects, with no freeform drawing. We also only support basic illumination (illum values 0-2) with bump mapping.
This class does not actually produce render data, as that is potentially time consuming. That step should be left up to an asset loader. Instead, this parser simply collates the information about the OBJ model into a single AST, as its data can potentially be spread over multiple files (including MTL and texture files).
Because OBJ data is spread over mutliple files, this parser is stateful. That means it can expand the current ModelInfo
data by reading other files.
|
inline |
Creates a new OBJ parser.
This is a fairly lightweight object. Therefore it is safe to use this constructor with new (though std::make_shared is prefered).
|
inline |
Deletes this OBJ parser, disposing all resource.
void cugl::scene3::ObjParser::clear | ( | ) |
|
inline |
Releases the data from all previously parsed files.
This method has the same affect as clear
.
std::shared_ptr< MaterialLib > cugl::scene3::ObjParser::getMtl | ( | const std::string | key | ) | const |
Returns the information for a previously parsed MTL file.
This method returns nullptr if the MTL file has not been yet parsed. For models that have been parsed, the retrieval key was specified at the time of parsing.
key | The retrieval key |
std::shared_ptr< ModelInfo > cugl::scene3::ObjParser::getObj | ( | const std::string | key | ) | const |
Returns the information for a previously parsed OBJ file.
This method returns nullptr if the OBJ file has not been yet parsed. For models that have been parsed, the retrieval key was specified at the time of parsing.
key | The retrieval key |
std::shared_ptr< ModelInfo > cugl::scene3::ObjParser::parseJson | ( | const std::shared_ptr< JsonValue > & | json | ) |
Returns the information for the given OBJ model.
This method allows you to specify the location of the OBJ file, its MTL file, and any associated textures as a single JSON entry. An OBJ Json entry has the following values
"file": The path to the OBJ file "mtls": An object of key:value pairs defining MTL libraries
The "mtls" entry is optional. For each MTL library, the key should match the name of the MTL file referenced in the obj file. If there are any missing MTL libraries (or the "mtls" entry is missing entirely), then the loader will attempt to use the same directory as the OBJ file.
An MTL entry is either a string (which is a reference to the path to the MTL file) or a JSON object. Such a JSON object would have the following values:
"file": The path to the MTL file "textures": An object of key:value pairs defining textures
The "textures" entry is optional. For each texture, the key should match the name of the texture in the MTL file. Any missing textures will attempt to be loaded if the parsing depth is correct.
The values for the texture entries should be strings or JSONs. If they are string, they should be either be a key referencing a previously loaded texture, or a path to the texture file (the loader interprets it as a path only if there is no key with that name). If it is a JSON, then the JSON should follow the same rules as graphics::Texture
.
json | The JSON value specifying the OBJ model |
std::shared_ptr< MaterialLib > cugl::scene3::ObjParser::parseMtl | ( | const std::string | key, |
const std::string | source | ||
) |
Returns the information for the given MTL file.
This method blocks until the MTL file is read. However, it does not read any imported files (like the Texture files). Instead, it assigns the TextureInfo
attributes according the settings in the MTL file.
This method does not link a MaterialInfo
to a ModelInfo
object. That is the responsibility of the user.
This is a stateful parser. Once a MTL file has been parsed, its data can be retreived at any time with getMtl
. This method uses the specified key for retrieval.
key | The retrieval key |
source | The path to the MTL file |
|
inline |
Returns the information for the given MTL file.
This method blocks until the MTL file is read. However, it does not read any imported files (like the Texture files). Instead, it assigns the TextureInfo
attributes according the settings in the MTL file.
This method does not link a MaterialInfo
to a ModelInfo
object. That is the responsibility of the user.
This is a stateful parser. Once a MTL file has been parsed, its data can be retreived at any time with getMtl
. This method uses the path to the MTL file as the key.
source | The path to the MTL file |
std::shared_ptr< ModelInfo > cugl::scene3::ObjParser::parseObj | ( | const std::string | key, |
const std::string | source, | ||
bool | recurse | ||
) |
Returns the information for the given OBJ file.
This method blocks until the OBJ file is read. If recurse is true, it will also read any imported MTL files (assuming that they are in the same directory as the OBJ files). If recurse ifs false, it will create entries in the ModelInfo
object for the imported libraries with no values. The user can add the information for these libraries later.
This is a stateful parser. Once an OBJ file has been parsed, its data can be retreived at any time with getObj
. This method uses the specified key for retrieval.
key | The retrieval key |
source | The path to the OBJ file |
recurse | Whether to load any files referenced by source |
|
inline |
Returns the information for the given OBJ file.
This method blocks until the OBJ file is read. If recurse is true, it will also read any imported MTL files (assuming that they are in the same directory as the OBJ files). If recurse ifs false, it will create entries in the ModelInfo
object for the imported libraries with no values. The user can add the information for these libraries later.
This is a stateful parser. Once an OBJ file has been parsed, its data can be retreived at any time with getObj
. This method uses the path to the OBJ file as the key.
source | The path to the OBJ file |
recurse | Whether to load any files referenced by source |
bool cugl::scene3::ObjParser::debug |
Whether to emit debugging information
std::unordered_map<std::string,std::shared_ptr<MaterialLib> > cugl::scene3::ObjParser::materials |
The information for previously parsed MTL files
std::unordered_map<std::string,std::shared_ptr<ModelInfo> > cugl::scene3::ObjParser::models |
The information for previously parsed OBJ files
std::unordered_map<std::string,std::shared_ptr<TextureInfo> > cugl::scene3::ObjParser::textures |
The information for the referenced textures