问题
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
来源:https://stackoverflow.com/questions/32984599/three-js-r72-texture-marked-for-update-but-image-is-undefined