How to get class from mesh


I am making a solar system. I have a javascript class (called Planet) that can be instantiated from my main.js. It accepts a few paramters and creates a planet based on that (creates a sphere mesh, puts different textures on it, sets the revolution distance from the Sun, etc.). I am able to click on each planet and make the camera target it with the mesh.isPickable = true and scene.onPointerDown = function(evt, pickResult). However, I would also need to get access to the Planet class of the given planet (because I need the data from it), and I have no clue how can I do that.

Can anybody help me?

I solved it! Will post the solution here, for anyone who is interested.

I have previously stored all my Planet objects (so basically the classes) in an array. So once I got the mesh from the mouseclick, I loop through the list and compare the mesh with the mesh property of each planet. If there is a match, I save the index of the planet, and whenever I want to get access to data related to the planet, I get it from the list using the index value.


Hello and welcome!

You may use mesh.metadata object for this purpose - Babylon.js Playground