textureLoader.load如何为多个纹理添加纹理并为每个纹理指定地图名称?

问题描述 投票:0回答:1

我怎么能只调用一次textureLoader.load并为每个纹理分配一个地图名称,以便在加载所有纹理时我可以调用它来创建材质?

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

我正在使用obj而不加载mtl。

谢谢您的帮助

这是我要求替换一个函数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.
three.js textures
1个回答
1
投票

在这种情况下,最好使用onLoad()回调THREE.LoadingManager。它将在加载所有资源后立即执行。由于您已经将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

© www.soinside.com 2019 - 2024. All rights reserved.