Convert Figma logo to code with AI

bepu logobepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.

2,594
286
2,594
60

Top Related Projects

13,296

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

8,897

Box2D is a 2D physics engine for games

4,583

2D and 3D physics engines focused on performance.

Quick Overview

BEPUphysics2 is a high-performance 3D physics engine written in C#. It's designed for real-time simulations and games, focusing on speed and accuracy. The library provides a comprehensive set of physics features while maintaining a clean and efficient codebase.

Pros

  • High performance and optimized for modern hardware
  • Extensive physics simulation capabilities, including rigid bodies, constraints, and collision detection
  • Well-documented and actively maintained
  • Supports both single-threaded and multithreaded simulations

Cons

  • Steeper learning curve compared to some other physics engines
  • Limited built-in rendering capabilities (focuses primarily on physics simulation)
  • May require additional work to integrate with certain game engines or frameworks
  • Documentation, while comprehensive, can be technical and challenging for beginners

Code Examples

Creating a simple simulation:

var simulation = Simulation.Create(BufferPool, new NarrowPhaseCallbacks(), new PoseIntegratorCallbacks(new Vector3(0, -10, 0)));
var shape = new Box(1, 1, 1);
var description = BodyDescription.CreateDynamic(new Vector3(0, 5, 0), shape.ComputeInertia(1), simulation.Shapes.Add(shape), 0.01f);
var bodyHandle = simulation.Bodies.Add(description);

Stepping the simulation:

float timeStep = 1f / 60f;
simulation.Timestep(timeStep);

Querying body position:

simulation.Bodies.GetDescription(bodyHandle, out var bodyDescription);
Vector3 position = bodyDescription.Pose.Position;

Getting Started

  1. Install the BEPUphysics2 NuGet package:

    dotnet add package BepuPhysics
    
  2. Create a simulation and add bodies:

    using BepuPhysics;
    using BepuUtilities;
    
    var simulation = Simulation.Create(new BufferPool(), new NarrowPhaseCallbacks(), new PoseIntegratorCallbacks(new Vector3(0, -10, 0)));
    var shape = new Box(1, 1, 1);
    var description = BodyDescription.CreateDynamic(new Vector3(0, 5, 0), shape.ComputeInertia(1), simulation.Shapes.Add(shape), 0.01f);
    var bodyHandle = simulation.Bodies.Add(description);
    
  3. Run the simulation in your game loop:

    float timeStep = 1f / 60f;
    simulation.Timestep(timeStep);
    

Competitor Comparisons

13,296

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Pros of Bullet3

  • More mature and widely adopted in industry
  • Supports a broader range of platforms and languages
  • Extensive documentation and community support

Cons of Bullet3

  • Can be more complex to set up and use
  • Performance may be slower in some scenarios
  • Less focus on determinism across platforms

Code Comparison

