Obi Official Forum

Full Version: Synchronizing softbody, doesn't render
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I tried using the same script I had for synchronizing ropes, but instead of using a ObiRope component, I replaced it with ObiActor for a more general approach since it's just synchronizing particles. The ropes work fine but the softbody doesn't, the positions are received correctly, I am drawing debug lines to visualize them:

[Image: r91h9FW.png]

You can see the softbody shape, its there.

This script works just fine for ropes, there isn't any rope specific code there.

This is how I am setting the solver positions

Code:
var wantedHostTimeStamp = Host.Now - HostTimespan.FromSeconds(ReceiveDelay);

        var states = GetStatesAroundHostTimeStamp(wantedHostTimeStamp);

        if (states.HasStates)
        {
            var interpolationFactor = GetInterpolationFactorBetweenStates(wantedHostTimeStamp, states.Item1, states.Item2);

            for (int i = 0; i < actor.activeParticleCount; i++)
            {
                var globalPosition = actor.solver.transform.TransformPoint(Vector3.Lerp(states.Item1.Positions[i], states.Item2.Positions[i], interpolationFactor));
                Debug.DrawLine(Vector3.zero, globalPosition);
                actor.solver.positions[actor.solverIndices[i]] = Vector3.Lerp(states.Item1.Positions[i], states.Item2.Positions[i], interpolationFactor);
                actor.solver.invMasses[actor.solverIndices[i]] = 0;
            }
        }

This is where I actually set the particles positions in the solver:
Code:
actor.solver.positions[actor.solverIndices[i]] = Vector3.Lerp(states.Item1.Positions[i], states.Item2.Positions[i], interpolationFactor);
                actor.solver.invMasses[actor.solverIndices[i]] = 0;

Gettings lots of these:

[Image: tF2z4l3.png]}

So it looks like its trying to set invalid values for the softbody transform on Softbody script line 281

It works just fine for the ropes and its the same component that i am using to synchronize them, what can I do to track this problem down?
(06-12-2022, 02:41 PM)Milionario Wrote: [ -> ]So I tried using the same script I had for synchronizing ropes, but instead of using a ObiRope component, I replaced it with ObiActor for a more general approach since it's just synchronizing particles. The ropes work fine but the softbody doesn't, the positions are received correctly, I am drawing debug lines to visualize them:

[Image: r91h9FW.png]

You can see the softbody shape, its there.

This script works just fine for ropes, there isn't any rope specific code there.

This is how I am setting the solver positions

Code:
var wantedHostTimeStamp = Host.Now - HostTimespan.FromSeconds(ReceiveDelay);

        var states = GetStatesAroundHostTimeStamp(wantedHostTimeStamp);

        if (states.HasStates)
        {
            var interpolationFactor = GetInterpolationFactorBetweenStates(wantedHostTimeStamp, states.Item1, states.Item2);

            for (int i = 0; i < actor.activeParticleCount; i++)
            {
                var globalPosition = actor.solver.transform.TransformPoint(Vector3.Lerp(states.Item1.Positions[i], states.Item2.Positions[i], interpolationFactor));
                Debug.DrawLine(Vector3.zero, globalPosition);
                actor.solver.positions[actor.solverIndices[i]] = Vector3.Lerp(states.Item1.Positions[i], states.Item2.Positions[i], interpolationFactor);
                actor.solver.invMasses[actor.solverIndices[i]] = 0;
            }
        }

This is where I actually set the particles positions in the solver:
Code:
actor.solver.positions[actor.solverIndices[i]] = Vector3.Lerp(states.Item1.Positions[i], states.Item2.Positions[i], interpolationFactor);
                actor.solver.invMasses[actor.solverIndices[i]] = 0;

Gettings lots of these:

[Image: tF2z4l3.png]}

So it looks like its trying to set invalid values for the softbody transform on Softbody script line 281

It works just fine for the ropes and its the same component that i am using to synchronize them, what can I do to track this problem down?

Hi,

You're setting particle inverse masses to zero, which in the case of softbodies requires recalculating their rest shape since the inertia tensor of the softbody changes as a result. Call UpdateParticleProperties() on the softbody after setting the particle's inverse mass. Quoting the API docs:

Quote:override void Obi.ObiSoftbody.UpdateParticleProperties()

Recalculates the shape used as reference for transform position/orientation when there are no fixed particles, as well as the rest shape matching state. Should be called manually when changing the amount of fixed particles and/ or active particles.

Note all ObiActors declare the UpdateParticleProperties() method, in some cases (like ropes) its implementation is a no-op so you can use the same code for both ropes and softbodies.
(06-12-2022, 03:03 PM)josemendez Wrote: [ -> ]Hi,

You're setting particle inverse masses to zero, which in the case of softbodies requires recalculating their rest shape since the inertia tensor of the softbody changes as a result. Call UpdateParticleProperties() on the softbody after setting the particle's inverse mass. Quoting the API docs:


Note all ObiActors declare the UpdateParticleProperties() method, in some cases (like ropes) its implementation is a no-op so you can use the same code for both ropes and softbodies.
That worked!

Should I keep setting invMasses to zero? It was a suggestion from another thread
(06-12-2022, 03:11 PM)Milionario Wrote: [ -> ]That worked!

Should I keep setting invMasses to zero? It was a suggestion from another thread

It's fine to set invMasses to zero, as that deactivates simulation and allows you to override their position. Just remember to call UpdateParticleProperties afterwards.
(06-12-2022, 03:20 PM)josemendez Wrote: [ -> ]It's fine to set invMasses to zero, as that deactivates simulation and allows you to override their position. Just remember to call UpdateParticleProperties afterwards.

Cool, also, seen some weird behaviour, the softbody does not start simulating until its touched by an ObiCollider if i set iterations to 8, if 4 it imediatelly starts simulating?

Pretty sure this is not intentional?
(06-12-2022, 06:51 PM)Milionario Wrote: [ -> ]Cool, also, seen some weird behaviour, the softbody does not start simulating until its touched by an ObiCollider if i set iterations to 8, if 4 it imediatelly starts simulating?

Pretty sure this is not intentional?

Hi,

Yes that’s intentional, it’s the solver’s sleep threshold. Try reducing it. (See: http://obi.virtualmethodstudio.com/manua...olver.html)

This is a kinetic energy threshold, which means that if you increase simulation quality the softbody’s energy will be reduced and as a result, the same threshold that would keep it awake with lower quality settings might put it to sleep now.

regards,