Prevent particles from passing through a mesh?

Everything is said in the title.

For example, let’s imagine a house on a piece of land. It’s raining or it’s snowing, but if you’re inside the house, the snow or the rain goes through the roof of the house, (so it’s raining in the house) which is not very logical.

Some will say that you have to deactivate the particles (I’ve already thought about it), but if you look out the window inside the house, it doesn’t rain anymore if you deactivate the particle system. So we get out of the house, and it’s raining again. Also not very logical.

Is there something like isBlocker that blocks light and lensflare from passing through a mesh, but for particles ?

Could isBLocker on the mesh also block the particles?
If not, what tricks could work for this case?

Thanks

1 Like

You might need to customize the particle update (ParticleSystem | Babylon.js Documentation) and kill the particles when they intersect your mesh.

A simpler option might be to have a really big cylindrical emitter (that emits particles from the edges) over the house and a main emitter that emits particles from the face onto the house and switch between them when you enter the house. Or maybe a small emitter over each window if that works better for perf.

1 Like

Yes but how to detect that a particle touches a mesh? Particles have no onCollide

I quite like this idea.

It would have been so much cooler if mesh.isBlocker blocked the particles too. That would simplify things so much.

SPS particles have intersection checks Physics and Solid Particles | Babylon.js Documentation (babylonjs.com), but it’s pretty costly to check for so many objects, so I like ericwood’s suggestion more :slight_smile:

1 Like

I had thought of the SPS, and I also think that detecting collisions with particles would be expensive.

I think I’ll stick with just disabling the particle system when the character enters a house.

I’m not going to be able to put “small” particles systems in front of houses windows automatically. I’m making an editor and my weather system is integrated into the game. I can’t know in advance where the buildings/houses will be placed by the users, or even where the windows of the houses will be, which makes the task very complicated to know where to put my “small” particles systems.

Hmmm this is less of a technical and more of a design suggestion but maybe you could allow users to “mark” the areas where the windows are so you would know where to put the systems?

I just thought of something.
Is there no possibility to play with layers or a zIndex (something like that) so that when you are in a building, the particles are not rendered.

It’s just an idea, not sure it changes anything between disabling the system or not rendering them with a zIndex.

I remember seeing a playground that uses ammo and has a dynamically resizing and morphing plane mesh with a ton of particles falling on it doing collision detection, so i think the preconception that perf will be bad is wrong

You could add a TransformNode to the window model and name it something like “particleEmitter” or add a reference to it to your window mesh. As you instance your window mesh, each instance will have an emitter node. Then you could search the scene for all transform nodes with that name and set up a PS for each with the node as the emitter. We do something similar where we have a special emitter node that we create because we want certain effects to radiate outward from a cylinder with the axis aligned with z so we created a node, rotated it, and used it as the emitter.

1 Like