I have multiple boxes that are of the same size, shape, texture etc… And I want to instead of making a new material for each box, to instead make them all share the same material
and merging them isnt an option (unless I can make them dynamic while theyre merged)
Just assign them the same material?
@aWeirdo Idk that doesnt seem to work for me
When I open the inspector it shows that theres a lot of the same material
Not sure why it wouldn’t work
var grass = new BABYLON.StandardMaterial('grassMat');
var texture = new BABYLON.Texture(`${textures}grass.jpeg`);
grass.diffuseTexture = texture;
grass.freeze();
var columns = 6;
var rows = 1;
var faceUV = new Array(6);
for (var i = 0; i < 6; i++) {
faceUV[i] = new BABYLON.Vector4(i / columns, 0, (i + 1) / columns, 1 / rows);
};
var options = {
updatable: true,
faceUV: faceUV,
wrap: true
};
let block = new BABYLON.MeshBuilder.CreateBox(
`block_${x}_${y}_${z}`,
options,
);
block.material = grass;
block.position.x = x;
block.position.y = y;
block.position.z = z;
// performance
block.material.freeze();
block.freezeWorldMatrix();
block.doNotSyncBoundingInfo = true;
block.convertToUnIndexedMesh();
The code above isnt run once, its run multiple times
Maybe thats why theres mutliple materials?
Well yeah, if you create multiple materials there’ll be multiple materials
also, if they’re completely identical, you could just create 1 and make instances
mesh.createInstance()
2 Likes
@aWeirdo Ohhhhhh my bad
I had the material things outside of the loop but still in the function
So I thought they wont repeat, now theyre outside the loop and the function and it works
Thanks
1 Like