A Computer Graphics project.
This project focuses on 3D surface extraction using the Marching Cubes algorithm and Phong shading in OpenGL.
The result is a fully interactive Python application for visualizing scalar fields in 3D.
- ๐บ Marching Cubes implementation from scratch to extract isosurfaces from arbitrary scalar fields.
- ๐ก Lighting & Shading: Realistic rendering using a Phong-like shader with ambient, diffuse, and specular components.
- ๐ 3D Camera Controls: Spherical coordinate camera system with mouse-based orbiting and zoom.
- ๐ฆ Mesh Export: Export generated triangle mesh to
.plyformat for use in 3D tools. - ๐ Normal Calculation: Proper surface normals calculated and normalized per triangle for lighting accuracy.
- ๐ณ Bounding Box & Axes: 3D scene includes bounding volume and coordinate axes for orientation.
src/โ Main source files including OpenGL initialization, rendering logic, marching cubes core, and shaders.requirements.txtโ Python dependencies.output/โ Output.plyfiles (not versioned, but generated here).screenshots/โ Visual results of rendering (see below).
- Python 3.13.1
- pip 25.0.1 or newer
- Required packages listed in
requirements.txt
pip install -r requirements.txt
cd src
python main.py- Mouse Drag: Orbit camera around origin
- Scroll or Arrow Keys: Zoom in/out
- Code Edit: Change the scalar field by modifying the
scalar_field()function inmain.py
- No bounding box fitting is enforced โ surfaces can extend outside the visual cube.
- The app has been tested for marching cube step sizes from
0.2to0.001โ lower values are untested but theoretically supported. - Performance scales non-linearly with lower step sizes due to mesh resolution.
- Surface from
y - sin(x)cos(z)at isovalue 0 - Surface from
xยฒ - yยฒ - zยฒ - zat isovalue -1.5

cos(z).png)
