百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
B

box3d-unity

> 编程语言
开源

适用于 Unity 的 Box3d 物理绑定

185 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

适用于 Unity 的 Box3d 物理绑定

Box3D for Unity

Unity bindings for Box3D — the 3D physics engine by Erin Catto, author of Box2D. The full native C API (~580 functions) is exposed through a Unity-friendly C# layer: no pointers in user code, no per-frame allocations, deterministic simulation, and excellent multithreaded performance.

▶ Try the live WebGL demo

This project was inspired by, and owes its architecture to, two projects:

  • Box3D by Erin Catto — the engine itself. This package is only a thin, faithful wrapper around it; all the hard physics work is his.
  • JoltPhysicsUnity inspired the way this wrapper is implemented. Its binding-generation pipeline and packaging decisions shaped mine (what I deliberately did differently, is covered in the docs).

Status: early (0.8.x). Box3D itself is a young engine (v0.1) with no API stability guarantees yet, and this wrapper tracks it. It is usable and well-tested, but expect breaking changes on engine updates.

Features

  • World & bodies — static/kinematic/dynamic bodies, full body API (velocities, forces, mass, damping, per-axis motion locks, bullets/CCD, gravity scale).
  • Shapes — sphere, capsule, convex hull (with cylinder/cone/rock/point-cloud builders), triangle mesh, height field (buildable straight from a Unity Terrain, painted holes included), compound. Clear, documented geometry lifetime rules. Concave objects: triangle meshes for static geometry, compounds of convex parts for dynamic bodies (details).
  • Joints — all nine box3d joints: distance, motor, filter, parallel, prismatic, revolute, spherical (cone/twist limits), weld, wheel (suspension + steering + drive) — each with its full spring/limit/motor accessor surface.
  • Events — polled contact begin/end/hit, sensor enter/exit, joint force-threshold and body-move events, delivered as zero-copy spans (the compiler enforces the transient-memory rule).
  • Queries — closest-hit and all-hits ray casts, shape casts, AABB/shape overlaps, all allocation-free via caller-provided buffers.
  • Dynamic tree — box3d's broadphase AABB tree as a standalone spatial index for your own (non-physics) data: a fast "what's near here?" over thousands of moving objects — AI perception, interest management, trigger volumes, culling — without spinning up colliders.
  • Character mover — box3d's kinematic capsule toolkit (collide → solve planes → clip velocity) with a ready-made sample controller.
  • Callbacks — custom collision filtering, pre-solve contact veto, friction/restitution mixing (with clear worker-thread safety rules).
  • Diagnostics — debug-draw overlay (shapes, contacts, forces, islands) toggled right on the Box3DWorld component; a drop-in stats HUD (step time, per-phase profile, live counts); World.GetProfile() / GetCounters() for programmatic profiling; and a Collision Debugger window answering "why isn't this pair colliding?" rule by rule.
  • Determinism & replay — record a simulation, verify it reproduces bit-identical state (even across worker counts), save it, and scrub the replay frame by frame with divergence detection — either as wireframes or played back on your real scene objects. For lockstep/rollback netcode and bug repro. No other Unity physics wrapper ships this.
  • Water — GPU particle water: a position-based fluid simulated in compute shaders that fills pools, pours from waterfalls, flows around your Box3D shapes (terrain included) and carries floating bodies back — rendered as a URP screen-space liquid surface with refraction, foam and spray. Plus a cheap analytic buoyancy volume (Archimedes floating, waves, splash events) for pool-style game water (guide).
  • Extras — explosions, wind (it grips the water surface too), impact-dent deformable meshes, conveyor surface materials, and a Scene-view physics simulation tool for settling props in edit mode.
  • Multithreading — box3d's internal scheduler, configurable worker count per world.
  • Component layer (experimental) — author bodies and shapes in the Inspector, mirroring Unity's Rigidbody/Collider model (see the docs).

Performance

