-
-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete rewrite for ergonomics improvements + update to Bevy 0.7 and Rapier 0.12 #138
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is compatible with Rapier 0.12, and bevy 0.7
… wasn’t actually modified by the simulation
Flipping a bit is cheaper than removing/adding a component.
This was referenced Apr 29, 2022
Closed
Closed
Closed
Merged
❤️ You are making all of my wildest dreams come true. |
quackercrumbs
added a commit
to quackercrumbs/tower-defense
that referenced
this pull request
May 15, 2022
Rapier seems to have caught up with bevy so i had to do alot of refactors for rapier colliders as well. This included restructuring how the entities are built. and moving away from using nalgebra. More information about these update can be found here: - dimforge/bevy_rapier#138
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the third design of this plugin:
Query
. This improved ergonomics significantly but also reduced performances (because of the inefficiency of randomly accessing components through a BevyQuery
). This ergonomics gain was significantly hurt by the introduction of the requiredComponent
trait implementation in bevy 0.6.Query
to store the components used by Rapier itself. Instead, we define our own components that get synchronized with Rapier at each frame (somewhat similar to the way theheron
plugin is designed).This new design has many advantages:
nalgebra
andglam
is needed any more. Users can useglam
everywhere and the plugin takes care of the conversion when synchronizing with Rapier’s state. Note however that users have access to the original Rapier objects, accessing to these raw objects will require usingnalgebra
(but you shouldn’t need to access them unless for very advanced stuffs).Reflect
trait can be auto-implemented for many components (not all of them yet).Colliders
Colliders can be created easily by inserting one of two components:
Collider
orAsyncCollider
. TheAsyncCollider
is only available in 3D right now: it allows you to create a collider from a BevyHandle<Mesh>
. If that mesh isn’t loaded yet (i.e. if you are using asynchronous asset loading), the correspondingCollider
will automatically be created once theMesh
becomes available. Some examples:When the mesh doesn’t originate from asset loading, a mesh collider can be created directly with
Collider::bevy_mesh(mesh)
wheremesh
is just abevy::render::Mesh
.Just like before, colliders are attached to rigid-bodies by adding the component to the same entity, or to its children.
Other optional components can be added to customize the collider’s behavior:
Friction
,Restitution
,CollisionGroups
, etc. The collider position can be controlled with a bevyTransform
. The scaling part of that transform is automatically taken into account to scale the collider accordingly (unless theColliderScale
component is added to control the scaling manually).Rigid-bodies
Rigid-bodies can be created easily by inserting the
RigidBodyComponent
:All the other components are optional to customize the rigid-body’s behavior:
Velocity
,LockedAxes
,ExternalForce
, etc. The rigid-body’s position can be controlled with a bevyTransform
. The scaling part of that transform has no effect on the rigid-body.Joints
Impulse joints and multibody joints are now supported as components. To attach a joint to rigid-body users only need to add the joint to the rigid-body’s entity. Impulse joints can also be attached to one of the rigid-body entity’s its children (because it is possible to have multiple impulse joint attached to the same rigid-body).
Scene queries
All the scene queries are made through the
RapierContext
object. These queries have been fully wrapped to only exposeglam
types. Querying the contact graph on intersection graph has also been wrapped to only exposeglam
types.Pixel scaling in 2D
One common source of confusion is the fact that 2D Bevy uses pixels as its default unit to place sprites, whereas Rapier use meters. Therefore a common mistake is to choose
1meter = 1pixel
which results in less accuracy and slow-motion simulation (unless one adjust the gravity). The solution we introduced previously was theRapierConfiguration::scale
that would affect the way rigid-body positions were synchronized with the bevyTransform
. However, the user had to be careful to take that scale into account everywhere else (when initializing colliders, modifying velocities, etc.)With this new design, it is possible to set a scale at the plugin-level, and that scale will be applied transparently throughout the engine. So basically, you can say "1 meter = 100 pixels" and then work with Rapier as if pixel was its distance unit (so having a collider sized as
Collider::cuboid(500.0, 100.0)
is perfectly fine). The plugin will deal with the conversion between pixels and meters transparently when it calls into Rapier itself.Debug-rendering
Debug rendering has been completely changed. Rapier 0.12 itself has its own official backend-agnostic debug-renderer (dimforge/rapier#315). This renderer is simple, and based on lines for better visibility when superimposed with your own graphics representation of your scene objects.
This renderer is able to render all the default shapes supported by Rapier (including round shapes), and will draw lines for joints.
It is completely non-instrusive (it doesn’t insert any component to any of the user’s entities) and automatic (it will render everything automatically, without the need to add components to the objects that need rendering). This renderer will render exactly what Rapier itself sees.
Debug-snapshots
Since this new design uses Rapier’s
ColliderSet
andRigidBodySet
under the hood (instead of bevyQuery
), it is now possible to serialize (withserde
) theRapierContext
. This can help debug issues that are hard to reproduce (by simply sending snapshots of the simulation shortly before the bug occurs).