如何对超过1个纹理进行textureLoader.load并为每个纹理分配地图名称?

时间:2019-03-29 17:06:05

标签: three.js textures

如何仅调用一次textureLoader.load并为每个纹理分配一个贴图名称,以便在所有纹理都加载后可以调用创建材质?

否则,我无法控制何时创建材质和正确分配纹理。

我在不加载mtl的情况下使用obj。

谢谢您的帮助

这是我要替换的一个函数textureLoader.load的代码

var textureLoader = new THREE.TextureLoader(manager);

var albedoM = textureLoader.load( "vaseTextures/albedo.png", onLoad, onProgress, onError );

var normalMap = textureLoader.load( "vaseTextures/normal.png", onLoad, onProgress, onError );

var aoMap = textureLoader.load( "vaseTextures/cavity.png", onLoad, onProgress, onError );   

Expected result: I call once function onLoad( texture) after the textures are loaded and saving a name for each texture, and so that I can then create one material that holds each texture and assign the textures to it.

1 个答案:

答案 0 :(得分:1)

在这种情况下,最好使用THREE.LoadingManageronLoad()回调。加载所有资源后,它将立即执行。由于您已经将THREE.LoadingManager的实例传递给纹理加载器,因此只需实现onLoad()。例如这样的

manager.onLoad = function ( ) {

    const material = new THREE.MeshPhongMaterial();
    material.map = albedoM;
    material.normalMap = normalMap;
    material.aoMap = aoMap;

    // do something with your material

};

three.js R103

相关问题