ten-minute-physics-rs

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

https://github.com/lucas-schuermann/ten-minute-physics-rs

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.4%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

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

Basic Info
Statistics
  • Stars: 145
  • Watchers: 3
  • Forks: 6
  • Open Issues: 0
  • Releases: 0
Created over 3 years ago · Last pushed over 2 years ago
Metadata Files
Readme License Citation

README.md

Build Netlify Status

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://ten-minute-physics-rs.netlify.app. Most can be interacted with by dragging the camera and/or objects on screen. This project is deployed to Netlify (since Github Pages does not support setting HTTP headers) after building with Github Actions.

Running

```bash

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.

Notes

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).

Owner

  • Name: Lucas V. Schuermann
  • Login: lucas-schuermann
  • Kind: user

Please visit my personal homepage at https://lvs.io for more information.

Citation (CITATION.cff)

cff-version: 1.2.0
title: "ten-minute-physics-rs"
message: "If you use this software, please cite it as below."
type: software
authors:
  - given-names: "Lucas V."
    family-names: "Schuermann"
    email: lucas@lvs.io
repository-code: "https://github.com/lucas-schuermann/ten-minute-physics-rs"
license: MIT
date-released: 2022-12-26

GitHub Events

Total
  • Watch event: 9
Last Year
  • Watch event: 9

Dependencies

.github/workflows/main.yml actions
  • JamesIves/github-pages-deploy-action v4.4.1 composite
  • actions-rs/toolchain v1 composite
  • actions/checkout v3 composite
  • jetli/wasm-pack-action v0.4.0 composite
Cargo.lock cargo
  • approx 0.4.0
  • autocfg 1.1.0
  • bumpalo 3.12.0
  • cfg-if 1.0.0
  • cgmath 0.18.0
  • getrandom 0.2.8
  • glam 0.22.0
  • js-sys 0.3.61
  • libc 0.2.139
  • log 0.4.17
  • num-traits 0.2.15
  • once_cell 1.17.0
  • ppv-lite86 0.2.17
  • proc-macro2 1.0.51
  • quote 1.0.23
  • rand 0.8.5
  • rand_chacha 0.3.1
  • rand_core 0.6.4
  • syn 1.0.107
  • unicode-ident 1.0.6
  • wasi 0.11.0+wasi-snapshot-preview1
  • wasm-bindgen 0.2.84
  • wasm-bindgen-backend 0.2.84
  • wasm-bindgen-macro 0.2.84
  • wasm-bindgen-macro-support 0.2.84
  • wasm-bindgen-shared 0.2.84
  • web-sys 0.3.61
package-lock.json npm
  • 347 dependencies
package.json npm
  • @types/stats.js ^0.17.0 development
  • @types/three ^0.149.0 development
  • @wasm-tool/wasm-pack-plugin 1.6.0 development
  • html-webpack-plugin ^5.5.0 development
  • text-encoding ^0.7.0 development
  • ts-loader ^9.4.2 development
  • typescript ^4.9.5 development
  • wasm-pack ^0.10.3 development
  • webpack ^5.75.0 development
  • webpack-cli ^5.0.1 development
  • webpack-dev-server ^4.11.1 development
  • lil-gui ^0.18.0
  • stats.js ^0.17.0
  • three ^0.149.0
Cargo.toml cargo