Measured against Unity's built-in PhysX with identical seeded scenes (editor, same machine, box3d running 4 sub-steps vs PhysX defaults — details and CSVs in the docs):

Scene PhysX Box3D (16 workers)
10,000 spheres raining 6.70 ms 1.84 ms ~3.6× faster
Destroyed city, ~10,000 bodies (buildings + props) 10.94 ms 7.67 ms ~1.4× faster
64 piles, 1,024 bodies (sleep off) 1.15 ms 0.54 ms ~2.1× faster
Joint-grid cloth, 930 joints 0.54 ms 0.71 ms PhysX ahead on single-island loads

The city scene is a mixed real-world load — a town of running-bond brick buildings and props on terrain, smashed by a scripted sequence of wrecking balls (identical seeded content on both engines). There, Box3D's slowest step matched PhysX's median — tighter frame times through the collapses.

A pure-box3d stress test ships too: a 16,290-box pyramid, one box deep, held upright by contact recycling. It steps in single-digit milliseconds, roughly halving once the stack settles to sleep — throw spheres to wake and collapse it, and dial the worker thread count to see how box3d's built-in scheduler scales. Ships in the Benchmarks sample.

Box3D's threading scales with the number of independent simulation islands — piles, debris, and crowds are its home turf; one giant coupled constraint network is its least favorable shape.

Installation

OpenUPM (recommended)

Via the openupm-cli:

openupm add com.suvitruf.box3d

Or add the scoped registry manually — Edit → Project Settings → Package Manager → Scoped Registries, add:

  • Name: package.openupm.com
  • URL: https://package.openupm.com
  • Scope(s): com.suvitruf

then install box3d for Unity from Window → Package Manager → My Registries.

Git URL

Alternatively, in the Package Manager choose Add package from git URL and paste:

https://github.com/Suvitruf/box3d-unity.git

Requires Unity 6000.0+. Native binaries are included for Windows x64, Linux x64, Android arm64, and WebGL; macOS/iOS build scripts are provided but binaries are not shipped yet (see Documentation~/building-natives.md).

Quick start

…

See Documentation~/getting-started.md for the full walkthrough, and install the samples from the Package Manager window: an interactive playground, basic simulation, joints, mouse drag, character controller, a drivable vehicle, two water scenes (a fillable buoyancy pool and a GPU particle water pool with a waterfall), and benchmark scenes comparing against PhysX — including a 16,290-box pyramid stress test you can smash by throwing spheres. The sample scenes assume URP (they render fine elsewhere, minus materials), and the interactive ones require the Input System package.

Documentation

  • Getting started
  • Component layer (experimental) — author physics in the Inspector
  • ECS / DOTS integration (experimental) — bodies as entities, Burst-compiled stepping and transform sync
  • Core concepts — ids, defs, lifetimes, the rules that matter
  • Shapes & geometry
  • Joints
  • Events
  • Queries
  • Character mover
  • Water — GPU particle water with a screen-space surface and floating bodies
  • Callbacks & threading
  • Debug draw
  • Determinism & replay — record, validate, and scrub replays
  • Determinism testing — state hashing for lockstep/cross-platform checks
  • Performance
  • Double precision (large worlds) — opt-in BOX3D_DOUBLE mode
  • Building the native libraries

Support & community

Join on Discord — chat about the project, follow progress, ask questions, share ideas, or help test. Everyone curious about Box3D or physics in Unity is welcome.

Support development — this is a free, open-source labour of love built in spare time. If you'd like to help it move along faster, you can support me on Patreon. Entirely optional — it funds the time spent on the bindings and tooling; the package stays free and MIT either way.

Contributors

  • timskap — Editor and tooling: the GameObject creation menu, component icons, inspectors and the rope editor workflow. Mostly focused on making the package more convenient to use in the editor.

License

MIT (see LICENSE). Box3D itself is MIT, © Erin Catto.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#box3dgamedevphysicsphysics-simulation

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言