Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Positions Saving & Loading
#1
Hello.

I need to save disposed positions of particles (or vertices) after closing the game and to load them when I start the game.
I managed to write actor's positions and obiCloth's meshVertices arrays to XML files and to read them.

But I faced with two problems:
1) It's ok to SetParticlePositions using the values from the file; but it was not possible to get changed positions of particles (I mean the position[] array doesn't change, however the real picture is ok while deforming the object). Maybe it's necessary to RequireRenderablePosition (or/and PullDataFromSolver), isn't it?
2) On the other hand, values of meshVertices array change when I deform the mesh, but I have no luck in changing them manually with the values from the XML file (I mean the clothMesh from ObiClothBase class).

Maybe I missed something important?

For clarity, here is an example of what I need:
1) I start my game with a ball.
[attachment=215]

2) Then I deform it (via the "finger" collider), save it, and quit the game.
[attachment=217]

3) When I open the game again I am to see the second picture.
Reply
#2
(16-01-2019, 05:03 AM)Loki_Priest Wrote: Hello.

I need to save disposed positions of particles (or vertices) after closing the game and to load them when I start the game.
I managed to write actor's positions and obiCloth's meshVertices arrays to XML files and to read them.

But I faced with two problems:
1) It's ok to SetParticlePositions using the values from the file; but it was not possible to get changed positions of particles (I mean the position[] array doesn't change, however the real picture is ok while deforming the object). Maybe it's necessary to RequireRenderablePosition (or/and PullDataFromSolver), isn't it?
2) On the other hand, values of meshVertices array change when I deform the mesh, but I have no luck in changing them manually with the values from the XML file (I mean the clothMesh from ObiClothBase class).

Maybe I missed something important?

For clarity, here is an example of what I need:
1) I start my game with a ball.


2) Then I deform it (via the "finger" collider), save it, and quit the game.


3) When I open the game again I am to see the second picture.

1) Correct, you need to use either renderable positions, call PullDataFromSolver(ParticleData.POSITIONS) to update the actor array, or use Oni.GetParticlePositions(). In your case, I'd use either method 1 or 2, 1 is easier. Renderable positions -as the name implies-, are used for smooth rendering and usually contain interpolated positions between two physics updates, so it's best to use regular positions if you intend to save/load them. See:
http://obi.virtualmethodstudio.com/tutor...icles.html

2) mesh vertices are modified internally the physics engine, and set at the end of every frame. You should either set the particle positions array and call PushDataToSolver() -opposite to PullDataFromSolver-, or Oni.SetParticlePositions.
Reply
#3
Thanks a lot! Now it works properly.


Code:
   void SaveAll()
   {
       //obiCloth.Solver.RequireRenderablePositions();
       obiCloth.PullDataFromSolver(ParticleData.POSITIONS);
       SaveDB(_xml3, s3, obiCloth.positions);
       //obiCloth.Solver.RelinquishRenderablePositions();
       Debug.Log("Saved");
   }

   public void LoadMesh()
   {
       if (obiCloth.InSolver)
       {
           obiCloth.PullDataFromSolver(ParticleData.POSITIONS);
           for (int i = 0; i < any.Length; i++)
           {
               obiCloth.positions[i] = any[i] + obiCloth.transform.localPosition;
           }
           obiCloth.PushDataToSolver(ParticleData.POSITIONS);
       }
   }

   public void LoadAll()
   {
       LoadAny(_xml3, s3, any);
       if (obiCloth != null)
       {
           if (obiCloth.Solver != null)
           {
               LoadMesh();
           }
       }
   }
Reply