三.js加载多个obj文件一个接一个 [英] Three.js load Multiple obj files one after another
问题描述
我正在使用three.js 提供的obj/mtl 加载器来加载包括mtl 在内的多个obj 文件.现在我需要加载多个对象.但我需要一个接一个地加载它们.我已经使用 THREE.DefaultLoadingManager.onProgress
添加加载屏幕".但是如何在循环中检查 loaded === total
以添加新对象.还是应该使用递归函数?
I'm using the obj/mtl loader provided by three.js to load several obj files including mtl.
Now I need to load multiple objs. But I need to load them one after another. I already used THREE.DefaultLoadingManager.onProgress
to add a "Loading Screen". But how can I check for loaded === total
within the loop for adding new objs. Or should I use a recursive function?
希望你能帮助我.谢谢
推荐答案
有一个回调函数,在加载对象时调用.在那里你可以触发下一个加载步骤.
There is a callback function that is called when an object is loaded. There you can trigger the next loading step.
var index = 0;
var files = ['file1.obj','file2.obj'];
var objLoader = new THREE.OBJLoader();
function loadNextFile() {
if (index > files.length - 1) return;
objLoader.load(files[index], function(object) {
scene.add(object);
index++;
loadNextFile();
});
}
loadNextFile();
需要扩展这个基本代码来加载材料.
This basic code needs to be extended to load materials.
这篇关于三.js加载多个obj文件一个接一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!