I have a SPS from a digested mesh. I try to detect which particle is in the path between a point and a box. But when I draw the ray with rayHelper, the rays are not passing through the particle but close to it. Below is a playground to illustrate.
As you can see, some rays are missing the SPS mesh.
And when I try do detect ray intersection with one box, I have some rays tagged as intersecting the box which are missing it when I draw them as in the playground below.
When you digest a mesh, the particles are created by isolating one or more successive facets of this mesh (facetNb = 2 in your example) and sticking them together. Then these particles are located in the SPS local space to the barycenter of the vertices composing them.
In your example, I suppose that the first 10 particles of the digested SPS are probably a mix of sectors from the cylinder cap and probably some facets from the cylinder side. This could a reason why the barycenter is not where you expect it. Not sure…
Actually, if you don’t know how the digested mesh geometry is designed, you’ll probably expect something different from the digesting process will product.
Say, if you still select 10 particles, but not from the first one (the cap), from the 30th to the 40th, it looks like what you maybe expect, doesn’t it ? https://playground.babylonjs.com/#R56QQU#2
Here is a slightly simplified PG Babylon.js Playground where the cylinder is yellow to see the contrast with the ray helper lines. As @jerome says you can see the difference on changing facetNb by playing with line 29
I think the variable vector barycenter is not reset to zero from a particle to the next within the loop. Not sure (abstract debugging with no dev platform ) …
Have finally (I think) worked out what the option facetNb does. It groups the facets of the mesh to form particles with facetNb facets as far as possible. When the number of facets in the mesh is not divisible by facetNb then some groups will have lower number of facets to make up the required total number. This can be seen in https://www.babylonjs-playground.com/#HDHQN#58. The green mesh shows the facets of the original mesh and the red one the facets of the particles of the digested mesh.
In this PG example with facetNb = 3 it forms particles when its grouped facets have spaces in them. It might be possible that in some cases the barycenter falls within this space and so a ray will not hit the particle. This is only a perhaps at this stage, more investigation necessary.
This is a correct argument. Unless we know exactly the mesh geometry, we can’t easily predict by using facetNb how some of the particles will be built : some barycenters can bet set off the particle surfaces and some facets may also be grouped even if they aren’t linked together on the mesh surface… just because they are successive in the mesh indice array.
digest() can’t know the geometry neither the user expectations. It just does the best it can by following the mesh indice array order and by trying to build the highest number of particles with the required facetNb value per particle.
That said, I think that the barycenter might not be correctly reset in the loop anyway.