Overview
As discussed in the previous article, we saw how geometric objects can be imported from obj and mtl files. Also, the implementation of the GenericObjMesh, GenericObj and GenericParser were covered.
In this post we will try to render a model from "dolphin.obj" and "dolphin.mtl" files.
Details
The purpose of Lesson09 is to demonstrate importing an obj and mtl files to extract geometry and material information.
System class diagram
The scene class overrides camera with an instance of ThreeDCamera.
Implementation
Scene
The functionality is implemented in the Scene class derived from BaseScene class. It creates an instance of AssetImpParser which parses the OBJ file and generates 1 more MeshInfo objects, MaterialInfo objects, TextureInfo Objects.
Each MeshInfo is associated with a MaterialInfo and 0 or 1 TextureInfo Object along with Vertex data. Each MeshInfo is represented by an instance of GenericObj instance which later becomes
The Init method calls
- BaseScene::Init to create hosting window and OpenGL Context.
- It creates an input dialog to import obj, and mtl files and input texture files.
- It calls init function with an instance of GenericObj object. Internally it creates a GenericObj Mesh object to load geometry and material information from the object files and to populate VBO/EBO buffers and bind them. Also create texture if necessary
- It also compiles and links shader programs.
The DrawScene method draws a string and image.
The message handler for IDOK is called when Apply button is pressed after updates are made in the input dialog. It refreshes the display.
The message handler for IDCANCEL is called when in Cancel button is pressed the input dialog. It calls
OnCloseWindow to destroy window.
Finally the WM_CLOSE event is handled in OnCloseWindow function and the window is destroyed and application is shutdown when the window is closed or Escape key is pressed.
Application
Scene class is hosted main.cpp. which creates the scene object and displays it. Message pump is added to process windows messages.
Input dialog
The input dialog as shown below can be used to change settings and understand drawing text and images.Output
The output looks as shown in the top.
No comments:
Post a Comment