Skip to content
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

Is it possible to serialize Desc struts? #212

Closed
aclysma opened this issue Jul 27, 2019 · 2 comments
Closed

Is it possible to serialize Desc struts? #212

aclysma opened this issue Jul 27, 2019 · 2 comments

Comments

@aclysma
Copy link

aclysma commented Jul 27, 2019

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

I have two use-cases:

  • RigidBodyDesc has a lifetime as mentioned in RigdBodyDesc can't be stored #205. I have a queue of these descriptions that would be used to create bodies later in the frame. It's a bit painful to enqueue this object because of the lifetimes.
  • I'd like to store body/collider descriptions in some sort of data file, likely pulled in using serde. I haven't looked at serde yet so perhaps it supports this, but I imagine if the lifetimes weren't there, it would be more straightforward to serialize structs like RigidBodyDesc.

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):

  • ColliderDesc
  • RigidBodyDescWithoutColliders
  • RigidBodyDescWithColliders<'a>

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
Copy link
Member

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
Copy link
Author

aclysma commented Jul 28, 2019

Thanks, sounds great!

@aclysma aclysma closed this as completed Jul 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants