DataTexture.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Texture] &rarr;
  11. <h1>数据纹理([name])</h1>
  12. <p class="desc">从原始数据(raw data)、宽(width)、高(height)来直接创建一个纹理贴图。</p>
  13. <h2>构造函数</h2>
  14. <h3>[name]( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace )</h3>
  15. <p>
  16. data 参数必须是一个 [link:https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView ArrayBufferView] 。
  17. 其他参数对应于继承自 [page:Texture] 的属性,其中 magFilter 与 minFilter 默认为 THREE.NearestFilter。
  18. </p>
  19. <p>
  20. 数据的解释取决于type与format:
  21. 如果类型为 THREE.UnsignedByteType,则 Uint8Array 可用于寻址纹素数据。
  22. 如果格式为 THREE.RGBAFormat,则每个纹素需要四个值:红色、绿色、蓝色和 Alpha(通常为不透明度)。
  23. 对于打包类型 THREE.UnsignedShort4444Type 和 THREE.UnsignedShort5551Type,一个纹素的所有颜色分量都可以作为 Uint16Array 整数元素内的位字段进行寻址。
  24. 为了使用 THREE.FloatType 和 THREE.HalfFloatType 类型,WebGL 实现必须支持相应的扩展 OES_texture_float 和 OES_texture_half_float。
  25. 为了使用 THREE.LinearFilter 对基于这些类型的纹素进行逐个组件的双线性插值,还必须存在 WebGL 扩展 OES_texture_float_linear 或 OES_texture_half_float_linear。
  26. </p>
  27. <h2>代码示例</h2>
  28. <code>
  29. // create a buffer with color data
  30. const width = 512;
  31. const height = 512;
  32. const size = width * height;
  33. const data = new Uint8Array( 4 * size );
  34. const color = new THREE.Color( 0xffffff );
  35. const r = Math.floor( color.r * 255 );
  36. const g = Math.floor( color.g * 255 );
  37. const b = Math.floor( color.b * 255 );
  38. for ( let i = 0; i < size; i ++ ) {
  39. const stride = i * 4;
  40. data[ stride ] = r;
  41. data[ stride + 1 ] = g;
  42. data[ stride + 2 ] = b;
  43. data[ stride + 3 ] = 255;
  44. }
  45. // used the buffer to create a [name]
  46. const texture = new THREE.DataTexture( data, width, height );
  47. texture.needsUpdate = true;
  48. </code>
  49. <h2>属性</h2>
  50. <p>
  51. 请参阅基本[page:Texture Texture]类以了解通用属性
  52. </p>
  53. <h3>[property:Boolean flipY]</h3>
  54. <p>
  55. 纹理上传到GPU时是否沿Y轴翻转。默认为false。
  56. </p>
  57. <h3>[property:Boolean generateMipmaps]</h3>
  58. <p>
  59. 是否为纹理生成 mipmap(如果可能)。默认为 `false`。
  60. </p>
  61. <h3>[property:Object image]</h3>
  62. <p>
  63. 被包含数据、宽度、高度和深度的对象覆盖。
  64. </p>
  65. <h3>[property:Boolean isDataTexture]</h3>
  66. <p>
  67. 只读属性,用于检查给定对象是否为 [name] 类型。
  68. </p>
  69. <h3>[property:number unpackAlignment]</h3>
  70. <p>
  71. 默认为1。
  72. 指定内存中每个像素行开始的对齐要求。
  73. 允许的值为1(字节对齐)、2(行对齐到偶数字节)、4(字对齐)和8(行从双字边界开始)。
  74. 有关详细信息,请参阅 [link:http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml glPixelStorei]。
  75. </p>
  76. <h2>方法</h2>
  77. <p>
  78. 有关常用方法,请参见 [page:Texture Texture] 类。
  79. </p>
  80. <h2>源码</h2>
  81. <p>
  82. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  83. </p>
  84. </body>
  85. </html>
粤ICP备19079148号