1

I am trying to generate a texture from an array in threeJS and it is not working as expected.

It appears that the way I generate the texture is not correct.

If I use the following texture, it works as expected. http://www.html5canvastutorials.com/demos/assets/crate.jpg

crateTex = THREE.ImageUtils.loadTexture('data/crate.jpg');

enter image description here

If I generate a dummy texture and try to display it, it is all black...

var dummyRGBA = new Uint8Array(4 * 4 * 4);
for(var i=0; i< 4 * 4; i++){
  // RGB from 0 to 255
  dummyRGBA[4*i] = dummyRGBA[4*i + 1] = dummyRGBA[4*i + 2] = 255*i/(4*4);
  // OPACITY
  dummyRGBA[4*i + 3] = 255;
}

dummyDataTex = new THREE.DataTexture( dummyRGBA, 4, 4, THREE.RGBAFormat );
dummyDataTex.needsUpdate = true;

dummyTex = new THREE.Texture(dummyDataTex);

enter image description here

1 Answer 1

4

I think your mistake is in the fact that you make a texture of a texture.

When you do:

dummyDataTex = new THREE.DataTexture( dummyRGBA, 4, 4, THREE.RGBAFormat );

the object dummyDataTex that you create here is already of type THREE.Texture.

So your next step:

dummyTex = new THREE.Texture(dummyDataTex);

is not necessary. You should instead immediately use dummyDataTex.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that fixed it. Next issue is that my "real" texture is too big to be passed (256*256*256*4) so I guess I'll have to find some work around. Does it make sense to attach 256 textures of 256*256*4 to the shader? Thanks anyway
I wouldn't know. Not that much experience with textures :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.