Comments (13)
Using type parameters is not an option because that would result in:
- The
Collider
having a type parameter. - The
ColliderSet
having a type parameter. - The
PhysicsPipeline
andQueryPipeline
having a type parameter. - Same for a lot of other structs (
BroadPhase
,NarrowPhase
, etc.)
So that means most of the Rapier structs will have a type parameters which is one thing you want to avoid because:
- It can slow down compilation times of the end-user crate.
- It prevents the end-user from enabling compiler optimizations for Rapier while keeping optimizations disabled for their own crate. And since Rapier is about 100 times slower in debug mode, this would make the end-user app unusable in debug mode.
from rapier.
Support for user-defined shapes will be possible in the next version of Rapier, to be released at the end of January 2021. However, for this release, serialization/deserialization will only work for shapes supported by Rapier by default.
I don't think there is any other options than using a Box trait-object (but I might be wrong). In that case, we need to see what we can do for serializing them
Have a look at https://github.com/dtolnay/typetag
I don't think using typetag
is a great solution because it has limited platform support. See the README of one of its dependencies, inventory.
from rapier.
Hi! Custom shapes is something I'd like to allow at some point but some big changes need to happen before that:
- We need to move all the collision-detection stuffs out of Rapier. I've been working on it lately but it will probably not be completed before 2 or 3 months (because this requires some significant modifications of the way ncollide works).
- I don't think there is any other options than using a
Box<Shape>
trait-object (but I might be wrong). In that case, we need to see what we can do for serializing them: either we#[serde(skip)]
custom shapes altogether, or we find another solution, based on erased_serde perhaps? - The
DefaultContactDispatcher
should no longer be hard-coded into the narrow-phase. But that should be dealt with once we complete the modification for 1.
from rapier.
Hi! Glad to hear this is part of the plan!
Another option instead of Box<dyn Shape>
would be to use type parameters. I'm envisioning usage that would look like this:
use rapier2d::geometry::collider::{Shape, DefaultShape};
#[derive(Shape)] // macro that handles all the boilerplate dispatching code
pub enum MyShape {
Default(DefaultShape),
MyShapeA(MyShapeA),
MyShapeB(MyShapeB),
}
Here the current Shape
enum is renamed to DefaultShape
, and Shape
is now a trait. DefaultShape
, MyShapeA
, and MyShapeB
, and MyShape
all implement Shape
. Rapier types can then be parameterized by MyShape
in user code. This should make serialization a bit easier. It would also open up the option of excluding some of the default shapes if they are never used in the simulation.
from rapier.
I have been convinced!
erased_serde
seems like a viable solution.
from rapier.
Using dyn pointers feels like it would lose a bunch of efficiency...
from rapier.
I don't think it will be that bad, because the use of trait objects can be reserved just for user-defined shapes. For example:
pub enum Shape {
/// A ball shape.
Ball(Ball),
/// A convex polygon shape.
Polygon(Polygon),
/// A cuboid shape.
Cuboid(Cuboid),
/// A capsule shape.
Capsule(Capsule),
/// A triangle shape.
Triangle(Triangle),
/// A triangle mesh shape.
Trimesh(Trimesh),
/// A heightfield shape.
HeightField(HeightField),
/// A user-defined shape.
Custom(Box<dyn CustomShape>),
}
from rapier.
That seems fine as long as there is a low amount of custom shapes. I guess the user could fork if they really needed a custom shape...
Also it seems like you are not using the enum_dispatch crate, which could be very helpful...
from rapier.
I don't think there is any other options than using a Box trait-object (but I might be wrong). In that case, we need to see what we can do for serializing them
Have a look at https://github.com/dtolnay/typetag
from rapier.
I wonder if it would be possible to completely offload the collisions from the physics, such that people could have a custom collider that doesn't use the support function things. For my game, I'm trying to have everything be a voxel, which leads to very simple collision code without using the support function.
from rapier.
@iMplode-nZ When user-defined shapes will be supported, it will be possible to provide your own collision-detection algorithms for your own shape types. So you could have some kind of VoxelSet
shape with a custom collision-detection algorithm.
from rapier.
I don't see how you could implement this... what would happen if a VoxelSet
collides with a TriangleMesh
?
(Also I would really prefer if the implementation doesn't include dynamic pointers or boxing at all)
I'm planning to offload all the collision work to the GPU, which is asynchronous, and I don't really see doing this with the CPU manually calling functions for whether two objects collide in the standard manner.
from rapier.
@iMplode-nZ It will be your responsibility to provide the collision-detection algorithms between your user-defined shape and all the other shapes. For each pair of colliders, we do a dynamic dispatch to select the right collision-detection algorithm for a given pair of shapes. Right now this is done by the hard-coded DefaultContactDispatcher
but once we support user-defined shapes, this dispatcher can be user-defined too.
Because there is a dynamic dispatch to select the algorithm, this involve trait-objects. But the collision-detection algorithm itself is free to downcast this trait-object to the concrete shape type before computing the contacts.
from rapier.
Related Issues (20)
- 4D Physics
- QueryFilter need Send + Sync
- Strange performance issue with many colliders HOT 2
- Issue with limits in RopeJoint? HOT 3
- Clarification on Determinism HOT 2
- Aabb type is not properly re-exported from Parry HOT 1
- Site link dead HOT 2
- `ColliderBuilder` does not implement `Debug` HOT 1
- `unreachable executed` error when using MultiBody joint with WASM HOT 1
- proxy.aabb.maxs >= min_bound 7683905000 HOT 3
- Build error after 0.24.0 update HOT 1
- Compilation error with bevy and bevy_rapier3d HOT 2
- Erased angular velocity since v0.18 HOT 2
- Particle physics HOT 5
- Custom broad-phase
- setTranslation results in NaN? (Javascript Version) HOT 1
- Build breakage with 0.18 in `SolverConstraintsSet` HOT 4
- Crash with `attempt to subtract with overflow` in `SAPRegion::update_after_subregion_removal()` HOT 1
- How to simulate triggers between kinematic and sensor bodies HOT 3
- Panics when setting collider via `ColliderSet::get_mut()` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rapier.