Is it possible to create world snapshots?

Hi,

I first want to thank you for your great work, as nphysics can be really useful for a project I’m working on.

I’m still evaluating if the library can be a good fit for what I need, but one feature I cannot find is the possibility to create snapshots or checkpoints in a simulation that allow to revert to this point, make some changes, and restart the simulation from there.

For my use case I want define a sequence of events (for example, impulses on objects) that interact with the simulation, I run the simulation, and save the result as an animation. The problem is that I need to be able to edit the events interactively and that requires to re-run the whole simulation from scratch, instead of starting from the last event that didn’t change.

I’m also concerned with the memory footprint of the snapshots, and ideally should be able to be based on previous snapshot and only store the changes.

Is this possible right now with nphysics? Can I get and set the different pieces of state in a World manually and implement the snapshot system myself, or is the internal state something not covered by the public API?

Thanks in advance.

Hi !

This is a very interesting use-case ! Unfortunately, as you expected, this is not possible yet as the internal state of the simulation is not available to the user. Actually you cannot even just restart the simulation at a previous snapshot (by just restoring the velocities and positions) because the reproductibility of the rest of the simulation depends en the physics engine internal state as well.

So unfortunately I don’t think there is a better solution than what you are already doing (restarting from the beggining, or restoting only the positions and velocities if non-reproductibility is not an issue).

This is a very interesting feature though so I’ll create an issue. The memory footprint could become a problem but we could for example let the user choose the amount of internal sate to be saved to have a sufficient level of reproductibility depending on its application ! Also, saving just a diff between snapshot is interesting, but useful only to avoid re-saving the part of the scene that is not moving (sleeping).

1 Like

Thanks for you answer !

Did an issue for this feature request ever get opened? I don’t see one in the nphysics repo, and this is a feature I’d be interested in as well.

1 Like

No, sorry. Looks like I forgot to actually open it. Here it is now: https://github.com/sebcrozet/nphysics/issues/83

Though I am extremely busy those weeks so it won’t be addressed for some time (at least not by me. Contributions are very welcome!)