Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Tear, Pin, Cut, Fold and Mark
#11
(13-01-2022, 10:31 AM)cycle6 Wrote: Ok let's say I have 
    int startPatical = solver.simplexCounts.GetSimplexStartAndSize(results.simplexIndex, out int simplexSize);
I'm assuming I can use "startPatical" as a reference to compare with all the particles in a constraint? So first, I just wanna confirm if "startPatical" is the correct parameter I can use?

The first particle in the simplex is just that, the first particle in the simplex in no particular order. A triangular simplex has 3 particles, which one of them to use depends entirely on what you want to do.


(13-01-2022, 10:31 AM)cycle6 Wrote: //here how do I get a constraint?
//and how do I check if startPatical is in that constraint?

Code:
// check if the particle index appears in the constraint:
if (theFirstBatch.particleIndices[/*depends o the specific type of constraint*/] == startParticle)
{
}

Each distance constraint joins 2 particles, so for distance constraints you would access the batch this way:

Code:
// check if the particle index appears in the constraint:
if (theFirstBatch.particleIndices[i*2] == startParticle)
{
// your particle is the first one in this distance constraint.
}
if (theFirstBatch.particleIndices[i*2+1] == startParticle)
{
// your particle is the second one in this distance constraint.
}


(13-01-2022, 10:31 AM)cycle6 Wrote: OK how do I get a constraint from the batch?

You don't. Constraints aren't classes or structs, neither are particles. Obi is fully data-oriented (just like Unity's DOTS) so everything is stored in flat arrays for efficient multithreading and good spatial locality. So to get the data for a constraint or a particle, all you do is access an array at a specific index.

(13-01-2022, 10:31 AM)cycle6 Wrote: There's no "theFirstBatch.ActiveConstraints[i]" or "theFirstBatch.GetConstraint(int index)", so how do I get each constraint object from the batch by iteration? And after that, how do I test if "startPatical" is in a constraint?

You simply access the batch arrays. Depending on the specific constraint type, the arrays available in the batch change. Refer to the API docs for more info. For instance, a distance batch has the following arrays (copy-pasting from the docs):

Quote:ObiConstraintsBatch.particleIndices: two particle indices per constraint.
ObiDistanceConstraintsBatch.restLengths: Rest distance for each individual constraint.
ObiDistanceConstraintsBatch.stiffnesses: 2 values for each constraint: compliance and slack.

Since there's two particles for each constraint, to access the first particle index in constraint N you do:

Code:
batch.particleIndices[N*2];

Then to check if it's the same particle in your simplex, you just compare them:

Code:
if (batch.particleIndices[N*2] == myParticle)
Reply


Messages In This Thread
Tear, Pin, Cut, Fold and Mark - by Valerize - 06-01-2021, 11:35 AM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 06-01-2021, 01:04 PM
RE: Tear, Pin, Cut, Fold and Mark - by Valerize - 07-01-2021, 09:03 PM
RE: Tear, Pin, Cut, Fold and Mark - by Valerize - 16-03-2021, 06:17 PM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 17-03-2021, 08:54 AM
RE: Tear, Pin, Cut, Fold and Mark - by Valerize - 18-03-2021, 10:21 AM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 18-03-2021, 10:55 AM
RE: Tear, Pin, Cut, Fold and Mark - by cycle6 - 13-01-2022, 01:58 AM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 13-01-2022, 09:37 AM
RE: Tear, Pin, Cut, Fold and Mark - by cycle6 - 13-01-2022, 10:31 AM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 13-01-2022, 10:50 AM
RE: Tear, Pin, Cut, Fold and Mark - by cycle6 - 13-01-2022, 11:04 AM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 13-01-2022, 11:36 AM