Expose shapeID in the solid particle system position function

spinoff request from here: Coding question: reducing draw calls of multiple instanced objects

Unlike most of the PG use cases, mine are (what I’d like to call) pushing the limits. I have 30 different types of flora for a static environment. Ideally, I’d hate to even spend 2 draw calls for eye candy. But common opinion is that its proper to create 1 sps per model, which would mean 30 sps (max) for my use case with 30 slightly different position functions. So I was thinking that it would save lines of code if the shapeId was exposed in the positionfunction to function(particle, i, s, shapeId). Users can then pull the right data into the positionfunction based on which shape the particle is modelled after instead of having to create many position functions.

Apologies if shapeId is not the correct var to expose, I’d browsed the API and not yet eyeballed the source for it.

At first sight, this seems doable. I’ll check this and keep you informed.

1 Like

There is a shapeId exposed on a particle. However in the PG https://www.babylonjs-playground.com/#2FPT1A#348 I would expect it to be 0 for the triangles and 1 for the boxes - I only get the value 0. Another for you @jerome, is it a bug or my expectations?

It’s not really a bug because when the SPS is created as not updatable the particles aren’t created. So no particle at all, then no particle shapeId property. In this case, the default value is zero.
I’ll change this behavior to pass the actual real shapeId value.


Thank you! :smiley:

Done. Wait for the PR.
Now, even when using an immutable SPS, you can read the current particle shapeId in the call to the positionFunction simply with : particle.shapeId

[EDIT] so no change in the positionFunction signature, still function(particle, idx, idxInShape)


Tested, works as intended. Thank you very much! :smiley:

1 Like