Three.js r72 - Texture marked for update but image is undefined?

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

Three.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) }) 

回答1:

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;  } 

See how it is done in http://threejs.org/examples/misc_ubiquity_test2.html.

three.js r.72



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!