Skip to content

This project runs a high-speed C++ physics engine inside your web browser using WebAssembly. It lets you spawn 3D shapes and tweak real-world forces like gravity and friction to see how they interact.

Notifications You must be signed in to change notification settings

The-Applicable/physics-engine

Repository files navigation

Physics Engine

A React + Three.js application integrated with a C++ physics engine via WebAssembly.

Prerequisites

  • Node.js (v20 or later recommended)
  • Docker (for building the physics engine) OR Emscripten SDK installed locally

Installation

Install the dependencies:

npm install

Building the Physics Engine

The project uses a C++ physics engine compiled to WebAssembly. You need to compile it before running the app.

Using Docker (Recommended)

Run the following command from the project root:

docker run --rm -v $(pwd):/src emscripten/emsdk emcc src/physics/engine.cpp -o public/wasm/physics.js -lembind -s MODULARIZE=1 -s EXPORT_NAME='createPhysicsModule' -s ALLOW_MEMORY_GROWTH=1 -s ENVIRONMENT=web -O3

Using Local Emscripten

If you have emcc in your path, you can run the build script directly:

cd src/physics
./build.sh
cd ../..

Quick Start with Docker

You can build and run the entire application (including the physics engine compilation) with a single command:

docker build -t physics-engine . && docker run -p 8080:8080 physics-engine

Then open http://localhost:8080 in your browser.

Running the Application

Start the development server:

npm run dev

Open your browser at http://localhost:5173 (or the URL shown in the terminal).

Building for Production

To create a production build:

npm run build

The output will be in the dist directory.

About

This project runs a high-speed C++ physics engine inside your web browser using WebAssembly. It lets you spawn 3D shapes and tweak real-world forces like gravity and friction to see how they interact.

Resources

Stars

Watchers

Forks