generate texture from array in threejs

江枫思渺然 提交于 2019-12-08 06:54:38

问题


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');

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


回答1:


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.



来源:https://stackoverflow.com/questions/28188775/generate-texture-from-array-in-threejs

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