Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Three.js r72-纹理标记为更新,但图像未定义?_Three.js - Fatal编程技术网

Three.js r72-纹理标记为更新,但图像未定义?

Three.js r72-纹理标记为更新,但图像未定义?,three.js,Three.js,3.js r72 我试图使用不同偏移和重复的同一纹理,但在我克隆纹理并应用needsUpdate后,我不断收到一个错误“纹理标记为更新,但图像未定义”。我检查克隆的纹理,图像属性未定义。克隆方法不应该引用纹理对象中纹理的源图像吗 var textures = {} var materials = {} textures.skin = THREE.ImageUtils.loadTexture('skin.png'); textures.skin.minFilter = THREE.Nearest

3.js r72

我试图使用不同偏移和重复的同一纹理,但在我克隆纹理并应用needsUpdate后,我不断收到一个错误“纹理标记为更新,但图像未定义”。我检查克隆的纹理,图像属性未定义。克隆方法不应该引用纹理对象中纹理的源图像吗

var textures = {}
var materials = {}

textures.skin = THREE.ImageUtils.loadTexture('skin.png');
textures.skin.minFilter = THREE.NearestFilter;
textures.skin.magFilter = THREE.NearestFilter;
skin.map_data.forEach(function(item) {
    var mats = []
    item.maps.forEach(function(item) {
        var tex = textures.skin.clone();
        tex.needsUpdate = true;
        tex.offset.x = ((1 / skin.width) * item.offset_x)
        tex.offset.y = ((1 / skin.height) * item.offset_y)
        tex.repeat.x = ((1 / skin.width) * item.width);
        tex.repeat.y = ((1 / skin.height) * item.height);
        var mat = new THREE.MeshBasicMaterial({
            map: tex
        });
        mats.push(mat);
    })
    materials[item.name] = new THREE.MeshFaceMaterial(mats)
})

纹理加载是异步的。您需要将大部分代码放入加载器回调中

texture = THREE.ImageUtils.loadTexture( 'filename.jpg', undefined, function() {

    // the rest of your code here...

    var tex = texture.clone();
    tex.needsUpdate = true;

}
看看这是怎么做的


three.js r.72

好的,我添加了回调,现在我在重新加载页面后得到了一个显示随机颜色的网格,纹理没有加载,所以显然我是在基本和面材质准备好之前创建网格的