Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Obi softbody crashes after setting inverse masses
#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


Messages In This Thread
RE: Obi softbody crashes after setting inverse masses - by Jschol - 25-10-2021, 11:08 AM