Reimplementation of Matthias Müller's "Ten Minute Physics" demos in Rust with WASM + WebGL

Overview

Build

ten-minute-physics-rs reimplements Matthias Müller's "Ten Minute Physics" demos in Rust with WASM + WebGL. Compared with the source pure Javascript implementations, many Rust versions run ~3x faster in Chrome on an M1 Max MacBook.

For all demos, please see https://cerrno.github.io/ten-minute-physics-rs/. Most can be interacted with by dragging the camera and/or objects on screen. This project is deployed to Github Pages after building with Github Actions.

Files in the src/ directory are labeled according to the corresponding source demo number. The top level index.{html,ts} files contain boilerplate code for all demos (such as initializing the <canvas> element, stats.js, and lil-gui). Each {demo}.ts file implements the generic interface defined in {lib}.ts, defining scene initialization parameters (THREE.js or canvas), scene setup (generally creating rendering elements, binding GUI elements, etc.), and update/render functions called by the index.ts main loop. Each {demo}.rs file implements a physics simulation in Rust, which is compiled to WASM using wasm-pack and instantiated/called by the corresponding {demo}.ts file to step the simulation.

Memory is shared between the WASM instance and JS via WebAssembly.Memory and Rust helper methods which return pointers to contiguous memory locations. For example, particle positions are stored in Rust as a Vec<Vec3> struct field. A wasm-bindgen getter is defined to return a *const Vec3. glam::Vec3 is repr(C), so each is a linear array of f32s somewhere in the WebAssembly.Memory buffer. For rendering in JS, a THREE.BufferAttribute is defined to reference a Float32Array referencing the WASM memory ArrayBuffer with the pointer (byte offset) returned from the getter and a known length (in this case, num_particles * 3).

Running

# install dependencies
npm install

# compile to WASM, run webpack, and spawn a local server
npm run serve

Then visit http://localhost:8080

License

This project is distributed under the MIT license.

You might also like...
Rust-raytracer - 🔭 A simple ray tracer in Rust 🦀
Rust-raytracer - 🔭 A simple ray tracer in Rust 🦀

rust-raytracer An implementation of a very simple raytracer based on Ray Tracing in One Weekend by Peter Shirley in Rust. I used this project to learn

Rust-and-opengl-lessons - Collection of example code for learning OpenGL in Rust

rust-and-opengl-lessons Project requires Rust 1.31 Collection of example code for learning OpenGL in Rust 00 - Setup 01 - Window 02 - OpenGL Context 0

Simple retro game made using Rust bracket-lib by following "Herbert Wolverson's Hands on Rust" book.

Flappy Dragon Code from This program is a result of a tutorial i followed from Herbert Wolverson's Hands-on Rust Effective Learning through 2D Game De

A Rust wrapper and bindings of Allegro 5 game programming library

RustAllegro A thin Rust wrapper of Allegro 5. Game loop example extern crate allegro; extern crate allegro_font; use allegro::*; use allegro_font::*;

High performance Rust ECS library
High performance Rust ECS library

Legion aims to be a feature rich high performance Entity component system (ECS) library for Rust game projects with minimal boilerplate. Getting Start

A refreshingly simple data-driven game engine built in Rust

What is Bevy? Bevy is a refreshingly simple data-driven game engine built in Rust. It is free and open-source forever! WARNING Bevy is still in the ve

Rust library to create a Good Game Easily

ggez What is this? ggez is a Rust library to create a Good Game Easily. The current version is 0.6.0-rc0. This is a RELEASE CANDIDATE version, which m

RTS game/engine in Rust and WebGPU
RTS game/engine in Rust and WebGPU

What is this? A real time strategy game/engine written with Rust and WebGPU. Eventually it will be able to run in a web browser thanks to WebGPU. This

Rust bindings for GDNative

GDNative bindings for Rust Rust bindings to the Godot game engine. Website | User Guide | API Documentation Stability The bindings cover most of the e

Owner
Lucas V. Schuermann
Please visit my personal homepage at https://lvs.io for more information.
Lucas V. Schuermann
A place to start when building webgl apps in Bevy. Use this to avoid writing the boilerplate.

Template Bevy project with WebGL enabled Prerequisites cargo install cargo-make Build and serve WASM version Set your local ip address in Makefile.to

Michael Dorst 0 Dec 24, 2021
A reimplementation of the minecraft server framework in rust.

FerrumC About FerrumC is a Rust-based reimplementation of the Minecraft server, designed to be fast and efficient, optimized for low memory usage and

Sweattypalms 3 Sep 4, 2023
A reimplementation of the excellent word game Wordle by Josh Wardle.

Paudle A reimplementation of the excellent word game Wordle by Josh Wardle. This version was created using Yew and Rust. I cribbed the colors and layo

Paul Sanford 39 Dec 5, 2022
A rust chess implementation using a neural network scoring function built on huggingface/candle + rust + wasm

Rusty Chess What is it? Rusty Chess aims to be a high quality embeddable chess engine that runs entirely locally in the browser (no backend required).

Gareth 3 Nov 3, 2023
A single-threaded polling-based Rust async executor suitable for use in games, embedded systems or WASM.

simple async local executor An Enlightware® software. Overview A single-threaded polling-based executor suitable for use in games, embedded systems or

Enlightware GmbH 16 Nov 15, 2022
Wasm game of life - A Rust and WebAssembly tutorial implementing the Game of Life

wasm_game_of_life Conway's Game of Life in Rust and WebAssembly Contributing | Chat Built with ?? ?? by The Rust and WebAssembly Working Group About T

Rust and WebAssembly 236 Dec 24, 2022
Cross-platform (including wasm) persistent key value store plugin for rust games/apps

bevy_pkv bevy_pkv is a cross-platform persistent key value store for rust apps. Use it for storing things like settings, save games etc. Currently, it

Johan Klokkhammer Helsing 25 Jan 9, 2023
A cross platform (wasm included) networking library!

bootleg_networking A cross platform (wasm included) networking library! A networking plugin for the Bevy game engine that wraps around bevy_networking

William Batista 51 Jan 1, 2023
An opinionated, monolithic template for Bevy with cross-platform CI/CD, native + WASM launchers, and managed cross-platform deployment.

??️ Bevy Shell - Template An opinionated, monolithic template for Bevy with cross-platform CI/CD, native + WASM launchers, and managed cross-platform

Kurbos 218 Dec 30, 2022
Adds support for wasm/wat assets in Bevy, and enables easier scripting

bevy_wasm_scripting Adds support for wasm/wat assets in Bevy, and enables easy scripting. This is enabled through the wasmer crate. Prepare for public

null 9 Dec 20, 2022