Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save Rope State
#1
Has anyone been able to successfully save the state of a rope and load it correctly? I was told to pull the position and velocity arrays and serialize those and then set them again and push the data but that doesn't seem to work - the rope goes crazy at the start.

I would love to see an example of saving rope state that also takes into account any potential lengthening from a rope cursor.

Thanks!
Reply
#2
So I've made a little progress and I can get the rope to initialize correctly as long as I haven't extended it previously. If I save the state of a rope that was extended with the rope cursor, I cannot successfully restore the state correctly.
Reply
#3
(09-09-2017, 01:16 AM)ptrick Wrote: So I've made a little progress and I can get the rope to initialize correctly as long as I haven't extended it previously. If I save the state of a rope that was extended with the rope cursor, I cannot successfully restore the state correctly.

If your rope has been extended, things get quite complex. You need to store which particles are active, and any new constraints that have been generated by the cursor. Haven´t tried this use case myself to be honest, once I do I´ll come back with some more info.
Reply
#4
(09-09-2017, 11:03 AM)josemendez Wrote: If your rope has been extended, things get quite complex. You need to store which particles are active, and any new constraints that have been generated by the cursor. Haven´t tried this use case myself to be honest, once I do I´ll come back with some more info.

OK well that gives me something to start with - I tried serializing everything in the Actor class and then reloading that in, but it still was wacky, I think I will have to take care of the constraints as well. If I get this working, I will post the code up here.
Reply
#5
OK so I have made some significant progress with saving the state of a rope that has been extended.

The long and the short of it is this:

1. I have a component that manages extending the Rope using the Rope Cursor. We are using a script which was provided a while ago to check for tension and extend the rope if tension exceeds a threshold.

2. If you do not use the rope cursor, saving and restoring rope state is pretty easy and can be summarized as:

* Pull velocity and position data from solver
* Serialize the positions and velocities of the rope in JSON or whatever
* To load - we attach an event handler to the OnAddedToSolver of the rope and in that event handler, we set the positions and velocities on the rope to the serialized values after Instantiate'ing our rope. We then call PushDataToSolver

3. after much experimentation, I found that in order to be able to easily save changes when the rope has been extended we only have to do one thing, each time we use the ChangeLength method of the cursor, we add that value to a list, we call the list lengthChanges and it's a List<float>. This list gets serialized with your positions and velocities data like usual.

4. When you load this data, the order is important: first - for each entry in your lengthChanges list, call ChangeLength on the rope cursor with that value. This is basically getting your rope back to the length it was when you serialized it. THEN - set your velocities and positions and push to solver.

It really is that easy.

TLDR - keep a list of each time you call ChangeLength on your rope cursor and serialize your lengthChanges, positions, and velocities. When deserializing, first, call ChangeLength for each entry in the lengthChanges list, then set your positions and velocities and push to solver.

NOTE: If you plan on serializing multiple times, it's important that you keep track of the lengthChanges list for multiple loads otherwise, it won't work. One optimization that we have done is during the resize code, if we are shrinking the rope and we are back to the ORIGINAL size of the rope, we clear out the length changes list so that it doesn't grow infinitely.

NOTE: You CANNOT just keep the final length of the rope and call ChangeLength once - this doesn't work for whatever reason, you need to call ChangeLength as many times as you called it originally even though the end length will just be the final length of the rope, the internal state will be correct.
Reply
#6
Here's a screenshot of before and after loading about 40 ropes

http://imgur.com/a/gB7IU

It takes roughly .2ms to do this
Reply