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 mesh class WFObjMesh is defined for loading OBJ and MTL files. It's used by another new class WFObj object for loading vertex data and texture data to the vertex and fragment shaders. Note that a texture is not mandatory.
System class diagram
WFObj derives from BaseGeometry class. It overrides mesh with an instance of WFObjMesh to generate geometry and material color information.
MaterialInfo
This class contains information about a single Material obtained after parsing a mtl file. This information includes range of vertices, Ambient, Diffuse, Specular Colors and Texture information etc. Note that a mtl file can have multiple Materials applicable to a range of vertices.
These are stored in WFObjMesh object discussed below.
Members
| Name | Description |
|---|---|
| ambientclr | Contains ambient color |
| diffuseclr | Contains material information. It contains name of the material, mapped to the MatrialInfo structure. |
| diffusetxtfilename | Contains material file name associated with the obj file |
| emissiveclr | Contains normals |
| range | Contains texture info |
| shininess | Contains vertex info |
| specularclr | Contains Specular color |
WFObjMesh
WFObjMesh derives from IGeometryMesh 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.
| Name | Description |
|---|---|
| faces | Contains vertex/texture coordinate/Normal information for each of the vertices of the geometry triangle. |
| matinfomap | Contains material information. It contains name of the material, mapped to the MatrialInfo structure. |
| mtlfilename | Contains material file name associated with the obj file |
| normals | Contains normals |
| texturemap | Contains texture info |
| vertices | Contains vertex info |
Constructor
Parses obj and mtl files to generate geometry and color information.
Methods
| Name | Description |
|---|---|
| GenerateVerticesData | This method generates vertex data for the GPU to render the geometrical shape. This method is called if the data is sent in non indexed mode. It generates position and vertex data. |
| normals_count | This method returns number of normals. |
| texture_count | This method returns number of texture coordinates. |
| vertex_count | This method returns number of vertices. |
| readfile | This method reads obj file and mtl file and stores contents in text member |
| parsegeometrydata | This method generates geometry data from the obj file |
| parsematerialdata | This method generates material data from the mtl file |
Light
This class contains light properties such as ambient Coefficient, light position, and light color.
These are stored in WFObjInfo object discussed below.
Members
| Name | Description |
|---|---|
| ambientCoefficient | Contains ambient Coefficient. This is multiplied with ambient color of the material. |
| Position | Contains light position. Used in lighting calculations. |
| Color | Contains light color. Used in lighting calculations. |
WFOBJInfo
This class contains information about Geometry information and Material color information obtained after parsing .obj and .mtl file.
These are stored in WFObj object discussed below.
Constructors
Creates a fully populated WFOBJInfo from the input parameters.
Members
| Name | Description |
|---|---|
| objfilename | Contains name of the obj file |
| mtlfilename | Contains name of the mtl file |
| viewerpos | Contains texture info if a diffuse texture is available. |
| light | Contains an instance of Light object describing properties of the lighting. |
| texturemap | Contains texture info |
| vertices | Contains vertex info |
WFObj
WFObj derives from BaseGeometry class. It renders objects after parsing obj and mtl files.
| Name | Description |
|---|---|
| Init | This method overrides the base class Init method to loads the WFOBJInfo object. It parses obj and mtl files to generate geometric and material information. Generates the vertices data and material data consisting of surface normals in non indexed mode and later sets them up in VBO buffer. It also sets up initializes texutl to load texture if available. |
| UpdateUniforms | This method overrides the base class UpdateUniforms method. First it updates "cameraposition" uniform. It updates "tex" uniform to pass texture object. Also Light and Material properties are passed to the shaders. |
| vertexShaderSource | This method overrides the base class vertexShaderSource method. It returns the vertex shader code to render the geometric object. |
| fragmentShaderSource | This method overrides the base class fragmentShaderSource method. It returns the fragment shader code to render the geometric object. |
| UpdateUniformsLightMat | This method is called by UpdateUniforms() to update light and material properties to the shader. |
Output
No comments:
Post a Comment