Skip to content

Repository files navigation

ysim

A macOS physics simulation engine for cloth dynamics and rigid bodies with GPU-accelerated collision detection.

Demo

ysim cloth simulation demo
Scene #1 — cloth draping in real time, driven by the GPU sim.

Highlights

  • Dual-GPU strategy — OpenGL for rendering, Metal compute for simulation.
  • GPU collision pipeline — broad phase (LBVH / Morton codes) → narrow phase (point–triangle) → constraint response, all on Metal.
  • Cloth modelsTriangularCloth and FastGridCloth, plus Rigid bodies, each with its own parameter set and sim path.
  • Backend-parameterized core — types are templated on backend (CPU / CUDA / METAL): MeshState<BE,PR>, Scene<BE,PR>, VectorBase<BE,PR>.
  • Built-in profilingFrameProfiler tracks named timing sections with CSV export to profiles/.

Build

cmake -B build
cmake --build build
./build/ysim          # runnable from any cwd (paths resolve via exe dir + project root)

Requires: CMake 3.10+, C++17, Eigen 5.0+, GLFW 3.4, GLEW, OpenGL, Metal (macOS), Xcode CLI tools (for xcrun metal shader compilation).

Metal shaders build as part of the CMake run: .metal.air (per file via xcrun metal -c) → default.metallib (via xcrun metallib).

Architecture

  • src/main.cpp — simulation setup, main loop, and GUI (ImGui, OpenGL backend).
  • src/metal/ — compute shaders carrying the bulk of the sim:
    • physics.metal — spring forces, cloth grid physics.
    • bvh.metal — BVH build, Morton codes, broad-phase collision.
    • bruteforce.metal — point–triangle narrow-phase collision.
    • spatialhashing.metal / mlspatialhashing.metal — spatial-hash broad-phase variants.
  • arch-test/, arch-test-handmade/ — greenfield re-architecture experiments (virtual-interface and C++20-concepts designs); the live engine in src/ is untouched by them.

Layout

src/        engine + Metal shaders
assets/     meshes (Human.obj, teapot.obj, …)
scenes/     scene definitions
profiles/   profiler CSV output
docs/       design notes

About

my simulation enigne (26.03-)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages