Physics Engine for Remotion & Three.js

Giving Digital Animations Real Life & Weight

Bake in natural cloth movement, fabric tears, crunching collisions, and dynamic deformation so web animations look fluid and physical instead of rigid and static.

GitHub Repository
$ git clone git@github.com:Aarav90-cpu/aPhysics.git
๐Ÿงต

Cloth & Soft-Body Movement In Progress / Planned

Phase 2 native cloth is in progress (Steps 2.1โ€“2.3 complete); bending, colliders, and soft-body models remain Planned. See architecture.md.

๐Ÿ’ฅ

Crash & Impact Mechanics Planned

Fracture, structural collapse, and particle deformation so collisions look impactful and lifelike.

โšก

Zero-Copy Three.js Memory Planned

Direct WebAssembly linear memory mapping with Float32Array views. Zero buffer duplication between C and JS.

๐ŸŽฒ

Deterministic Seeds Planned

Deterministic Seeds: pass an explicit 64-bit seed (e.g. 1337ULL) for reproducible physics simulations across workers.

๐Ÿ› ๏ธ

Clang 23 & Bazel 9

Built strictly with Clang 23 and Bazel 9 for reproducible builds and deterministic toolchain sandboxing.

๐Ÿค–

Agent-Native Design

Strict rules in AGENTS.md with full compatibility for crawlers like fetchIt via sitemap.xml.

Engine Architecture

Planned memory sharing and determinism architecture, plus implemented Phase 1 core utilities.

1. Share Memory Directly with Three.js (Zero-Copy) Planned

Traditional bridges copy arrays between Wasm and JavaScript per frame, increasing copy work and Garbage Collection pressure on large meshes.

Zero-Copy WebAssembly & Three.js Pipeline
// 1. In C: Vertex buffer is contiguous in WebAssembly linear memory
// 2. In JavaScript: Wrap raw memory pointer with Float32Array (ZERO copies)
const positions = new Float32Array(
    wasmMemory.buffer,
    wasmInstance.exports.aphysics_get_positions(),
    vertexCount * 3
);

// 3. Bind directly to Three.js BufferAttribute
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));

// 4. On each simulation step in C:
wasmInstance.exports.aphysics_step(dt);
geometry.attributes.position.needsUpdate = true; // WebGL streams directly to GPU VBO!

2. Deterministic Simulation via Seeds Planned

Remotion renders video frames concurrently across worker threads or cloud rendering containers. To keep simulation results consistent between machine A and machine B:

  • Fixed Seed (seed = 1337ULL): Designed so the internal PRNG produces repeatable perturbation values, folding angles, and tear thresholds per run.
  • Pure C Engine: The simulation core never queries system clocks or entropy. Callers or the JavaScript wrapper provide explicit seeds.
  • Decoupled Fixed Delta Time (Δt): The solver advances on fixed intervals (e.g. 1/60s), avoiding frame-rate-dependent step divergence.
Call for Volunteers

Looking for macOS Testers!

Help us test and expand aPhysics support on Apple Silicon and macOS Intel machines.

Linux (x86_64): Fully supported and verified in CI.
macOS (arm64 & x86_64): Experimental & Untested on physical hardware.

Why We Need Your Help

aPhysics is configured to compile with Clang 23 and Bazel 9 on macOS, but we need hardware testing to verify:

  • Apple Silicon (M1/M2/M3/M4) compilation and floating-point determinism under Clang 23.
  • macOS Command Line Tools and Xcode toolchain compatibility.
  • Clean execution of bazel test //... on Darwin kernels.

How You Can Test on macOS

Terminal Commands for macOS Testers
# 1. Install Bazelisk
brew install bazelisk

# 2. Clone repository
git clone git@github.com:Aarav90-cpu/aPhysics.git
cd aPhysics

# 3. Build all targets
bazel build //...

# 4. Run tests
bazel test //...

# 5. Run executable
bazel run //tools:aphysics_info

Report any compiler warnings, build failures, or test results by opening an issue on GitHub:

Submit macOS Test Report

Agent Skills & Tooling

Autonomous AI guidelines and crawler compatibility.

Autonomous Agent Rules in AGENTS.md

This repository enforces strict operational guidelines for AI coding agents to guarantee code quality, reproducibility, and safety:

  • Understand & Plan First: Agents must read code and present a detailed plan before making edits.
  • Strict Tooling: Clang 23 only, Bazel 9 only. No GCC, no Makefiles.
  • Mandatory Verification: Every change must be verified via Bazel build and tests, reporting exact commands and output.
  • License Headers: Source files require Apache 2.0 headers applied through addlicense.

Compatibility with fetchIt

The repository and website are specifically formatted to be indexed and downloaded cleanly by fetchIt, the documentation crawler and markdown exporter built by Aarav:

  • The root sitemap.xml contains the directive comment <!-- For FetchIt --> immediately below the XML declaration.
  • Semantic markdown structure allows fetchIt to strip noise and download complete, self-contained documentation sets.

Documentation Reader

Read repository documentation directly in this browser window.

About the Creator

Meet the developer behind aPhysics, ARK OS, and fetchIt.

AK

Aarav (Arphd4)

he/him Maharashtra, India (GMT+05:30) Aarav90-cpu

"I build things because I can't help it: tools I wish existed, an operating system I probably have no business attempting, and songs that start as a half-formed idea at 2 a.m. Movies and music are a huge part of my life, and the rest is split between two obsessions: where AI is heading, and how interfaces should feel when it gets there."

Core Stack

Swift (home base for system-level programming), Kotlin (Android / Jetpack Compose UI experiments), C / C++, Python, and TypeScript.

Key Projects

ARK OS Linux kernel OS powered by Swift (libark, sash)
fetchIt Fast site-to-markdown documentation crawler (PyPI & AUR)
MusicSkills AI music composition tool with Python mido & DAW
Expressive-Glass UI experiment blending Apple Liquid Glass with Google Material 3 Expressive

Music & YouTube Channel

Aarav produces songs around tech, AI, and humanity. Check out tracks like BEYOND THE CODE, HUMAN BEHIND THE MACHINE, and One Bar of Wi-Fi: