Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageUtils.loadTexture with callback in Canvas Renderer

i'm using three.js revision 53

when loading a texture in Canvas Renderer (IE on Win7) and adding a callback for the onLoad event, the texture is not getting displayed. When i remove the callback function, the texture is getting displayed as expected:

// NOT WORKING with callback added

var material = new THREE.MeshBasicMaterial({
            map: THREE.ImageUtils.loadTexture('text_build.png', {}, function()
            {
 //do something
            })
});
var plane = new THREE.Mesh(new THREE.PlaneGeometry(135, 135), material);
plane .overdraw = true;
scene.add(plane );

// WORKING without callback

var material = new THREE.MeshBasicMaterial({
             map: THREE.ImageUtils.loadTexture('text_build.png')
});
var plane = new THREE.Mesh(new THREE.PlaneGeometry(135, 135), material);
plane .overdraw = true;
scene.add(plane );

When running the same code in WebGL Renderer (FF,Chrome on WIn7), both examples work just fine.

Maybe someone can point me to the mistake i'm obviously doing here.

Thanks a lot.

like image 769
Jaane Jogson Avatar asked Dec 20 '12 21:12

Jaane Jogson


1 Answers

Try this:

var material = new THREE.MeshBasicMaterial({    
    map: THREE.ImageUtils.loadTexture( 'text_build.png', new THREE.UVMapping(), function() { ... } )
});
like image 95
WestLangley Avatar answered Sep 22 '22 08:09

WestLangley