Ray through particle.position of a SPS digested mesh is not in the right place

Hi All,

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.


Am I missing something?

Thank you for you help.

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 ?

That said, it seems still buggy : https://playground.babylonjs.com/#R56QQU#3
Something went probably wrong either in the barycenter computation or in the BBox computation when fixing the last bug Intersection between a SPS from au digested mesh and a mesh

Investigating …

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

1 Like

not sure it’s a bug or a misunderstanding of the digested geometry : https://playground.babylonjs.com/#GE578Z#1

Seems to work here

[EDIT] https://playground.babylonjs.com/#GE578Z#2
A ray every 10 particles of 8 facets
some rays intersect no particle indeed

@JohnK or @sebavan , as I can’t dev/fix the BJS code yet, could you please add the line :

barycenter.copyFromFloats(0, 0, 0);

just after this comment Babylon.js/solidParticleSystem.ts at master · BabylonJS/Babylon.js · GitHub

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 :blush: ) …

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.

1 Like

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.

1 Like

Agree that

barycenter.copyFromFloats(0, 0, 0);

is needed in the loop to reset its value to 0. Will let @sebavan do it for same reason as before.

PR is here: Fix MRTT Parallel Shader Compile + SPS Barycenter by sebavan · Pull Request #6774 · BabylonJS/Babylon.js · GitHub

1 Like

does it fix the PG ? I mean : are there still rays passing outside the surface in this PG ?

Not sure how to fully test :frowning: Could you describe me the full procedure ?

Sorry for being dumb on this one, just want to be sure I look at the right thing.

oops I forgot the link : https://playground.babylonjs.com/#GE578Z#2

Just rotate the cam around the cylinder and check if some rays still pass outside the cylinder without intersecting it, please

Some intersect on the opposite side which is normal from what I understand but they all intersect with a red spot

yep, the “bug” was that some lines didn’t intersect at all
so : fixed



@jerome there are still rays passing outside the cylinder in your PG (https://playground.babylonjs.com/#GE578Z#2)
Here is a printSreen: image

Just wait for @sebavan 's fix to be published in the next nightly build. This should work now (tomorrow actually).

OK thank you very much,all of you.
I can’t believe in your responsiveness.