15-10-2021, 01:07 PM
Hi all,
I am trying to write a script, that allows me to tune/set the constraints of a selected obi particle group at runtime.
If I understood correctly, I should know the offset of that actor's particle group constraints, inside the solver batch, to set the constraints.
The problem that I am facing, is that I am not able to locate the constraints from the particle group in the solver.
My idea was to loop through the constraints of the actor, and if the constraint is also present in the particle group, set the constraints.
Is this the way to go? (As I cannot seem to figure that part out).
Any help would be greatly appreciated.
- Jasper
My current implementation on setting a softbody ShapeMatchingConstraints look something like this, where I still need to fill in the "ConstraintIsInParticleGroup()" function:
I am trying to write a script, that allows me to tune/set the constraints of a selected obi particle group at runtime.
If I understood correctly, I should know the offset of that actor's particle group constraints, inside the solver batch, to set the constraints.
The problem that I am facing, is that I am not able to locate the constraints from the particle group in the solver.
My idea was to loop through the constraints of the actor, and if the constraint is also present in the particle group, set the constraints.
Is this the way to go? (As I cannot seem to figure that part out).
Any help would be greatly appreciated.
- Jasper
My current implementation on setting a softbody ShapeMatchingConstraints look something like this, where I still need to fill in the "ConstraintIsInParticleGroup()" function:
Code:
using Obi;
using System.Collections.Generic;
using UnityEngine;
public class ParticleGroupTest : MonoBehaviour
{
[SerializeField] private ObiActor obiActor = null;
[SerializeField] private ObiParticleGroup obiParticleGroup = null;
private ObiSoftbody obiSoftbody = null;
bool ConstraintIsInParticleGroup()
{
// ???
return true;
}
void Start()
{
obiSoftbody = obiActor.GetComponent<ObiSoftbody>();
}
void Update()
{
// get constraints stored in the actor:
var actorConstraints = obiSoftbody.GetConstraintsByType(Oni.ConstraintType.ShapeMatching)
as ObiConstraints<ObiShapeMatchingConstraintsBatch>;
// get runtime constraints in the solver:
var solverConstraints = obiSoftbody.solver.GetConstraintsByType(Oni.ConstraintType.ShapeMatching)
as ObiConstraints<ObiShapeMatchingConstraintsBatch>;
// get batches and offsets
List<ObiShapeMatchingConstraintsBatch> actorSoftBodyBatches = actorConstraints.batches;
List<ObiShapeMatchingConstraintsBatch> solverSoftBodyBatches = solverConstraints.batches;
List<int> offsets = obiSoftbody.solverBatchOffsets[(int)Oni.ConstraintType.ShapeMatching];
for (int i_batch = 0; i_batch < actorConstraints.batches.Count; ++i_batch) // loop over batches
for (int i_constraint = 0; i_constraint < actorSoftBodyBatches[i_batch].activeConstraintCount; ++i_constraint) // loop over constraints
if (ConstraintIsInParticleGroup())
{
int index = i_constraint + offsets[i_batch]; //apply offset to constraint index per batch
solverSoftBodyBatches[i_batch].materialParameters[index * 5] = 0.0f; // deformation resistance
solverSoftBodyBatches[i_batch].materialParameters[index * 5 + 1] = 1.0f; // plasticYield
solverSoftBodyBatches[i_batch].materialParameters[index * 5 + 2] = 1.0f; // plasticCreep;
solverSoftBodyBatches[i_batch].materialParameters[index * 5 + 3] = 1.0f; // plasticRecovery
solverSoftBodyBatches[i_batch].materialParameters[index * 5 + 4] = 1.0f; // maxDeformation
}
}