Stride.BepuPhysics
0.9.0.2
Prefix Reserved
See the version list below for details.
dotnet add package Stride.BepuPhysics --version 0.9.0.2
NuGet\Install-Package Stride.BepuPhysics -Version 0.9.0.2
<PackageReference Include="Stride.BepuPhysics" Version="0.9.0.2" />
paket add Stride.BepuPhysics --version 0.9.0.2
#r "nuget: Stride.BepuPhysics, 0.9.0.2"
// Install Stride.BepuPhysics as a Cake Addin #addin nuget:?package=Stride.BepuPhysics&version=0.9.0.2 // Install Stride.BepuPhysics as a Cake Tool #tool nuget:?package=Stride.BepuPhysics&version=0.9.0.2
Bepu Physics V2 Integration with Stride 3D - Work in Progress
Integrating Bepu Physics v2 into Stride.
Features
- Simulations: Highly configurable simulation & multi-simulation
- Bodies: Static, dynamic, and kinematic
- Colliders: MeshCollider, ConvexHullCollider, Box, Sphere, Cylinder, Capsule, Triangle (Note: MeshCollider is categorized as a "body"; further details in the documentation)
- Collision Handler System by body & RayCast system
- CharacterController (Work in Progress)
- CarController
- Numerous utility scripts & scenes to aid understanding and usage of this Bepu implementation in Stride.
Usage
-Clone this repository to your local machine and run the stride project. You will have some samples to look at.
-Use our nuget : https://www.nuget.org/packages/Stride.BepuPhysics/
- Add Bepu Settings :
- Add Containers & Colliders :
- Add constraints :
- Use/Write Utility Scripts :
Settings
Description
Settings represent an instance of Bepu physics, defining various configurations for a simulation. You can create multiple settings to set up different simulations within your Stride project. These settings allow editing simulation global parameters, enabling customization and fine-tuning of the physics environment to suit specific requirements.
Properties
TimeWrap
- Type: float
- Description: Allows you to choose the speed of the simulation.
Pose gravity
- Type: Vector3
- Description: Represents general gravity. Note: Will change in the future.
Linear damping
- Type: float
- Description: Controls linear damping. (Refer to Bepu Docs for more details.)
Angular damping
- Type: float
- Description: Controls angular damping. (Refer to Bepu Docs for more details.)
Solve iteration
- Type: int
- Description: Controls the number of iterations for the solver. (Refer to Bepu Docs for more details.)
Solve sub step
- Type: int
- Description: Specifies the number of sub-steps for solving. (Refer to Bepu Docs for more details.)
Parallel update
- Type: bool
- Description: Allows updating Stride's entities' transform in parallel.
Simulation Fixed step
- Type: float
- Description: Specifies the number of milliseconds per step to simulate.
Max steps/frame
- Type: int
- Description: Represents the maximum number of steps per frame to avoid a death loop. (Refer to Bepu Docs for more details. Warning: You may lose real-time physics.)
Containers
Description
Containers serve as representations or links within Bepu physics for managing specific types of entities:
- BodyContainer: This container can contains in the same node or in childs nodes somes colliders provided in the "Colliders" section, representing physical bodies in the simulation.
- StaticContainer: Similar to the BodyContainer but represents static objects in the simulation.
- BodyMeshContainer: Specifically used for perfect mesh colliders in conjunction with the appropriate mesh collider, representing physical bodies.
- StaticMeshContainer: Like the MeshBodyContainer, this is used for perfect mesh colliders but represents static objects in the simulation.
These containers play a vital role in organizing and defining the properties and behaviors of entities within the Bepu physics simulation environment.
Properties
- SimulationIndex
- Description: Allow you to choose in which simulation the object is.
- Type: Integer
- Spring frequency
- Description: Determines the oscillation rate or stiffness of a spring constraint.
- Type: Float
- Range: Positive values; higher values result in a stiffer spring.
- Spring damping ratio
- Description: Controls the rate at which oscillations in a spring constraint decrease over time, affecting its responsiveness and stability.
- Type: Float
- Range: Values between 0 and 1; higher values dampen oscillations more quickly.
- Friction coefficient
- Description: Specifies the resistance to motion between two colliding objects, affecting how much they slide against each other.
- Type: Float
- Range: Non-negative values; higher values increase friction.
- Maximum recovery velocity
- Description: Sets the maximum speed at which objects can recover from penetration due to collisions or constraints.
- Type: Float
- Range: Positive values; higher values allow faster recovery from interpenetration.
- Collider group mask The collision mask system allows precise control over collision interactions between different groups of objects within the simulation.
- Type: Byte
- Algorithm:
bool CollisionOccur => (com == a.colliderGroupMask || com == b.colliderGroupMask) && com != 0;
com
is the comparison value obtained from the bitwise comparison of collision masks of two colliding objects.- Collision occurs if the
com
value matches either collider's group mask and is not equal to zero.
- Truth Table:
Collision Group Masks | 255 | 1 | 3 | 5 | 0 |
---|---|---|---|---|---|
255 | 255 | 1 | 3 | 5 | 0! |
1 | 1 | 1 | 1 | 1 | 0! |
3 | 3 | 1 | 3 | 1! | 0! |
5 | 5 | 1 | 1! | 5 | 0! |
0 | 0! | 0! | 0! | 0! | 0! |
Colliders
Description
Colliders define the shapes and properties of physical objects within a Bepu physics simulation. They play a crucial role in determining how objects interact with each other and the environment. There are various types of colliders available, each suited for different scenarios:
- Box Collider: Represents a rectangular prism-shaped collider, often used for simple objects like crates or buildings.
- Capsule Collider: Combines a cylinder and two half-spheres, useful for character models or objects with cylindrical shapes.
- Convex Hull Collider: Defines a collider based on the convex hull of a mesh, providing a simpler collision shape approximation for more complex geometries.
- Cylinder Collider: Shapes objects as cylinders, suitable for entities like pipes or cylindrical objects.
- Sphere Collider: Shapes objects as spheres, suitable for entities like balls or spherical objects.
- Triangle Collider: Uses triangles from a mesh to create a collider, often used for terrain or ground collision.
⚠️ A Mesh Container: Allows for collision based on the exact geometry of a mesh, enabling precise collision detection for irregular shapes but it cannot be compounded with regular colliders (so no colliders in the same/childs nodes of a MeshContainer).
Each collider type has its advantages and is chosen based on the specific requirements of the objects you're simulating. They come with parameters that can be adjusted such as Height. Note that you can compound any colliders by adding more component. Colliders must be in the same or in the child entities of a BodyContainer or a StaticContainer. If in a child entity, you can move, rotate & scale* it using Transform.
*Only ConvexHullCollider & MeshContainer can be scaled.
Properties
Dimensional (Height, radius, ..)
- Type: float
- Description: Allows you to choose the size of the collider (Refer to Bepu Docs.)
Mass
- Type: float
- Description: Allows you to choose the mass of the collider volume (Refer to Bepu Docs.)
Others
- Description: (Refer to Bepu Docs for more details on others properties.)
Constraints
Description
Constraints define relationships or rules that govern how entities interact within the simulation. They establish connections between bodies, dictating their movement or behavior based on specific criteria or physical laws.
Some common types of constraints in BepuPhysicsV2 include:
- BallSocketConstraint: Restricts two entities to a fixed distance, allowing rotation around the connecting point.
- DistanceLimitConstraint: Constrains entities within a certain distance range, restricting their movement beyond defined limits.
- HingeConstraint: Permits rotation around a single axis, simulating a hinge-like movement between entities.
- AngularMotorConstraint: Applies rotational force to enforce desired angular motion between entities.
- TwistMotorConstraint: Controls twisting motion between entities, allowing controlled rotation around a specific axis.
These constraints play a crucial role in simulating realistic interactions and behaviors between entities within the physics environment, enabling the creation of complex and accurate simulations.
Properties
Bodies
- Type: List<BodyContainerComponent>
- Description: Allows you to choose wich bodies to apply the constraint on. (Refer to Bepu Docs for more details on how many entities for each constraints.)
Others
- Description: (Refer to Bepu Docs for more details on others properties.)
Use/build Utility scripts
These scripts allow runtime modification of the simulation using keyboard inputs and serve as a good starting point to understand Bepu integration in Stride.
Issues & To-Do
Check out the TODO.txt for pending tasks and issues.
Videos
Note that in some videos, Bepu simulation settings had been tweaked to maximize performance.
These videos were recorded in 1080p using OBS, demonstrating the integration in Debug mode on hardware featuring an i7 6700k & GTX 970.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- BepuPhysics (>= 2.5.0-beta.17)
- Stride.Engine (>= 4.2.0.2043)
- Stride.Physics (>= 4.2.0.2043)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Stride.BepuPhysics:
Package | Downloads |
---|---|
Stride.Assets
Package Description |
|
Stride.Core.Assets.CompilerApp
Package Description |
|
Stride.Editor
Package Description |
|
Stride.CommunityToolkit.Bepu
A specialized extension of the Stride Community Toolkit, providing easy-to-use Bepu physics utilities for Stride projects. Enhance your Stride scenes with realistic physics simulations without needing additional assets or complex setup. |
|
Stride.BepuPhysics.Debug
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Stride.BepuPhysics:
Repository | Stars |
---|---|
stride3d/stride
Stride (formerly Xenko), a free and open-source cross-platform C# game engine.
|