Altering batched meshInstance's material

Hello!

I stumbled upon this weird thing when altering batched assets’s materials.
I have several assets in my scene that share the same material (1 meshInstance per asset, 1 material, different geometry). These assets are batched together into three meshInstances using PC’s auto batcher.

I use this code to alter the diffuseTex’s offset for the material:

this.testMat0 = pc.app.batcher._batchList[0].meshInstance.material;
this.testMat1 = pc.app.batcher._batchList[1].meshInstance.material;
this.testMat2 = pc.app.batcher._batchList[2].meshInstance.material;
self.testMat0.diffuseMapOffset.set(this.time * 0.5, this.time * 0.6);
self.testMat1.diffuseMapOffset.set(this.time * 0.5, this.time * 0.6);
self.testMat2.diffuseMapOffset.set(this.time * 0.5, this.time * 0.6);        
self.testMat0.update();
self.testMat1.update();
self.testMat2.update();

The thing is, this code works, but only like half of the assets are updated - and _batchList array contains only 3 batches the whole time.

The weird thing is that when I change the Batch Group’s AABB size in editor from (for example) 400 to 401, the whole things starts working just fine (every asset is now updated, not just half) - or when I set dynamic back and forth, it refreshes again and starts working (when the game is running)

So my idea is to do this “refresh” after the batch is generated? Or would it be possible to offset the diffuseTex for the material in any other way?

Thanks!

1 Like