All Projects → gkaemmer → Rust Wasm Blob

gkaemmer / Rust Wasm Blob

Softbody physics in Rust with WASM

Programming Languages

javascript
184084 projects - #8 most used programming language
rust
11053 projects

Projects that are alternatives of or similar to Rust Wasm Blob

Carton
📦 Watcher, bundler, and test runner for your SwiftWasm apps
Stars: ✭ 171 (+850%)
Mutual labels:  webpack, wasm
Modern Wasm Starter
🛸 Run C++ code on web and create blazingly fast websites! A starter template to easily create WebAssembly packages using type-safe C++ bindings with automatic TypeScript declarations.
Stars: ✭ 140 (+677.78%)
Mutual labels:  webpack, wasm
Rust Loader
Webpack loader for Rust files. DEPRECATED, use WasmPack instead
Stars: ✭ 34 (+88.89%)
Mutual labels:  webpack, wasm
Wasm Loader
✨ WASM webpack loader
Stars: ✭ 604 (+3255.56%)
Mutual labels:  webpack, wasm
Nunjucks Isomorphic Loader
Nunjucks loader for webpack, supporting both javascript templating and generating static HTML files through the HtmlWebpackPlugin.
Stars: ✭ 17 (-5.56%)
Mutual labels:  webpack
Web
React web interface for the OpenDota platform
Stars: ✭ 889 (+4838.89%)
Mutual labels:  webpack
Vuefront Nuxt
Vuefront Nuxt module for building components based on config.
Stars: ✭ 16 (-11.11%)
Mutual labels:  webpack
Awesome Wasm Zh
WebAssembly(wasm)资源精选
Stars: ✭ 838 (+4555.56%)
Mutual labels:  wasm
Wasm2kt
Web Assembly to Kotlin and Java converter. Allows to compile a C or C++ program/library, and generate a Kotlin or Java program/library.
Stars: ✭ 18 (+0%)
Mutual labels:  wasm
Cypress Hmr Restarter
A Cypress plugin which restarts tests on webpack-dev-server HMR updates
Stars: ✭ 18 (+0%)
Mutual labels:  webpack
Initior
A command line application that let's you initialize your new projects the right way, replaces npm and yarn's init 🎆
Stars: ✭ 17 (-5.56%)
Mutual labels:  webpack
Skpm
💎📦 A utility to build and publish Sketch plugins
Stars: ✭ 890 (+4844.44%)
Mutual labels:  webpack
Easy Vue
Learn vueJS Easily 👻
Stars: ✭ 896 (+4877.78%)
Mutual labels:  webpack
Vue2 Study
vue 的webpack配置,按需加载,element-ui,vuex
Stars: ✭ 16 (-11.11%)
Mutual labels:  webpack
Webxr Physics
Adds physics to WebXR
Stars: ✭ 18 (+0%)
Mutual labels:  webpack
Pcaaron.github.io
Web全栈技术笔记:https://pcaaron.github.io/
Stars: ✭ 16 (-11.11%)
Mutual labels:  webpack
Mam.client.js
Masked Authentication Messaging wrapper for Javascript (Browser and Node)
Stars: ✭ 17 (-5.56%)
Mutual labels:  wasm
Great Big Example Application
A full-stack example app built with JHipster, Spring Boot, Kotlin, Angular 4, ngrx, and Webpack
Stars: ✭ 899 (+4894.44%)
Mutual labels:  webpack
Gameboy
🎮 Game Boy emulator written in Rust
Stars: ✭ 17 (-5.56%)
Mutual labels:  wasm
Braid Design System
Themeable design system for the SEEK Group
Stars: ✭ 888 (+4833.33%)
Mutual labels:  webpack

Blob, a softbody physics simulation in Rust + WASM

View Demo Here

Blob is simulated by calls to WASM. The coordinates and velocities of each vertex are shared between Rust and Javascript. Every frame, the physics code is run 40 times, and the positions of each vertex are sampled for rendering.

Rendering is done with a few SVG polygons in React.

The site uses Next.js and doesn't really need to, but it really cuts down boilerplate.

rustLoader.js

SoftBody.js require()s the rust source code directly, and the import is managed by a webpack loader that runs the rust compiler (to the wasm32-unknown-unknown target). It grabs the WASM byte code and creates Javascript glue code automatically.

Sharing data with WASM

For a blob with 50 sides, the shared data is a Float64Array with 250 (50 * 5) numbers in it. In rust, this memory is passed in as a *mut Vertex, and turned into a &mut [Vertex] with slice::from_raw_parts_mut. Then, the init and step functions can edit the data freely.

The javascript must know how that array is structured. To make interaction and rendering easier, the coordinates are copied every frame:

for (let i = 0; i < this.vertexCount; i++) {
  // Vertex is stored as five floats at vertexData[i * 5];
  this.vertices[i].x = this.vertexData[i * 5 + 0];
  this.vertices[i].y = this.vertexData[i * 5 + 1];
}

From there, Javascript can handle the rendering and events, while Rust handles all the number crunching.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].