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
#12
Ohhhh!!! so there's no class called Constraint!? Nice, that's all I needed.
I was looking at the codes like particleIndices[index * 2] and I was thinking: that's odd ... ly strange Guiño.
But I never thought that means you're paring em through that way. Now that totally make sense to me.
Thx a lot mate Gran sonrisa

Ohhhh now I get it!!! That's why in a single batch there's no two adjacent constraints connecting to the same particle!! because you don't want store the same particle more than once in the same batch?!! Dawg, that's pretty smart!!! Gran sonrisa
Reply
#13
(13-01-2022, 11:04 AM)cycle6 Wrote: Ohhhh!!! so there's no class called Constraint!? Nice, that's all I needed.
I was looking at the codes like particleIndices[index * 2] and I was thinking: that's odd ... ly strange Guiño.
But I never thought that means you're paring em through that way. Now that totally make sense to me.
Thx a lot mate Gran sonrisa


You're welcome Sonrisa. Let me know if you need any help.

(13-01-2022, 11:04 AM)cycle6 Wrote: Ohhhh now I get it!!! That's why in a single batch there's no two adjacent constraints connecting to the same particle!! because you don't want store the same particle more than once in the same batch?!! Dawg, that's pretty smart!!! Gran sonrisa

Exactly! that way all constraints in each batch can be processed in parallel with no need for thread synchronization, because it guarantees two threads cannot modify the same particle simultaneously and step on each other's toes.

If you're curious about it, batches are generated when you create the blueprint using graph coloring.
Reply