3 projects from CS313 (Computer Graphics) that I took Spring '23, including a tree modeler, a particle system and a 3D mesh viewer. These projects were all done in C++ using variants of the OpenGL library.
Generating 3D Trees from Freehand Sketches
3D tree generation has been a hot topic in computer graphics for some time now. Early tools to create and render trees were parameter-based. Shapes of common trees were encoded within templates, upon which users would further modify by specifying branch number, variation, splits, curves, etc. Contemporary techniques take as input images of trees, removes the background and uses a voxel simulation to recreate the tree in 3D. Our approach is somewhere in between, and is similar to Okabe and Igarashi’s freehand sketch approach, which generates 3D geometry based on a sketch of a tree.
There are two components to my project: [1] A sketchpad that keeps track of users' brushstrokes [2] A 3D mesh viewer that processes and displays the brushtrokes. Both the sketching interface and the mesh viewer were written in C++ using the tinyGL and agl libraries respectively (both simplified versions of OpenGL).
The sketching interface stores the user’s brushstrokes (shown in green) by keeping track of the xy coordinates of the vertices (shown as dots). The first stroke is registered as the “trunk” and subsequent strokes automatically clip to existing strokes (parents). If the user draws a strokes that is not touching any existing branch, the sketchpad will clip that stroke to the nearest branch.
The strokes can now be displayed in 3D space, but only as a “pancake” 2D tree. So the mesh viewer need to interpolate depth. With the exception of the trunk, all strokes are now randomly assigned a z direction towards which they will extend. Lastly, we have to reattach the branch to their parent branch. So we look up the root position for each branch based on their parent stroke and parent vertex, and subtract the distance delta. See a video demo below:
Particle system: Cellular Automata
A cellular automaton (CA) is a collection of cells such that each cell changes state as a function of time, according to a defined set of rules driven by the states of neighboring cells. This project uses the agl library to simulate cellular automata that can cannabilize and grow (similar to agar.io). See a video demo below.
Here are the rules used:
- When particles hit the border of the screen, they will go the other way.
- When two particles are fairly close to one another, the bigger particle will "pull" the smaller particle in.
- When two particles are very close to one another, the bigger particle will absorb the smaller particle and gain size proportional to the smaller particle's size.
- When there is only one particle remaining, that particle will burst into smaller particles.
Mesh Viewer
This project is a mesh viewer coded from scratch that reads in PLY files and renders 3D models using C++ and the agl library.
I also included some features such as texturing, the Phong shader, as well as mesh composition. See the github repo here.
Top Left: textured and shaded cow model, Bottom and Right: composed meshes