返回介绍

手册

参考

示例

开发者参考

DataTexture2DArray

发布于 2021-07-10 14:14:19 字数 3267 浏览 1089 评论 0 收藏 0

Creates an array of textures directly from raw data, width and height and depth. This type of texture can only be used with a WebGL 2 rendering context.

Constructor

DataTexture2DArray( data, width, height, depth )

The data argument must be an ArrayBufferView. The properties inherited from Texture are the default, except magFilter and minFilter default to THREE.NearestFilter. The properties flipY and generateMipmaps are intially set to false.

The interpretation of the data depends on type and format: If the type is THREE.UnsignedByteType, a Uint8Array will be useful for addressing the texel data. If the format is THREE.RGBAFormat, data needs four values for one texel; Red, Green, Blue and Alpha (typically the opacity). Similarly, THREE.RGBFormat specifies a format where only three values are used for each texel.
For the packed types, THREE.UnsignedShort4444Type, THREE.UnsignedShort5551Type or THREE.UnsignedShort565Type, all color components of one texel can be addressed as bitfields within an integer element of a Uint16Array.
In order to use the types THREE.FloatType and THREE.HalfFloatType, the WebGL implementation must support the respective extensions OES_texture_float and OES_texture_half_float. In order to use THREE.LinearFilter for component-wise, bilinear interpolation of the texels based on these types, the WebGL extensions OES_texture_float_linear or OES_texture_half_float_linear must also be present.

代码示例

This creates a DataTexture2DArray where each texture has a different color.

// create a buffer with color data
const width = 512;
const height = 512;
const depth = 100;
const size = width * height;
const data = new Uint8Array( 3 * size * depth );
for ( let i = 0; i < depth; i ++ ) {
  const color = new THREE.Color( Math.random(), Math.random(), Math.random() );
  const r = Math.floor( color.r * 255 );
  const g = Math.floor( color.g * 255 );
  const b = Math.floor( color.b * 255 );
  for ( let j = 0; j < size; j ++ ) {
    const stride = ( i * size + j ) * 3;
    data[ stride ] = r;
    data[ stride + 1 ] = g;
    data[ stride + 2 ] = b;
  }
}
// used the buffer to create a DataTexture2DArray
const texture = new THREE.DataTexture2DArray( data, width, height, depth );
texture.format = THREE.RGBFormat;
texture.type = THREE.UnsignedByteType;

WebGL2 / materials / texture3d

Properties

See the base Texture class for common properties.

.image : Image

Overridden with a record type holding data, width and height and depth.

Methods

See the base Texture class for common methods.

Source

src/textures/DataTexture2DArray.js

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文