I am trying to load images as data so that I can modify one with the other and then display the result as a texture. However, I am stuck on the first part and have had no success even getting one image to load.
Following the many examples online, I have tried the following sequence of commands:
let geometry, material, texture, mesh, color;
let doData = 0; // Address of destination image data
let imagloader = new ImageLoader();
let PlnObj = new Object3D();
scene.add(PlnObj);
imagloader.load('https://threejs.org/examples/textures/crate.gif', function(image) {
let canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 512;
let context = canvas.getContext('2d');
context.drawImage(image,0,0);
let imageData = context.getImageData(0,0,512,512);
d0Data = imageData.data; // save for later;
});
To see if the image has loaded, I use these commands to display the data:
texture = new DataTexture(d0Data.data, d0Size, d0Size, RGBAFormat);
material = new MeshPhongMaterial({map: texture});
mesh = new Mesh(geometry, material);
PlnObj.add(mesh);
I donât get any error messages, but all that is displayed is a dark blue plane.
Just to check I tried:
let txtrloader = new TextureLoader();
texture = txtrloader.load('https://threejs.org/examples/textures/crate.gif.jpg');
etc.
and the image displays just fine.
I looked at various examples on JSfiddle and none of them appeared to work either.
Then I remembered that I had read that the ImageLoader does not have support for progress events. So is the whole âfunction (image)â portion non operative? Is the problem that I am displaying things before they have been loaded?
I have used both three.js and the three.js module and the results are the same.