Ocular Engine
Ocular::Graphics::MeshResourceLoader_PLY Class Reference

#include <MeshResourceLoader_PLY.hpp>

Inheritance diagram for Ocular::Graphics::MeshResourceLoader_PLY:
Ocular::Graphics::MeshResourceLoader Ocular::Core::AResourceLoader

Protected Member Functions

virtual bool readFile (Core::File const &file, std::vector< Graphics::Vertex > &vertices, std::vector< uint32_t > &indices, uint32_t &numVertices, uint32_t &numIndices, Math::Vector3f &min, Math::Vector3f &max) override
 
bool parseHeader (std::ifstream &stream)
 
bool parseElement (std::ifstream &stream, std::string &line, PLYParser **parser)
 
bool parseElementNameAndCount (std::string const &line, PLYParser *parser) const
 
bool parseProperty (std::string const &line, PLYElementParser *parser) const
 
bool parsePropertyList (std::string const &line, PLYElementListParser *parser) const
 
bool parseBody (std::ifstream &stream, std::vector< Graphics::Vertex > &vertices, std::vector< uint32_t > &indices, uint32_t &numVertices, uint32_t &numIndices, Math::Vector3f &min, Math::Vector3f &max)
 
bool isValidPLYFile (std::ifstream &stream) const
 
bool isComment (std::string const &line) const
 
bool isElement (std::string const &line) const
 
bool isElementList (std::string const &line) const
 
bool isFormatASCII (std::string const &line) const
 
PLYPropertyType toPropertyType (std::string const &str) const
 
PLYElementType toElementType (std::string const &str) const
 
void reserveVectorSpace (std::vector< Graphics::Vertex > &vertices, std::vector< uint32_t > &indices) const
 
- Protected Member Functions inherited from Ocular::Graphics::MeshResourceLoader
virtual bool createResource (Core::Resource *&resource, Core::File const &file, std::vector< Graphics::Vertex > const &vertices, std::vector< uint32_t > const &indices, uint32_t numVertices, uint32_t numIndices, Math::Vector3f const &min, Math::Vector3f const &max)
 
- Protected Member Functions inherited from Ocular::Core::AResourceLoader
bool isFileValid (Core::File const &file) const
 

Additional Inherited Members

- Public Member Functions inherited from Ocular::Graphics::MeshResourceLoader
 MeshResourceLoader (std::string const &extension)
 
virtual bool loadResource (Core::Resource *&resource, Core::File const &file, std::string const &mappingName) override
 
- Public Member Functions inherited from Ocular::Core::AResourceLoader
 AResourceLoader (std::string const &extension, ResourceType type)
 
virtual std::string getSupportedFileType () const
 
virtual bool loadSubResource (Resource *&resource, File const &file, std::string const &mappingName)
 
virtual bool exploreResource (File const &file)
 
ResourceType getResourceType () const
 
- Protected Attributes inherited from Ocular::Core::AResourceLoader
std::string m_SupportedExtension
 
ResourceType m_Type
 

Detailed Description

Implementation of AResourceLoader that handles the loading of files with the '.ply' extension as meshes.

Member Function Documentation

bool Ocular::Graphics::MeshResourceLoader_PLY::parseHeader ( std::ifstream &  stream)
protected

Header is split into the following pieces:

- Identifier
- Element definition
- End of header

In addition to this, any line of the file (including the header), may be a comment. A comment is any line that begins with 'comment'. Example:

comment This line is a comment

The identifier informs us that this is a PLY file and what type of PLY file. A file is marked as a PLY by having it's very first line be equal to 'ply'. The next line will then tell which of the following kinds of PLY files it is:

ASCII
Binary (little endian)
Binary (big endian)

So an identifier will look like:

ply
format ascii 1.0

or

ply
format binary_little_endian 1.0

etc.

The rest of the header is dedicated to defining the elements that make up the body of the PLY header. This can occur in one of two different ways. Either an element definition followed by a variable number of property definitions, or an element definition followed by a single property list.

The element definition also tells us what kind of element it is, and how many individual elements there are. Example:

element vertex 8
property float x
property float y
property float z
element face 6
property list uchar int vertex_index

The above tells us there will be 8 vertex elements, each defined as (x, y, z). It will then be followed by 6 face elements, defined as a variable number of integer indices.

Finally, the end of the header is marked by 'end_header'. All together, a header may resemble:

ply
format ascii 1.0
example A sample header
element vertex 8
property float x
property float y
property float z
element face 6
property list uchar int vertex_index
end_header

It should be noted there are no limits to the number of elements or their properties. There is also no standard set of element types. But the following are generally accepted:

vertex
face
edge

Of which, we currently support vertex and face. Any unsupported or unknown element types will simply be skipped over while parsing the body.

See below for more information: http://paulbourke.net/dataformats/ply/

bool Ocular::Graphics::MeshResourceLoader_PLY::readFile ( Core::File const &  file,
std::vector< Graphics::Vertex > &  vertices,
std::vector< uint32_t > &  indices,
uint32_t &  numVertices,
uint32_t &  numIndices,
Math::Vector3f min,
Math::Vector3f max 
)
overrideprotectedvirtual

Each MeshResourceLoader must provide a custom implementation for it's specific file type.

Parameters
[in]fileSource file to read from.
[out]verticesTexture pixel data read in from the file.
[out]indicesWidth of the texture.
[out]numVerticesNumber of vertices in the mesh (depending on the loader implementation, this may not equal vertices.size())
[out]numIndicesNumber of indices in the mesh (depending on the loader implementation, this may not equal indices.size())
[out]minThe minimum spatial point along the local axis among all vertices
[out]maxThe maximum spatial point along the local axis among all vertices
Returns
TRUE if file was read in successfully.

Implements Ocular::Graphics::MeshResourceLoader.


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