Obi Official Forum
Help Matching up particles with vertices in 7.X - 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 Matching up particles with vertices in 7.X (/thread-4414.html)



Matching up particles with vertices in 7.X - CptnFabulous - 29-11-2024

I recently updated the version of Obi Cloth from 6.5.4 to 7.0.3. I checked some of the differences between Obi Cloth 7.X and 6.X:
https://obi.virtualmethodstudio.com/manual/7.0/upgrading.html

One thing mentioned is that “…blueprints may now decimate/simplify the input mesh and generate particles at positions other than the cloth vertices…”. This would result in a discrepancy between the vertices in the mesh and the particles in the cloth.

We currently have some code that procedurally generates cloth shapes, then procedurally stitches them together at certain edges. Upon further inspection, I found that the particle index list used for stitching is calculated based off the mesh’s vertex indices, rather than calculating them after the particles are generated.

This method was fine with the previous version of the package, as the vertices and particles would always match up 1:1. But now they don’t, so this sometimes causes the cloth to glitch out violently when the procedural stitching code is run.

With this new system, how can I find the cloth particles that correspond with a given set of mesh vertices, or vice versa, so I can accurately determine at runtime what particles need to be stitched together?

Or will I have to recalculate whatever criteria is used to obtain the correct vertices, but on the particles instead after they’ve been generated?

Thanks!


RE: Matching up particles with vertices in 7.X - josemendez - 29-11-2024

Hi!

Cloth blueprints now have two extra properties: a topology (of type ObiMesh) and a skinmap (of type ObiSkinMap).

The topology holds information about the simplified cloth mesh: clusters and triangles. Clusters are groups of vertices of the original mesh that have been merged together into what will eventually become a single particle: there's a 1-1 correspondence between clusters and particles in the blueprint, and they're stored in the same order. So given a particle index, you can read the corresponding cluster on the topology and retrieve the indices of the original vertices that got absorbed into that cluster.

Code:
var cluster = clothBlueprint.topology.clusters[actorParticleIndex];
foreach (var vertexIndex in cluster.vertexIndices)
{
// do something with the vertex: mesh.vertices[vertexIndex]
}

The skinmap stores deformation influences: for each vertex in the mesh, which particles influence its deformation during simulation, and the amount of influence for each one. The amount of particles influencing each vertex is variable. This is similar to how bones influence vertices for skeletal animation (essentially linear blend skinning, if you're familiar with the term). Given a mesh vertex, you can get the particles that influence its position:

Code:
var map = clothBlueprint.defaultSkinmap.particlesOnVertices;
int offset = map.influenceOffsets[vertexIndex]; // index of the first influence for this vertex.
int count = map.influenceOffsets[vertexIndex+1] - offset; // amount of influences for this vertex.
for (int i = 0; i < count; ++i)
{
   int actorParticleIndex = map.influences[offset + i].index;
}

Note that the topology and the skinmap aren't mirror images of each other: even though a vertex may not be part of a cluster, it may be influenced by that cluster/particle at runtime.

Let me know if I can be of further help,

kind regards


RE: Matching up particles with vertices in 7.X - CptnFabulous - 29-11-2024

Based on your description and example code, I think the topology/cluster code is just what I'm looking for. I'll try working with it tomorrow. Thanks!