Three.js r72 - 纹理标记为更新但图像未定义? [英] Three.js r72 - Texture marked for update but image is undefined?
本文介绍了Three.js r72 - 纹理标记为更新但图像未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
三.js r72
我正在尝试使用具有不同偏移和重复的相同纹理,但是在我克隆纹理并应用需要更新后,我不断收到错误纹理标记为更新但图像未定义".我检查了克隆的纹理,图像属性未定义.克隆方法不应该从纹理对象中的纹理引用源图像.
I'm trying to use the same texture with different offsets and repeats, but after I clone the texture and apply needsUpdate I keep getting an error "Texture marked for update but image is undefined". I check the cloned texture and the image property is undefined. Shouldn't the clone method have referenced the source image from the texture in the textures Object.
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 loading is asynchronous. You need to put the bulk of your code in the loader callback.
texture = THREE.ImageUtils.loadTexture( 'filename.jpg', undefined, function() {
// the rest of your code here...
var tex = texture.clone();
tex.needsUpdate = true;
}
在 http://threejs.org/examples/misc_ubiquity_test2.html.
three.js r.72
three.js r.72
这篇关于Three.js r72 - 纹理标记为更新但图像未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文