BEPUphysics2 (C#):

var simulation = Simulation.Create(BufferPool, new NarrowPhaseCallbacks(), new PoseIntegratorCallbacks(new Vector3(0, -10, 0)));
var box = new Box(1f, 1f, 1f);
var boxShape = new CollidableDescription(simulation.Shapes.Add(box));
var boxPose = new RigidPose(new Vector3(0, 5, 0));
simulation.Bodies.Add(BodyDescription.CreateDynamic(boxPose, boxShape, 1));

Bullet3 (C++):

btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
8,897

Box2D is a 2D physics engine for games

Pros of Box2D

  • Widely adopted and battle-tested in numerous games and applications
  • Extensive documentation and community support
  • Supports multiple programming languages through ports

Cons of Box2D

  • Less performant for large-scale simulations compared to BEPUphysics2
  • Limited to 2D physics, while BEPUphysics2 supports 3D simulations
  • Less frequent updates and maintenance

Code Comparison

Box2D (C++):

b2Vec2 gravity(0.0f, -10.0f);
b2World world(gravity);
b2BodyDef groundBodyDef;
b2Body* groundBody = world.CreateBody(&groundBodyDef);

BEPUphysics2 (C#):

var simulation = Simulation.Create(BufferPool, new NarrowPhaseCallbacks(), new PoseIntegratorCallbacks(new Vector3(0, -10, 0)));
var shape = new Box(1, 1, 1);
simulation.Bodies.Add(BodyDescription.CreateDynamic(new Vector3(0, 5, 0), shape.ComputeInertia(1), simulation.Shapes.Add(shape), 0.01f));

Both libraries provide similar functionality for creating physics simulations, but BEPUphysics2 offers more advanced features and better performance for complex scenarios. Box2D remains a solid choice for 2D games and simpler applications, while BEPUphysics2 is better suited for large-scale 3D simulations and high-performance requirements.

4,583

2D and 3D physics engines focused on performance.

Pros of Rapier

  • Multi-language support: Rapier is available in Rust, C++, and JavaScript, making it more versatile for different platforms and development environments
  • Continuous collision detection: Offers better handling of fast-moving objects and prevents tunneling issues
  • Active development and community: Regular updates and a growing user base contribute to ongoing improvements and support

Cons of Rapier

  • Performance: Generally slower than BEPUphysics2 in some benchmarks, especially for large-scale simulations
  • Documentation: Less comprehensive documentation compared to BEPUphysics2, which may make it harder for beginners to get started

Code Comparison

Rapier (Rust):

let mut rigid_body = RigidBodyBuilder::dynamic()
    .translation(vector![0.0, 10.0, 0.0])
    .build();
let collider = ColliderBuilder::ball(0.5).build();

BEPUphysics2 (C#):

var body = new BodyDescription
{
    Pose = new RigidPose(new Vector3(0, 10, 0)),
    LocalInertia = default(BodyInertia)
};
var shape = new Sphere(0.5f);

Both examples demonstrate creating a dynamic rigid body with a spherical collider, showcasing similar concepts but with language-specific syntax and structure.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

bepuphysics v2

This is the repo for the bepuphysics v2 library, a complete rewrite of the C# 3d rigid body physics engine BEPUphysics v1.

The BepuPhysics and BepuUtilities libraries target .NET 8 and should work on any supported platform. The demos application, Demos.sln, uses DX11 by default. There is also a Demos.GL.sln that uses OpenGL and should run on other platforms. The demos can be run from the command line (in the repo root directory) with dotnet run --project Demos/Demos.csproj -c Release or dotnet run --project Demos.GL/Demos.csproj -c Release.

The physics engine heavily uses System.Numerics.Vectors types, so to get good performance, you'll need a compiler which can consume those types (like RyuJIT).

To build the source, the easiest option is a recent version of Visual Studio with the .NET desktop development workload installed. Demos.sln references all relevant projects. For more information, see Building.

Features

  • Spheres, capsules, boxes, triangles, cylinders, and convex hulls
  • Compounds of the above
  • Meshes
  • A whole bunch of constraint types
  • Newts
  • Linear and angular continuous collision detection
  • Extremely low cost sleep states for resting bodies
  • Efficient scene-wide ray and sweep queries
  • Character controller example
  • At least somewhat extensible collision pipeline, with example custom voxel collidable
  • Highly nonidiomatic APIs
  • Super speediness
  • And a bunch of other miscellaneous stuff!

Links

Report bugs on the issues tab.

Use the discussions tab for... discussions. And questions.

There's a discord server. I'll be focusing on github for long-form content, but if you like discord, you can discord.

Documentation pages in a conventional form factor exist! (If I've broken the docs page, see the raw repo versions as a backup or github pages if I just broke the domain redirect.)

If you have too many dollars, I'm willing to consume them through github sponsors. Please do not give me any amount of money that feels even slightly painful. Development is not conditional on sponsorships, and I already have a goodly number of dollars.