Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  Rod loses initial shape when forced
#6
(14-08-2025, 01:02 PM)Qriva0 Wrote: Exactly, however I thought that maybe some precision error builds up or something, so I commented code in BendTwistBatch, to be precise those lines:
Code:
// plasticity
if (math.lengthsq(omega.value.xyz) > plasticity[i].x * plasticity[i].x)
{
    rest.value += omega.value * plasticity[i].y * deltaTime;
    restDarboux[i] = rest;
}

but it still breaks and problem persists.

I've been trying to reproduce this to no avail. Tested with a rod that's curved at rest, sliding it into a straight collider, then disabling the collider: the rod quickly recovers its initial shape. Would it be possible for you to send a repro scene, so that I can take a look at what's going on?

(14-08-2025, 01:02 PM)Qriva0 Wrote: I did something like this:
Code:
private void OnDrawGizmos()
{
    ObiRod rod = GetComponent<ObiRod>();
    if (rod == null || !rod.isLoaded)
    {
        return;
    }

    var solverConstraints = rod.solver.GetConstraintsByType(Oni.ConstraintType.BendTwist) as ObiConstraints<ObiBendTwistConstraintsBatch>;
    if (solverConstraints != null)
    {
        for (int j = 0; j < solverConstraints.batchCount; ++j)
        {
            var batch = solverConstraints.GetBatch(j) as ObiBendTwistConstraintsBatch;

            for (int i = 0; i < batch.activeConstraintCount; i++)
            {
                int indexA = batch.particleIndices[i * 2];
                int indexB = batch.particleIndices[i * 2 + 1];

                //Gizmos.DrawWireSphere(rod.solver.positions[indexA], 0.5f);
                UnityEditor.Handles.Label(rod.solver.positions[indexA], batch.restDarbouxVectors[i * 2].ToString());
                //Gizmos.color = Color.yellow;
                //Gizmos.DrawRay(rod.solver.positions[indexA], (rod.solver.orientations[indexA] * batch.restDarbouxVectors[i * 2]) * Vector3.forward);
            }
        }
    }
}

There's only one darboux vector per constraint (check API docs for ObiBendTwistConstraintsBatch), however your code assumes there's two for some reason (multiplying i by 2 when accessing batch.restDarbouxVectors). As a result you're skipping every other entry in the array, and end up reading data that's out of bounds - that's where the NaNs come from. Just remove the "*2" when accessing the restDarbouxVectors array.

kind regards,
Reply


Messages In This Thread
Rod loses initial shape when forced - by Qriva0 - 12-08-2025, 03:58 PM
RE: Rod loses initial shape when forced - by josemendez - 15-08-2025, 12:10 PM