从threejs中的数组生成纹理 [英] generate texture from array in threejs
问题描述
我正在尝试从threeJS中的数组生成纹理,但它没有按预期工作。
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.
如果我使用以下纹理,它会按预期工作。
http://www.html5canvastutorials.com/demos/assets/crate。 jpg
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);
推荐答案
我认为你的错误在于你制作纹理纹理。
I think your mistake is in the fact that you make a texture of a texture.
当你这样做时:
dummyDataTex = new THREE.DataTexture( dummyRGBA, 4, 4, THREE.RGBAFormat );
您在此处创建的对象 dummyDataTex
是已经类型 THREE.Texture
。
the object dummyDataTex
that you create here is already of type THREE.Texture
.
所以你的下一步:
dummyTex = new THREE.Texture(dummyDataTex);
不是必需的。你应该立即使用 dummyDataTex
。
is not necessary. You should instead immediately use dummyDataTex
.
这篇关于从threejs中的数组生成纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!