Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Problem with importing ropes
#1
Hi Jose, 

I hope you are well. Thank you so much for the help you provided on my first issues.
Today, I am contacting you because I am having issues with exporting then importing ropes.

For the export, I am saving the positions and invMasses for every particles.

Then, for the import, I am resetting those as follows : 
Code:
for (int i = 0; i < rope.elements.Count && i < data.particles.Count; i++) {
      solver.positions[rope.elements[i].particle1] = data.particles[i];
      solver.invMasses[rope.elements[i].particle1] = data.invMasses[i];
 }

However, I feel this is not enough, as upon reloading, the rope lost all the smoothness it had before loading.
I feel like I missed something. Perhaps saving the orientation and or velocity as well, but I checked it, and before 
saving, all the values are 0f, 0f, 0f  so I feel like it's not what I am missing...
I made a video to better explain my issue : 



What would you advise ? 
Thanks in advance for any advice you can provide.  Sonrojado
Reply
#2
Code:
for (int i = 0; i < rope.elements.Count && i < data.particles.Count; i++) {
      solver.positions[rope.elements[i].particle1] = data.particles[i];
      solver.invMasses[rope.elements[i].particle1] = data.invMasses[i];
 }

This code doesn't make much sense. There's always more particles than there are elements in a rope (at least one more), so if you stop iterating when you hit the amount of elements, you're missing particles.

No need to use elements for this at all, as you don't care about the order in which data is stored. Simply iterate over all particles in the rope instead, I believe this will fix your issue Sonrisa. Let me know if you need further help!
Reply
#3
(20-10-2020, 12:24 PM)josemendez Wrote:
Code:
for (int i = 0; i < rope.elements.Count && i < data.particles.Count; i++) {
      solver.positions[rope.elements[i].particle1] = data.particles[i];
      solver.invMasses[rope.elements[i].particle1] = data.invMasses[i];
 }

This code doesn't make much sense. There's always more particles than there are elements in a rope (at least one more), so if you stop iterating when you hit the amount of elements, you're missing particles.

No need to use elements for this at all, as you don't care about the order in which data is stored. Simply iterate over all particles in the rope instead, I believe this will fix your issue Sonrisa. Let me know if you need further help!

I am now using :
Code:
for (int i = 0; i < rope.solverIndices.Length && i < data.particles.Count; i++) {
      solver.positions[rope.solverIndices[i]] = data.particles[i];
      solver.invMasses[rope.solverIndices[i]] = data.invMasses[i];
 }
For both import and export, but I still encounter the same issue.  Triste
Reply
#4
(20-10-2020, 01:19 PM)slugGoddess Wrote: I am now using :
Code:
for (int i = 0; i < rope.solverIndices.Length && i < data.particles.Count; i++) {
      solver.positions[rope.solverIndices[i]] = data.particles[i];
      solver.invMasses[rope.solverIndices[i]] = data.invMasses[i];
 }
For both import and export, but I still encounter the same issue.  Triste

Hard to say what the issue could be at this point. One thing Id' try when loading data is to zero out velocities, since you're still using whatever velocities the particles had at the time of loading the data. This might or might not be the culprit, but zeroing them out is definitely a good idea.

How are you storing the data? I take it that you're also iterating over particles? At which point in the frame do you load/store data?
Reply
#5
(20-10-2020, 01:38 PM)josemendez Wrote: Hard to say what the issue could be at this point. One thing Id' try when loading data is to zero out velocities, since you're still using whatever velocities the particles had at the time of loading the data. This might or might not be the culprit, but zeroing them out is definitely a good idea.

How are you storing the data? I take it that you're also iterating over particles? At which point in the frame do you load/store data?

I tried zeroing the velocities out but it didn't help.

Yes, I iterate over the particles to save them : 
Code:
for (int i = 0; i < r.solverIndices.Length; i++) {
        str += solver.positions[r.solverIndices[i]].ToString() + " : ";
        str += solver.invMasses[r.solverIndices[i]].ToString() + "; ";
}
I do the storing as soon as a click event is detected on the save button,
and I do the loading on fixed update.
Reply
#6
(20-10-2020, 01:56 PM)slugGoddess Wrote: I tried zeroing the velocities out but it didn't help.

Yes, I iterate over the particles to save them : 
Code:
for (int i = 0; i < r.solverIndices.Length; i++) {
        str += solver.positions[r.solverIndices[i]].ToString() + " : ";
        str += solver.invMasses[r.solverIndices[i]].ToString() + "; ";
}
I do the storing as soon as a click event is detected on the save button,
and I do the loading on fixed update.

Looks good to me. Is there any chance I could take a look at the actual project? I can't think of anything else that might be wrong with the load/save code.
Reply