DataTexture.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE html>
  2. <html lang="en">
  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">Creates a texture directly from raw data, width and height.</p>
  13. <h2>Constructor</h2>
  14. <h3>[name]( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding )</h3>
  15. <p>
  16. The data argument must be an [link:https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView ArrayBufferView].
  17. Further parameters correspond to the properties inherited from [page:Texture], where both magFilter and minFilter default to THREE.NearestFilter. The properties flipY and generateMipmaps are intially set to false.
  18. </p>
  19. <p>
  20. The interpretation of the data depends on type and 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). Similarly, THREE.RGBFormat specifies a format where only three values are used for each texel.<br />
  23. 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 />
  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>Code Example</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( 3 * 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 * 3;
  39. data[ stride ] = r;
  40. data[ stride + 1 ] = g;
  41. data[ stride + 2 ] = b;
  42. }
  43. // used the buffer to create a [name]
  44. const texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  45. </code>
  46. <h2>Properties</h2>
  47. <p>
  48. See the base [page:Texture Texture] class for common properties.
  49. </p>
  50. <h3>[property:Image image]</h3>
  51. <p>
  52. Overridden with a record type holding data, width and height.
  53. </p>
  54. <h2>Methods</h2>
  55. <p>
  56. See the base [page:Texture Texture] class for common methods.
  57. </p>
  58. <h2>Source</h2>
  59. <p>
  60. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  61. </p>
  62. </body>
  63. </html>