DataTexture 数据纹理

—> Texture

data 参数必须是 ArrayBuffer 或类型化数组视图. 数据的解释取决于类型和格式:如果类型为 THREE.UnsignedByteType , 则 Uint8Array 有利于 解决 texel 数据. 如果格式为 THREE.RGBAFormat , 则数据需要一个 texel 的四个值 r, g, b 和 Alpha(通常是不透明度). 类似地, THREE.RGBFormat 指定一种格式, 其中每个 texel 只使用三个值. 对于打包类型, THREE.UnsignedShort4444Type, THREE.UnsignedShort5551Type 或 THREE.UnsignedShort565Type, 一个 texel 的所有颜色分量可在 Uint16Array 的整数内的位字段来寻址. 利用 WebGLRenderer 的 copyTextureToTexture( position, srcTexture, dstTexture, level ) 或 copyFramebufferToTexture = function ( position, texture, level ) 来进行数据复制、转换.

function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) { } var loader = new THREE.TextureLoader(); diffuseMap = loader.load( '---.jpg', animation ); diffuseMap.minFilter = THREE.LinearFilter; diffuseMap.generateMipmaps = false; var material = new THREE.MeshBasicMaterial({ color: 0xffffff, map: diffuseMap }); var width = 32, height = 32, data = new Uint8Array(width * height * 3); var dataTexture = new THREE.DataTexture(data, width, height, THREE.RGBFormat); function animation(){ requestAnimationFrame(animation); var elapsedTime = clock.getElapsedTime(); if ( elapsedTime - last > 0.1 ) { last = elapsedTime; position.x = ( 32 * THREE.Math.randInt( 1, 32 ) ) - 32 ; position.y = ( 32 * THREE.Math.randInt( 1, 32 ) ) - 32 ; updateDataTexture( dataTexture ); renderer.copyTextureToTexture(position, dataTexture, diffuseMap); } renderer.render(scene, camera); } function updateDataTexture( texture ) { var size = texture.image.width * texture.image.height; var data = texture.image.data; color.setHex( Math.random() * 0xffffff ); var r = Math.floor( color.r * 255 ); var g = Math.floor( color.g * 255 ); var b = Math.floor( color.b * 255 ); for ( var i = 0; i < size; i ++ ) { var stride = i * 3; data[ stride ] = r; data[ stride + 1 ] = g; data[ stride + 2 ] = b; } }

Attributes

isDataTexture : Boolean

Default value : true (只读)
Description : 类型是否为DataTexture.

flipY : Boolean

Default value : false
Description : 是否翻转图像的 y 轴以匹配 WebGL 的纹理坐标.

generateMipmaps : Boolean

Default value : false
Description : 是否为纹理生产 mipmaps.

image : Object

Default value : { data: data, width: width, height: height }
Description : 图像信息对象.

magFilter : Integer

Default value : THREE.NearestFilter
Description : 放大滤镜, 纹理如何放大.

minFilter : Integer

Default value : THREE.NearestFilter
Description : 缩小滤镜, 纹理如何缩小.

unpackAlignment : Integer ( 1, 2, 4, 8 )

Default value : 1
Description : 指定内存中每个像素行开头的对齐要求. 允许值为 1(字节对齐), 2(与偶数字节对齐的行), 4(字对齐)和 8(从双字边界开始的行)