Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Obi softbody crashes after setting inverse masses
#1
Hi all,






I am trying to set the inverse masses of my obi softbody however, it crashes when settting it to a non 0 value with the error:




transform.position assign attempt for 'Cluster0' is not valid. Input position is { NaN, NaN, NaN }.



UnityEngine.TransformConfundidoet_position (UnityEngine.Vector3)



Obi.ObiSoftbodySkinner:UpdateBones (Obi.ObiActor) (at Assets/Obi/Scripts/Softbody/Rendering/ObiSoftbodySkinner.cs:130)



Obi.ObiActor:Interpolate () (at Assets/Obi/Scripts/Common/Actors/ObiActor.cs:1207)



Obi.ObiSoftbody:Interpolate () (at Assets/Obi/Scripts/Softbody/Actors/ObiSoftbody.cs:289)







I am setting the inverse masses like this:

Code:
    public void setGroupInvMasses()
    {
        foreach (int index in obiParticleGroup.particleIndices)
            obiActor.solver.invMasses[obiActor.solverIndices[index]] = inverseMasses;
    }



I also call:



Code:
ObiSoftbody.UpdateParticleProperties()
after setting the inverse masses.



Is there something I miss?




I am not sure if it is relevant but, I also change some of the shape matching constraints of the body.





Kind regards,



Jasper
Reply
#2
(25-10-2021, 10:42 AM)Jschol Wrote: I am not sure if it is relevant but, I also change some of the shape matching constraints of the body.

Hi,

How are you changing the shape matching constraints? It's fairly easy to get issues if you're not careful with indices, since none of the constraint arrays do any range/bounds checks at runtime.
Reply
#3
I loop over the constraints and particles, and if a particle is referenced in the constraint, I set the constraints. This works on its own though.
Something like this:
Code:
            // get batches and offsets
            List<ObiShapeMatchingConstraintsBatch> actorSoftBodyBatches = GetActorConstraintBatches();
            List<ObiShapeMatchingConstraintsBatch> solverSoftBodyBatches = GetSolverConstraintBatches();
            List<int> offsets = Softbody.solverBatchOffsets[(int)Oni.ConstraintType.ShapeMatching];

            for (int i_batch = 0; i_batch < actorSoftBodyBatches.Count; ++i_batch) // loop over batches   
                for (int i_constraint = 0; i_constraint < actorSoftBodyBatches[i_batch].activeConstraintCount; ++i_constraint) // constraints
                    if (ConstraintIsReferencedInParticleGroup(actorSoftBodyBatches[i_batch], i_constraint, ParticleIndices))
                    {
                        int index = i_constraint + offsets[i_batch];

                        solverSoftBodyBatches[i_batch].materialParameters[index * 5] = DeformationResistance;
                        solverSoftBodyBatches[i_batch].materialParameters[index * 5 + 1] = PlasticYield;
                        solverSoftBodyBatches[i_batch].materialParameters[index * 5 + 2] = PlasticCreep;
                        solverSoftBodyBatches[i_batch].materialParameters[index * 5 + 3] = PlasticRecovery;
                        solverSoftBodyBatches[i_batch].materialParameters[index * 5 + 4] = MaxDeformation;
                    }
        }

With:
Code:
    bool ConstraintIsReferencedInParticleGroup(ObiShapeMatchingConstraintsBatch actorSoftBodyBatch,
                                                                    int constraint_i, List<int> particlesInGroup)
    {
        // If constraint_i is reference by any (maybe even single) particle in the particle group, return true, else false
        int firstIndex = actorSoftBodyBatch.firstIndex[constraint_i]; // first index of particle affected by constraint i
        int numIndices = actorSoftBodyBatch.numIndices[constraint_i]; // amount of particles affected by constraint i

        for (int i = firstIndex; i < firstIndex + numIndices; ++i) // loop over particles affected by constraint i
        {
            int particle_index = actorSoftBodyBatch.particleIndices[i]; // get particle index
            if (particlesInGroup.Contains(particle_index)) return true;
        }
        return false;
    }
Reply