Obi Official Forum
Define Particle Position without inertia - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Softbody (https://obi.virtualmethodstudio.com/forum/forum-12.html)
+--- Thread: Define Particle Position without inertia (/thread-3335.html)



Define Particle Position without inertia - promero - 24-02-2022

I try to generate a save and load function for softbody object.
For that, I save on json file all particle positions.

When I load it, I define the position of each particle with velocity to zero.
I know that to keep positions I must define invMasses to zero.

If I do it works, because softbody particles are fixed.

My problem is that I don't want to fix the particles, particles must move depending ObiParticleAttachment.

What I need is to open the softbody on same position that I save before, and particles must be without movement, until I interact with ObiParticleAttachment elements.

In theory if velocity is zero, particles must keep positions but my softbody particles move a lot until loose inertial energy.

Any advice or help is appreciated.

Thanks


RE: Define Particle Position without inertia - josemendez - 25-02-2022

(24-02-2022, 10:35 PM)promero Wrote: I try to generate a save and load function for softbody object.
For that, I save on json file all particle positions.

When I load it, I define the position of each particle with velocity to zero.
I know that to keep positions I must define invMasses to zero.

If I do it works, because softbody particles are fixed.

My problem is that I don't want to fix the particles, particles must move depending ObiParticleAttachment.

What I need is to open the softbody on same position that I save before, and particles must be without movement, until I interact with ObiParticleAttachment elements.

In theory if velocity is zero, particles must keep positions but my softbody particles move a lot until loose inertial energy.

Any advice or help is appreciated.

Thanks

Make sure that the "prevPositions" and "startPositions" arrays are set to the same values as "positions". Obi is a position-based dynamics engine, which means velocities are derived from positions. This happens at the end of each simulation step (pseudocode):

Code:
particle.velocity = (particle.position - particle.prevPosition) / deltaTime;

The values in "startPositions" are used to interpolate physics state, then velocities are used to update particle positions at the start of the next frame. If the initial particle position doesn't match is previous position, velocity will not be zero. Note this is only an issue during instantiation, generally when you set a custom particle velocity it overrides the one calculated by the engine at the end of each frame.

You can read more about how position-based dynamics (or PBD for short) work here:
https://matthias-research.github.io/pages/publications/posBasedDyn.pdf


RE: Define Particle Position without inertia - promero - 10-03-2022

(25-02-2022, 08:56 AM)Hi Jose,I review code and now it works fine. Thank you very much for your help.Obisoftbody need RecalculateRestShapeMatching() after set valuesis it the same process for obi rope ?I set positions, prevpositions, startPositions and velocities, but when I generate rope it has too much inertial.Thanksjosemendez Wrote: Make sure that the "prevPositions" and "startPositions" arrays are set to the same values as "positions". Obi is a position-based dynamics engine, which means velocities are derived from positions. This happens at the end of each simulation step (pseudocode):

Code:
particle.velocity = (particle.position - particle.prevPosition) / deltaTime;

The values in "startPositions" are used to interpolate physics state, then velocities are used to update particle positions at the start of the next frame. If the initial particle position doesn't match is previous position, velocity will not be zero. Note this is only an issue during instantiation, generally when you set a custom particle velocity it overrides the one calculated by the engine at the end of each frame.

You can read more about how position-based dynamics (or PBD for short) work here:
https://matthias-research.github.io/pages/publications/posBasedDyn.pdf



RE: Define Particle Position without inertia - josemendez - 11-03-2022

Quote:Hi Jose,I review code and now it works fine. Thank you very much for your help.Obisoftbody need RecalculateRestShapeMatching() after set valuesis it the same process for obi rope ?I set positions, prevpositions, startPositions and velocities, but when I generate rope it has too much inertial.Thanks

RecalculateRestShapeMatching() recalculates the rest state of shape matching constraints, as the name implies. Shape matching is only used in softbodies (see: http://obi.virtualmethodstudio.com/manual/6.3/convergence.html) so there's no need to call it when modifying ropes.

If you set positions, previous positions and velocities, inertia at the time of generating the rope should be zero. Can you share the code you're using to generate your rope?