Obi Official Forum
Help Problem with importing ropes - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Help Problem with importing ropes (/thread-2549.html)



Problem with importing ropes - slugGoddess - 20-10-2020

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


RE: Problem with importing ropes - josemendez - 20-10-2020

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!


RE: Problem with importing ropes - slugGoddess - 20-10-2020

(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


RE: Problem with importing ropes - josemendez - 20-10-2020

(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?


RE: Problem with importing ropes - slugGoddess - 20-10-2020

(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.


RE: Problem with importing ropes - josemendez - 20-10-2020

(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.