TextureLoader中的onLoad不起作用?

时间:2016-01-28 07:29:00

标签: javascript 3d three.js textures onload

在Three.js中使用纹理加载器,其中的onLoad函数无效,在控制台中出现错误

var TextureLoader = new THREE.TextureLoader();

boxtexture.onChange(function (value) {

    TextureLoader.load('textures/' + value,

        // onLoad callback
        function(texture){
            Box1.material.map = texture
            Box1.material.map.wrapT = THREE.RepeatWrapping;
            Box1.material.map.wrapS = THREE.RepeatWrapping;
            Box1.material.map.repeat.set(38, 38);
            Box2.material.map = texture
            Box2.material.map.wrapT = THREE.RepeatWrapping;
            Box2.material.map.wrapS = THREE.RepeatWrapping;
            Box2.material.map.repeat.set(38, 38);
        },

        // onProgress callback
        function(loaded)
        {
            load = 1;
            console.log(loaded);
            window.open(Renderer.domElement.toDataURL());
        }
    );

});

但是它没有调用onLoad函数并在控制台中给出错误消息 纹理正确加载。但我需要在加载函数时调用它。

the methods for textureLoader in three.js

console error

1 个答案:

答案 0 :(得分:0)

我只是使用three.js中的加载管理器来解决它

var manager = new THREE.LoadingManager();
manager.onLoad = function () {

// call back function when the texture gets loaded

}
var TextureLoader = new THREE.TextureLoader(manager);

TextureLoader.load('textures/', function (texture) {

 material.map = texture;

 });