dimforge / nphysics

2 and 3-dimensional rigid body physics engine for Rust.
https://nphysics.org
Apache License 2.0
1.62k stars 121 forks source link

Is it possible to serialize Desc struts? #212

Closed aclysma closed 5 years ago

aclysma commented 5 years ago

Thanks for all the work on this great library! This may be more of a question than an issue..

I have two use-cases:

My first thought is that additional helper structs could easily be implemented (even potentially in a separate crate) that are reference-free and explicitly designed with serialization in mind, but I was wondering if I was missing something that might make that step unnecessary.

Another option might be to break apart the RigidBodyDesc.. so for example there would be types (not a serious naming suggestion):

There would need to be some way to combine them like:

fn create_rigid_body_desc<'a>(colliders: &'a Vec<ColliderDesc>, body: &'a RigidBodyDescWithoutColliders) -> RigidBodyWithColliders<'a>

But maybe there is already a good solution that would make something like this unnecessary?

sebcrozet commented 5 years ago

Hi! Actually, the next version of nphysics which will be released at the end of next week or the week after will no longer have any lifetimes in any Desc structures, except for the descriptors of deformable bodies. For example, here is what the RigidBodyDesc will look like: https://github.com/rustsim/nphysics/blob/ccd/src/object/rigid_body.rs#L804-L823

Regarding serialization, keep in mind you will have some difficulty for serializing collider descriptors since there is currently no way of serializing an Arc<Box<Shape<N>>> because it's a trait-object. See that issue. So you will have some custom serialization code to write to handle the collider shapes.

aclysma commented 5 years ago

Thanks, sounds great!