Skip to content

Graphics Project: Loop subdivision on a 3D mesh (OBJ) using the WingedEdge data structure.

Notifications You must be signed in to change notification settings

madhawav/Loop-Subdivision

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OBJ Viewer with Loop Subdivision

The project is for the Computational Geometry/Computer Graphics graduate course. This is a 3D mesh viewer with support for parsing and serializing OBJ meshes. Implements loop subdivision using the Winged Edge data structure. Implements proper vertex normal / face normal calculation to support smooth/flat shading modes.

preview

How to compile and run the code?

Preferred compiler is GNU C++ compiler. Tested with GNU C++ compiler on Linux and Visual C++ compiler on Windows.

  • For Linux users
    1. Run git submodule update --init --recursive.
    2. Compile and run the code as follows.
      mkdir build
      cd build
      cmake ../
      make
      ./subd
  • For Windows users
    1. Run git submodule update --init --recursive.
    2. Compile and run the code as follows.
      mkdir build
      cd build
      # In the next command, specify the version string according to your visual studio version. Win64 is necessary for nanogui.
      cmake -G "Visual Studio 15 2017 Win64" .. 
      cmake --build . --config Debug
      Debug\subd.exe
      Note: If you encouter render issues, copy the StandardShading.fragmentshader file and the StandardShading.vertexshader file to the target directory.

Notes on Implementation of Subdivision

  1. To perform subdivision, choose level of subdivision using the Subdivision count slider and click "Loop".
  2. To perform only tessellation used by Loop Subdivision (no vertex or edge rule applied), select appropriate subdivision count from slider and click "Tessellate". Switch to wireframe view to view the tessellation.
  3. Click "Reset" to reload the original mesh.
  4. Loop subdivision is implemented in Subdivision/loopsubd.cpp file.

Notes on implementation of OBJ View

  1. Whenever a mesh is loaded, it is automatically converted to a WingedEdge mesh. Upon saving, its converted back to an OBJ mesh.
  2. Rotation, zooming and translation was implemented using mouse controls and Model View Projection matrices. The model matrix is always identity. The view matrix changes as the user orbits / moves around an object. The projection matrix is an Orthogonal Projection, which changes its width and height based on zoom level.
  3. The camera is design to orbit around a target position, based on the rotation vector. The target position can be changed relative to the current view of camera by clicking and dragging the scene.
  4. In the example on Wireframe shading provided in assignment, back-sides are culled off. Thus, backsides are culled off in rendering.
  5. The WingedEdge structure is implemented in the directory WingedEdge. It uses classes Vertex, Edge and Face. The class WEMesh uses aforementioned classes to hold a mesh. It also implements following methods.
    • The method ComputeSmoothShadingMatrices of WEMesh is used to populate position, normall and indices matrices for smooth shading. Vertex normals are calculated as the average of adjacent face's normals.
    • The method ComputeFlatShadingMatrices of WEMesh is used to populate position, normall and indices matrices for flat shading. New vertices are introduces such that unique normals can be defined for triangle faces.
    • The method populateExpandedVertexMatrix of WEMesh is used to populate expandedPositions used to render wireframe on top of shaded mesh.
    • The method loadModel of WEMesh is used to develop a WingedEdge mesh using two matrices positions and indices retrieved from an obj file.
    • The method fillOBJMesh of WEMesh is used to fill a OBJMesh structure which can then be parsed as an OBJ file and save to disk.
  6. The OBJ parser is implemented by WingedEdge/OBJMesh class. It has methods parseFile and saveFile to load and save OBJ files.
  7. For rendering WireFrame on top of shaded mesh, the mesh is expanded by 0.01 or maximum distance between two vertices divided by 100 units, whichever is smallest.
  8. Upon loading a new mesh, projection matrix is re-calculated to have left, bottom, top and right bounds be maximum distance between two vertices divided by zoom. Far plane is set to be 2 * maximum distance between two vertices + 400.

About

Graphics Project: Loop subdivision on a 3D mesh (OBJ) using the WingedEdge data structure.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published