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)
