Skip to content

alyashour/Marching-Cube-Renderer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸงŠ OpenGL Marching Cubes

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.

Demo


Key Features

  • ๐Ÿ”บ 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 .ply format 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.

๐Ÿ“ Structure

  • src/ โ€“ Main source files including OpenGL initialization, rendering logic, marching cubes core, and shaders.
  • requirements.txt โ€“ Python dependencies.
  • output/ โ€“ Output .ply files (not versioned, but generated here).
  • screenshots/ โ€“ Visual results of rendering (see below).

Running the App

Requirements

  • Python 3.13.1
  • pip 25.0.1 or newer
  • Required packages listed in requirements.txt

๐Ÿ”ง Setup & Run

pip install -r requirements.txt
cd src
python main.py

Controls

  • 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 in main.py

Notes

  • 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.2 to 0.001 โ€“ lower values are untested but theoretically supported.
  • Performance scales non-linearly with lower step sizes due to mesh resolution.

๐Ÿ“ธ Sample Outputs

  1. Surface from y - sin(x)cos(z) at isovalue 0
  2. Surface from xยฒ - yยฒ - zยฒ - z at isovalue -1.5

Surface 1 Surface 2

About

3D scalar field visualization using OpenGL and marching cubes

Topics

Resources

Stars

Watchers

Forks

Languages