DataArrayTexture.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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">
  13. 直接从原始数据、宽度、高度和深度创建纹理数组。
  14. </p>
  15. <h2>构造函数(Constructor)</h2>
  16. <h3>[name]( data, width, height, depth )</h3>
  17. <p>
  18. data参数必须是[link:https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView ArrayBufferView]。
  19. 默认继承自[page:Texture Texture]的属性,除了magFilter和minFilter默认为THREE.NearestFilter。
  20. 属性flipY和generateMipmaps最初设置为false。
  21. </p>
  22. <p>
  23. 数据的解释取决于类型和格式:如果类型是THREE.UnsignedByteType,则Uint8Array可用于寻址纹素数据。
  24. 如果格式为THREE.RGBAFormat,则数据需要为一个纹素提供四个值;红色、绿色、蓝色和Alpha(通常是不透明度)。
  25. 对于打包类型,THREE.UnsignedShort4444Type和THREE.UnsignedShort5551Type,一个纹素的所有颜色分量都可以作为Uint16Array的整数元素中的位域进行寻址。
  26. 为了使用THREE.FloatType和THREE.HalfFloatType类型,WebGL实现必须支持相应的扩展OES_texture_float和OES_texture_half_float。
  27. 为了将THREE.LinearFilter用于基于这些类型的纹素的分量双线性插值,还必须存在WebGL扩展OES_texture_float_linear或OES_texture_half_float_linear。
  28. </p>
  29. <h2>代码示例(Code Example)</h2>
  30. <p>这将创建一个[name],其中每个纹理都有不同的颜色。</p>
  31. <code>
  32. // 使用颜色数据创建缓冲区
  33. const width = 512;
  34. const height = 512;
  35. const depth = 100;
  36. const size = width * height;
  37. const data = new Uint8Array( 4 * size * depth );
  38. for ( let i = 0; i < depth; i ++ ) {
  39. const color = new THREE.Color( Math.random(), Math.random(), Math.random() );
  40. const r = Math.floor( color.r * 255 );
  41. const g = Math.floor( color.g * 255 );
  42. const b = Math.floor( color.b * 255 );
  43. for ( let j = 0; j < size; j ++ ) {
  44. const stride = ( i * size + j ) * 4;
  45. data[ stride ] = r;
  46. data[ stride + 1 ] = g;
  47. data[ stride + 2 ] = b;
  48. data[ stride + 3 ] = 255;
  49. }
  50. }
  51. // 使用缓冲区创建的颜色数据创建缓冲区[name]
  52. const texture = new THREE.DataArrayTexture( data, width, height, depth );
  53. texture.needsUpdate = true;
  54. </code>
  55. <h2>示例(Examples)</h2>
  56. <p>
  57. [example:webgl_texture2darray WebGL / texture2darray]<br />
  58. [example:webgl_rendertarget_texture2darray WebGL / rendertarget / texture2darray]
  59. </p>
  60. <h2>属性(Properties)</h2>
  61. <p>
  62. 请参阅基本[page:Texture Texture]类以了解通用属性
  63. </p>
  64. <h3>[property:Boolean flipY]</h3>
  65. <p>
  66. 纹理上传到GPU时是否沿Y轴翻转。默认为false。
  67. </p>
  68. <h3>[property:Boolean generateMipmaps]</h3>
  69. <p>
  70. 是否为纹理生成mipmap(如果可能)。默认为false。
  71. </p>
  72. <h3>[property:Object image]</h3>
  73. <p>
  74. 被包含数据、宽度、高度和深度的对象覆盖。
  75. </p>
  76. <h3>[property:Boolean isDataArrayTexture]</h3>
  77. <p>
  78. 只读标志,用于检查给定对象是否属于[name]类型。
  79. </p>
  80. <h3>[property:Set layerUpdates]</h3>
  81. <p>
  82. 纹理中需要更新的所有图层的集合(set)。查看 [Page:DataArrayTexture.addLayerUpdate addLayerUpdate]。
  83. </p>
  84. <h3>[property:number magFilter]</h3>
  85. <p>
  86. 当纹素覆盖多个像素时如何对纹理进行采样。默认值为[page:Textures THREE.NearestFilter],它使用最近的纹理元素的值。
  87. <br /><br />
  88. 有关详细信息,请参阅[page:Textures texture constants]页面。
  89. </p>
  90. <h3>[property:number minFilter]</h3>
  91. <p>
  92. 当纹素覆盖少于一个像素时如何对纹理进行采样。默认值为[page:Textures THREE.NearestFilter],它使用最近的纹理元素的值。
  93. <br /><br />
  94. 有关详细信息,请参阅[page:Textures texture constants]页面。
  95. </p>
  96. <h3>[property:number unpackAlignment]</h3>
  97. <p>
  98. 默认为1。
  99. 指定内存中每个像素行开始的对齐要求。
  100. 允许的值为1(字节对齐)、2(行对齐到偶数字节)、4(字对齐)和8(行从双字边界开始)。
  101. 有关详细信息,请参阅[link:https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glPixelStorei.xhtml glPixelStorei]。
  102. </p>
  103. <h3>[property:number wrapR]</h3>
  104. <p>
  105. 这定义了纹理在深度方向上的包裹方式。<br />
  106. 默认值为[page:Textures THREE.ClampToEdgeWrapping],其中边缘被夹紧到外边缘纹素。
  107. 其他两个选择是[page:Textures THREE.RepeatWrapping]和[page:Textures THREE.MirroredRepeatWrapping]。
  108. 有关详细信息,请参阅[page:Textures texture constants]页面。
  109. </p>
  110. <h2>方法(Methods)</h2>
  111. <p>
  112. 有关常用方法,请参见 [page:Texture Texture] 类。
  113. </p>
  114. <h3>[method:addLayerUpdate addLayerUpdate]( layerIndex )</h3>
  115. <p>
  116. 描述需要更新纹理的特定层。通常,当 [page:Texture.needsUpdate needsUpdate] 设置为 true 时,整个压缩纹理数组都会发送到 GPU。
  117. 标记特定层将仅传输数组中与特定深度相关的所有 mipmap 的子集,这通常可以提高性能。
  118. </p>
  119. <h3>[method:clearLayerUpdates clearLayerUpdates]()</h3>
  120. <p>
  121. 清除图层更新记录。
  122. 查看 [Page:DataArrayTexture.addLayerUpdate addLayerUpdate]。
  123. </p>
  124. <h2>源代码(Source)</h2>
  125. <p>
  126. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  127. </p>
  128. </body>
  129. </html>
粤ICP备19079148号