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

Contributors

Languages