Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manually Placing Rope Particles
#3
(17-07-2017, 03:43 PM)josemendez Wrote: GetParticlePosition() returns the final rendered position of a particle, so it's good when you want to post-process particle positions each frame. Not good at all if you want to transfer positions to another rope. The rendered position is usually not the same as the actual, physical position in the simulation due to several reasons:

- The rendered position might be the result of interpolating the previous frame's position and the current one (when the solver has interpolation enabled).
- Modifiers such as particle smoothing might offset the particle position only for rendering purposes. This modified position is not fed back into the simulation for the next frame.

The easiest (and fastest) way to do what you look for is to use the low-level getters/setters. These give you access to the solver particle positions/velocities/masses/etc directly. Take a look at the last part of this page:

http://obi.virtualmethodstudio.com/tutor...icles.html

That's brilliant! Thank you Sonrisa
My final solution, should anyone else need it, is as follows;

Code:
   /// <summary>
   /// Sets the rope's current positions to the network using the Oni C++ Solver
   /// </summary>
   private void SetPositions()
   {
       if (entity.isAttached)
       {
           //Get the particle positions through the Oni .dll
           Vector4[] particlePositions = new Vector4[ObiRope.UsedParticles];
           Oni.GetParticlePositions(ObiRope.Solver.OniSolver, particlePositions, ObiRope.UsedParticles, ObiRope.particleIndices[0]);

           //Bind them to the network until we're done or hit the hard limit
           for (int i = 0; i < particlePositions.Length && i < PositionArrayHardLimit; i++)
           {
               state.RopePositions[i] = particlePositions[i];
           }
       }
   }

   /// <summary>
   /// Gets the rope's current positions from the network and sets our locals to that
   /// </summary>
   private void GetPositions()
   {
       if (entity.isAttached)
       {
           //Create a temporary array to hold all the particles we use
           Vector4[] newPositions = new Vector4[ObiRope.UsedParticles];

           //Retrieve the values from the network until we have them all or hit our hard limit
           for (int i = 0; i < newPositions.Length && i < PositionArrayHardLimit; i++)
           {
               newPositions[i] = state.RopePositions[i];
           }

           //Set the particle positions using the Oni .dll in order to apply to the rope
           Oni.SetParticlePositions(ObiRope.Solver.OniSolver, newPositions, newPositions.Length, ObiRope.particleIndices[0]);
           //Oni.ApplyPositionInterpolation(ObiRope.Solver.OniSolver, Time.fixedDeltaTime); Maybe ???
       }
   }
Reply


Messages In This Thread
RE: Manually Placing Rope Particles - by PhantomBadger - 18-07-2017, 12:37 PM