Monday, August 1, 2022

Implementation: Importing WaveFront OBJ Models

Overview 
As discussed before, WaveFront OBJ and MTL files needs to be parsed to get geometry, Material information. A new mesh class and new geometry object are required for this.

Details
A new utility class  GenericObjParser is defined for loading OBJ and MTL files and generating VertexData, Material and texture information. A model can consists of 1 or more Mesh. Each mesh is associated with 1 material which in turn is associated with 0 or 1 texture. Each MeshInfo object represents a mesh which contains Vertex Data consisting of vertices.

System  class diagram
The GenericParser is an abstract class. There are derived two derived classes WFObjParser and AssetImpParser to implement parsing functionality.

A new mesh class  GenericObjMesh is defined for loading vertexdata, Material and texture data. It's used by another new class  GenericObj object for loading vertex data to vertex shader and texture data to the vertex and fragment shaders. Note that a texture is not mandatory. A GenericObj  is created for each MeshInfo object generated by the GenericParser derivative.

MeshInfo
MeshInfo is a utility class that holds vertex data of the various meshes defined by the OBJ file.

GenericParser
GenericParser the base class for parser classes that parses OBJ file and MTL files to provide geometry  and material color information for rendering. It supplies vertices, texture coordinates, normals, Ambient, Diffuse, Specular Colors and Texture information.

WFObjParser 
WFObjParser derives from GenericParser class. It parses OBJ file and MTL files to provide geometry  and material color information for rendering. It supplies vertices, texture coordinates, normals, Ambient, Diffuse, Specular Colors and Texture information.

AssetImpParser
AssetImpParser derives from GenericParser class. It parses OBJ file and MTL files to provide geometry  and material color information for rendering. It supplies vertices, texture coordinates, normals, Ambient, Diffuse, Specular Colors and Texture information. Internally it uses AssetImport library.

GenericObjMesh
This class derives from IGeometryMesh class. It contains information about Geometry information and Material color information obtained after parsing .obj and .mtl file.
GenericObj
GenericObj derives from BaseGeometry class. It renders objects after parsing obj and mtl files.

Output

The Source Code can be accessed from MeshInfo, GenericParserWFObjParser ,AssetImpParserGenericObjMeshGenericObj

No comments:

Post a Comment