Javascript JS语法问题或在一个周期内使用three.JS three.ImageLoader

Javascript JS语法问题或在一个周期内使用three.JS three.ImageLoader,javascript,three.js,Javascript,Three.js,想想它的javascript语法问题,然后是three.js,但仍然。。 我有一个对象“o={}”,其纹理存储如下 o = { ... textures: { one: { low: { t: new THREE.Texture(), url: 'http://i.imgur.com/tJ0uJPt.jpg' }, normal: { t: new THREE.Texture(), url: 'http://i.

想想它的javascript语法问题,然后是three.js,但仍然。。 我有一个对象“o={}”,其纹理存储如下

o = {
    ...
    textures: {
        one: {  
            low: { t: new THREE.Texture(), url: 'http://i.imgur.com/tJ0uJPt.jpg' },
            normal: { t: new THREE.Texture(), url: 'http://i.imgur.com/wBB1nZN.jpg' }
        },
        two: {  
            low: { t: new THREE.Texture(), url: 'http://i.imgur.com/9JaoZNA.jpg' },
            normal: { t: new THREE.Texture(), url: 'http://i.imgur.com/p9wO18t.jpg' }
            hd: ...
            etc..
        }

        etc..
    }
    ...
}
我需要的是一个函数,它可以使用THREE.ImageLoader加载所有这些纹理。 此外,当加载所有纹理时,我希望运行o.texturesOnLoad();功能

(function(obj, texture) {
    if (current == total) {
        // last texture
        loader.load( texture.url, function (image){
            texture.t.image = image;
            texture.t.needsUpdate = true;

            obj.texturesOnLoad();
        });
    } else {
        loader.load( texture.url, function (image){
            texture.t.image = image;
            texture.t.needsUpdate = true;
        });
    }
})(this, this.textures[texture][quality]);
这就是我现在拥有的 但是只有o.textures的最后一个纹理在工作。。认为我以错误的方式将变量传递给loader.load(…)


希望任何人都能帮助我,谢谢。

我通过在自动执行函数中包装loader.load(…)找到了解决方案

(function(obj, texture) {
    if (current == total) {
        // last texture
        loader.load( texture.url, function (image){
            texture.t.image = image;
            texture.t.needsUpdate = true;

            obj.texturesOnLoad();
        });
    } else {
        loader.load( texture.url, function (image){
            texture.t.image = image;
            texture.t.needsUpdate = true;
        });
    }
})(this, this.textures[texture][quality]);