DataTexture.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. If the type is THREE.UnsignedByteType, a Uint8Array will be useful for addressing the texel data.
  22. If the format is THREE.RGBAFormat, data needs four values for one texel; Red, Green, Blue and Alpha (typically the opacity).<br />
  23. For the packed types, THREE.UnsignedShort4444Type and THREE.UnsignedShort5551Type all color components of one texel can be addressed as bitfields within an integer element of a Uint16Array.<br />
  24. 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.
  25. </p>
  26. <h2>代码示例</h2>
  27. <code>
  28. // create a buffer with color data
  29. const width = 512;
  30. const height = 512;
  31. const size = width * height;
  32. const data = new Uint8Array( 4 * size );
  33. const color = new THREE.Color( 0xffffff );
  34. const r = Math.floor( color.r * 255 );
  35. const g = Math.floor( color.g * 255 );
  36. const b = Math.floor( color.b * 255 );
  37. for ( let i = 0; i < size; i ++ ) {
  38. const stride = i * 4;
  39. data[ stride ] = r;
  40. data[ stride + 1 ] = g;
  41. data[ stride + 2 ] = b;
  42. data[ stride + 3 ] = 255;
  43. }
  44. // used the buffer to create a [name]
  45. const texture = new THREE.DataTexture( data, width, height );
  46. texture.needsUpdate = true;
  47. </code>
  48. <h2>属性</h2>
  49. <p>
  50. See the base [page:Texture Texture] class for common properties.
  51. </p>
  52. <h3>[property:Boolean flipY]</h3>
  53. <p>
  54. If set to *true*, the texture is flipped along the vertical axis when uploaded to the GPU. Default is *false*.
  55. </p>
  56. <h3>[property:Boolean generateMipmaps]</h3>
  57. <p>
  58. Whether to generate mipmaps (if possible) for a texture. False by default.
  59. </p>
  60. <h3>[property:Object image]</h3>
  61. <p>
  62. Overridden with a record type holding data, width and height.
  63. </p>
  64. <h3>[property:Boolean isDataTexture]</h3>
  65. <p>
  66. Read-only flag to check if a given object is of type [name].
  67. </p>
  68. <h3>[property:number unpackAlignment]</h3>
  69. <p>
  70. 1 by default. Specifies the alignment requirements for the start of each pixel row in memory.
  71. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes),
  72. 4 (word-alignment), and 8 (rows start on double-word boundaries).
  73. See [link:http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml glPixelStorei]
  74. for more information.
  75. </p>
  76. <h2>方法</h2>
  77. <p>
  78. See the base [page:Texture Texture] class for common methods.
  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>