DataTexture2DArray.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:Texture] &rarr;
  12. <h1>[name]</h1>
  13. <p class="desc">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.</p>
  14. <h2>Constructor</h2>
  15. <h3>[name]( data, width, height, depth )</h3>
  16. <p>
  17. The data argument must be an [link:https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView ArrayBufferView].
  18. The properties inherited from [page:Texture] are the default, except magFilter and minFilter default to THREE.NearestFilter. The properties flipY and generateMipmaps are intially set to false.
  19. </p>
  20. <p>
  21. The interpretation of the data depends on type and format:
  22. If the type is THREE.UnsignedByteType, a Uint8Array will be useful for addressing the texel data.
  23. 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.<br />
  24. 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.<br />
  25. 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.
  26. </p>
  27. <h2>代码示例</h2>
  28. <p>This creates a [name] where each texture has a different color.</p>
  29. <code>
  30. // create a buffer with color data
  31. const width = 512;
  32. const height = 512;
  33. const depth = 100;
  34. const size = width * height;
  35. const data = new Uint8Array( 3 * size * depth );
  36. for ( let i = 0; i < depth; i ++ ) {
  37. const color = new THREE.Color( Math.random(), Math.random(), Math.random() );
  38. const r = Math.floor( color.r * 255 );
  39. const g = Math.floor( color.g * 255 );
  40. const b = Math.floor( color.b * 255 );
  41. for ( let j = 0; j < size; j ++ ) {
  42. const stride = ( i * size + j ) * 3;
  43. data[ stride ] = r;
  44. data[ stride + 1 ] = g;
  45. data[ stride + 2 ] = b;
  46. }
  47. }
  48. // used the buffer to create a [name]
  49. const texture = new THREE.DataTexture2DArray( data, width, height, depth );
  50. texture.format = THREE.RGBFormat;
  51. texture.type = THREE.UnsignedByteType;
  52. </code>
  53. <p>
  54. [example:webgl2_materials_texture3d WebGL2 / materials / texture3d]
  55. </p>
  56. <h2>Properties</h2>
  57. <p>
  58. See the base [page:Texture Texture] class for common properties.
  59. </p>
  60. <h3>[property:Image image]</h3>
  61. <p>
  62. Overridden with a record type holding data, width and height and depth.
  63. </p>
  64. <h2>Methods</h2>
  65. <p>
  66. See the base [page:Texture Texture] class for common methods.
  67. </p>
  68. <h2>Source</h2>
  69. <p>
  70. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  71. </p>
  72. </body>
  73. </html>