How can I set Texture sampling on a loaded model?

I have not found any info about how can I change the texture sampling mode on a loaded model.
I am working on a pixel based game and this setting is mandatory for the project.

I have created a playground for this here:

Can anyone help me how I can set Texture.NEAREST_NEAREST sampling for the model texture?

Hello and welcome!

One needs to iterate over imported textures and change the sampling mode.
Example - https://playground.babylonjs.com/#QCU8DJ#636
You can check texture sampling mode in the Inspector:

2 Likes

Working like a charm! Thanks :slight_smile:

I’ll share the code snippet here in case anyone comes here

const task = this.assetsManager.addMeshTask(taskName, null, url("models/"), fileName);
task.onSuccess = (task) => {
  task.loadedMeshes.forEach((mesh) => {
    if (mesh.material) {
      const activeTexture = mesh.material.getActiveTextures();
      activeTexture.forEach((texture) => {
        texture.updateSamplingMode(Texture.NEAREST_NEAREST);
      });
    }
  });
};
1 Like

Snippets always help to save time for others!
Also note that if you import a model with Asset Container you have direct access to the all imported materials with container.materials property, so there is no need to iterate meshes in this case.
More info - Asset Containers | Babylon.js Documentation