Three.js:我是否必须为每个纹理设置各向异性纹理过滤?

时间:2016-01-26 11:35:09

标签: three.js

我是否必须为每个纹理设置各向异性纹理过滤? 我认为这很酷如果您可以为材质甚至全局场景设置各向异性水平。任何想法?

maxA = renderer.getMaxAnisotropy();

var texture1 = THREE.ImageUtils.loadTexture('models/folder/m67/o1.jpg');
texture1.anisotropy = maxA;

var texture2 = THREE.ImageUtils.loadTexture('models/folder/m67/o2.jpg');
texture2.anisotropy = maxA;

var texture3 = THREE.ImageUtils.loadTexture('models/folder/m67/c1.jpg');
texture3.anisotropy = maxA;

var texture4 = THREE.ImageUtils.loadTexture('models/folder/m67/c2.jpg');
texture4.anisotropy = maxA;

var material = {
  "logoprint": new THREE.MeshPhongMaterial({
    map: texture1
  }),
}

1 个答案:

答案 0 :(得分:3)

你可以将负载包装成一个函数,imageutils只为你提供另一个实用函数

function loadTexture( url ){
    var tex = THREE.ImageUtils.loadTexture(url);
    tex.anisotropy = MAXANISO;
    return tex;
}

澄清这里发生了什么,以及如何处理ImageUtils折旧警告:

var tl = new THREE.TextureLoader();

//calling load on it immediately returns a THREE.Texture object
var myTexture = tl.load( 'name.jpg' );

//you can also pass a callback
function onTextureLoaded( tex ){

    //tex.image contains data, because textureLoader updated it, before passing it to the callback
    handleTexture( tex )...
}
var myTexture = tl.load( 'name.jpg' , onTextureLoaded );

// myTexture is now an instance of THREE.Texture
// myTexture.image contains no data

myTexture.aniso = ...; //texture is configured , but probably waiting for data

纹理对象本身包含所有这些3d属性,如包装,映射类型和过滤。图像数据本身与此无关,无论您如何使用它,它都保持不变。 当您在纹理加载器上调用load时,它会返回一个代理 - 一个对象的引用,该对象可以被配置,操作并传递给要使用的其他对象(如材质)。 材质可以渲染空纹理。加载图像数据时,纹理会更新,下一帧将反映出来。

 var tl = new THREE.TextureLoader()

 function myCustomLoad( url ){
     var newTex = tl.load(url); //make the proxy
     newTex.prop = ... ;//config
     return newTex; //return configured texture, it will update itself 
}