Applying anisotropic filtering on gltf model’s texture

I’m loading my gltf models into ar.js as the following. The models are binary gltf files with baked in textures. But seems like it’s not applying any anisotropic filtering to the model. I also tried separate textures exported with collada2gltf, but then the model doesn’t appeared (I think the texture is missing in this case):

const maxAnisotropy = renderer.capabilities.getMaxAnisotropy();
const loader = new THREE.GLTFLoader();
loader.load(
	// resource URL
	`${url}/model.glb`,
	// called when the resource is loaded
	(data) => {
		const gltf = data;
		const object = gltf.scene;
		object.anisotropy = maxAnisotropy;
		arWorldRoot.add(object);
	},
	// called when loading is in progresses
	(xhr) => {
		console.log(`${(xhr.loaded / xhr.total) * 100}%% loaded`);
	},
	// called when loading has errors
	(error) => {
		console.log(`An error happened: ${error}`);
	},
);

Author: Fantashit

1 thought on “Applying anisotropic filtering on gltf model’s texture

  1. Oops, my fault. If the material of a mesh does not have a diffuse map, map is null.

    const scene = gltf.scene;
    
    scene.traverse( ( object ) => {
    
       if ( object.isMesh === true && object.material.map !== null ) {
    
          object.material.map.anisotropy = maxAnisotropy;
    
       }
    
    } );

Comments are closed.