Random Texture for Imported Mesh or Instance?

Hello everyone,

I’ve had no trouble assigning random textures to clones, but I’m having difficulty doing the same for imported meshes. Here are the goals for my project:

Goal 1: Assign random textures from an array to an imported mesh (or to the instances generated from this mesh).

Goal 2: Based on which texture a mesh receives, create a unique result for that mesh. For example:

if texture 1–mesh.position.x += 1;
or…
if texture 2–mesh.rotation.y += 2;

Here’s an example PG I’ve been using to work on these goals:
https://www.babylonjs-playground.com/#L5EB6B

You’ll notice that each the clone parents are assigned 1 of the 3 random textures. The imported mesh (and its instances) receive a random texture also, but it’s the same for all of them.

You’ll also notice my failed attempt at Goal 2 commented out :confused:

Any help or suggestions would be greatly appreciated! :smiley: :+1:

Hey!

Instances cannot get a different textures (or a different material) than parents

Hey @Deltakosh!

I see, that’s helpful to know. Is it also not possible to randomly assign textures to the imported mesh directly (before instances are created)?

That should work but in your case you are applying the material on every loop

Excellent, I’ll give that a try then. Thanks! :smiley: :+1: