Tag / Metadata on SolidParticle

In the Babylon project that I’m working on, each SolidParticle relates to a real world object. When the user picks a particle, I do a web call to get information on that object.

At the moment, in the initParticles method I do a very non-Typescript-like

(<any>particle).tag = this.myObjectArray[p].id;

to create a new property on the particle and assign it to the read world object Id. I can then read that tag back out when the particle is picked.

It would be nice to have “official” support for this in the way that a Mesh has the metadata property.

There is also the issue that if you do the above in the particlePosition method, the added property (tag in this case) gets removed. (I’m not totally sure why, maybe the object properties are copied).

1 Like

maybe it is useful “officially”, idk.

Great topic nick. Good to see you back.

Also, is easily possible to use a different pattern, a LOOKUP pattern.

Can you give the particle a unique ID?

If so, then consider a lookup in a completely separate (and custom) state matrix.

There are additional advantages to choosing that approach.

It used to be called Namespace design pattern.

Now reduced to: state and context.

Depending who you talk to.

~ : )-.

adding @jerome

It’s definitely possible to code around it in various ways. The SolidParticle does have a unique, immutable id given by Babylon.

However, I have 30k of these “things” as particles in my scene. Updating them all and having to do a lookup to get the real world ID, then another lookup with the real world object is all overhead.

When they are deleted or add I also have to keep the lookup table in sync etc.

1 Like

makes sense. I see what you are looking for now. : )

Well, it’s a concern beyond the solid particles themselves. It’s related to each BJS entity or any other framework provided entity.
Depending on the language capabilities, you can in this case either :

  • maintain a side appart object of your own holding your logic data, what you’re doing with all expected the syncing issues and all the lookup performance problems
  • or extend/modify, if possible, the class of the object provided by the framework, what would probably lead to a framework recompilation or rebuild.

I think that none of both these options fits your need.

So if everyone is ok, I can implement the feature to add some optional properties to the Solid Particle object. Something, maybe, that could be instanciated from the SPS constructor (let me know the name that you prefer) if TypeScript allows this (not sure at this time) :

var sps = new BABYLON.SolidParticleSystem("sps", {particleCustomProperties: ["myProperty1", "myProperty2"]}, scene);
\\ this would lead to give each solid particle 
\\ the properties "myProperty1" and "myProperty2" typed as "Any"
var particle = sps.particles[i];
particle.myProperty1 = myValue1;
particle.myProperty2 = myValue2;

More generally, maybe this kind of feature could be implemented at a higher level for each BJS object constructor so this could solve the framework object to logic object linking issue for anything and anyone.