| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <!DOCTYPE html>
- <html lang="zh">
- <head>
- <meta charset="utf-8" />
- <base href="../../../" />
- <script src="page.js"></script>
- <link type="text/css" rel="stylesheet" href="page.css" />
- </head>
- <body>
- [page:Texture] →
- <h1>数据纹理([name])</h1>
- <p class="desc">从原始数据(raw data)、宽(width)、高(height)来直接创建一个纹理贴图。</p>
- <h2>构造函数</h2>
- <h3>[name]( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace )</h3>
- <p>
- data 参数必须是一个 [link:https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView ArrayBufferView] 。
- 其他参数对应于继承自 [page:Texture] 的属性,其中 magFilter 与 minFilter 默认为 THREE.NearestFilter。
- </p>
- <p>
- 数据的解释取决于type与format:
- 如果类型为 THREE.UnsignedByteType,则 Uint8Array 可用于寻址纹素数据。
- 如果格式为 THREE.RGBAFormat,则每个纹素需要四个值:红色、绿色、蓝色和 Alpha(通常为不透明度)。
- 对于打包类型 THREE.UnsignedShort4444Type 和 THREE.UnsignedShort5551Type,一个纹素的所有颜色分量都可以作为 Uint16Array 整数元素内的位字段进行寻址。
- 为了使用 THREE.FloatType 和 THREE.HalfFloatType 类型,WebGL 实现必须支持相应的扩展 OES_texture_float 和 OES_texture_half_float。
- 为了使用 THREE.LinearFilter 对基于这些类型的纹素进行逐个组件的双线性插值,还必须存在 WebGL 扩展 OES_texture_float_linear 或 OES_texture_half_float_linear。
- </p>
- <h2>代码示例</h2>
- <code>
- // create a buffer with color data
- const width = 512;
- const height = 512;
- const size = width * height;
- const data = new Uint8Array( 4 * size );
- const color = new THREE.Color( 0xffffff );
- const r = Math.floor( color.r * 255 );
- const g = Math.floor( color.g * 255 );
- const b = Math.floor( color.b * 255 );
- for ( let i = 0; i < size; i ++ ) {
- const stride = i * 4;
- data[ stride ] = r;
- data[ stride + 1 ] = g;
- data[ stride + 2 ] = b;
- data[ stride + 3 ] = 255;
- }
- // used the buffer to create a [name]
- const texture = new THREE.DataTexture( data, width, height );
- texture.needsUpdate = true;
- </code>
- <h2>属性</h2>
- <p>
- 请参阅基本[page:Texture Texture]类以了解通用属性
- </p>
- <h3>[property:Boolean flipY]</h3>
- <p>
- 纹理上传到GPU时是否沿Y轴翻转。默认为false。
- </p>
- <h3>[property:Boolean generateMipmaps]</h3>
- <p>
- 是否为纹理生成 mipmap(如果可能)。默认为 `false`。
- </p>
- <h3>[property:Object image]</h3>
- <p>
- 被包含数据、宽度、高度和深度的对象覆盖。
- </p>
- <h3>[property:Boolean isDataTexture]</h3>
- <p>
- 只读属性,用于检查给定对象是否为 [name] 类型。
- </p>
- <h3>[property:number unpackAlignment]</h3>
- <p>
- 默认为1。
- 指定内存中每个像素行开始的对齐要求。
- 允许的值为1(字节对齐)、2(行对齐到偶数字节)、4(字对齐)和8(行从双字边界开始)。
- 有关详细信息,请参阅 [link:http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml glPixelStorei]。
- </p>
- <h2>方法</h2>
- <p>
- 有关常用方法,请参见 [page:Texture Texture] 类。
- </p>
- <h2>源码</h2>
- <p>
- [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
- </p>
- </body>
- </html>
|