Random Submesh From Set?

Hello everyone,

I’m experimenting with an example to see if I can get meshes to load randomly from an array.
Here’s the PG: https://www.babylonjs-playground.com/#QY1WYT#0

“Dude” has 5 submeshes. The code I tried below is in bold.

I tried making an array for the submesh numbers…

meshArray = [0,1,2,3,4];

Then tried adding code that would select a random number from that array…

// Dude
BABYLON.SceneLoader.ImportMesh(“him”, “/scenes/Dude/”, “Dude.babylon”, scene, function
(newMeshes2, particleSystems2, skeletons2) {
var dude = newMeshes2[meshArray[Math.floor(Math.random() * meshArray.length)]];

The last bit of code is obviously incorrect because it doesn’t work, but I’m not sure how to get only 1 submesh from the set of 5 to to randomly load :thinking:

Can you share the PG with your code? I struggle to see what you mean

Hello @Deltakosh , thanks for taking a look at this.

Here’s a PG: https://www.babylonjs-playground.com/#QY1WYT#223

You’ll see that ImportMesh is loading a submesh from an array. The goal is to have ImportMesh randomly select from the meshArray (0,1,2,3, or 4). I hope that makes sense, but if not, just let me know.

Thanks!

here we are: https://www.babylonjs-playground.com/#QY1WYT#224

Excellent, thanks! :smiley: :+1: