![]() |
Help Tear, Pin, Cut, Fold and Mark - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Cloth (https://obi.virtualmethodstudio.com/forum/forum-2.html) +--- Thread: Help Tear, Pin, Cut, Fold and Mark (/thread-2685.html) Pages:
1
2
|
RE: Tear, Pin, Cut, Fold and Mark - josemendez - 13-01-2022 (13-01-2022, 10:31 AM)cycle6 Wrote: Ok let's say I have 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? Code: // check if the particle index appears in the constraint: 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: (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. 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) RE: Tear, Pin, Cut, Fold and Mark - cycle6 - 13-01-2022 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 ![]() But I never thought that means you're paring em through that way. Now that totally make sense to me. Thx a lot mate ![]() 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!!! ![]() RE: Tear, Pin, Cut, Fold and Mark - josemendez - 13-01-2022 (13-01-2022, 11:04 AM)cycle6 Wrote: Ohhhh!!! so there's no class called Constraint!? Nice, that's all I needed. You're welcome ![]() (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!!! 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. |