Texture.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. <h1>[name]</h1>
  11. <p class="desc">
  12. Create a texture to apply to a surface or as a reflection or refraction
  13. map.
  14. </p>
  15. <p>
  16. Note: After the initial use of a texture, its dimensions, format, and type
  17. cannot be changed. Instead, call [page:.dispose]() on the texture and
  18. instantiate a new one.
  19. </p>
  20. <h2>Code Example</h2>
  21. <code>
  22. // load a texture, set wrap mode to repeat
  23. const texture = new THREE.TextureLoader().load( "textures/water.jpg" );
  24. texture.wrapS = THREE.RepeatWrapping;
  25. texture.wrapT = THREE.RepeatWrapping;
  26. texture.repeat.set( 4, 4 );
  27. </code>
  28. <h2>Constructor</h2>
  29. <h3>
  30. [name]( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type,
  31. anisotropy, colorSpace )
  32. </h3>
  33. <h2>Properties</h2>
  34. <h3>[property:Integer id]</h3>
  35. <p>Readonly - unique number for this texture instance.</p>
  36. <h3>[property:Boolean isTexture]</h3>
  37. <p>Read-only flag to check if a given object is of type [name].</p>
  38. <h3>[property:String uuid]</h3>
  39. <p>
  40. [link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] of
  41. this object instance. This gets automatically assigned, so this shouldn't
  42. be edited.
  43. </p>
  44. <h3>[property:String name]</h3>
  45. <p>
  46. Optional name of the object (doesn't need to be unique). Default is an
  47. empty string.
  48. </p>
  49. <h3>[property:Image image]</h3>
  50. <p>
  51. An image object, typically created using the [page:TextureLoader.load]
  52. method. This can be any image (e.g., PNG, JPG, GIF, DDS) or video (e.g.,
  53. MP4, OGG/OGV) type supported by three.js.<br /><br />
  54. To use video as a texture you need to have a playing HTML5 video element
  55. as a source for your texture image and continuously update this texture as
  56. long as video is playing - the [page:VideoTexture VideoTexture] class
  57. handles this automatically.
  58. </p>
  59. <h3>[property:Array mipmaps]</h3>
  60. <p>Array of user-specified mipmaps (optional).</p>
  61. <h3>[property:number mapping]</h3>
  62. <p>
  63. How the image is applied to the object. An object type of [page:Textures THREE.UVMapping]
  64. is the default, where the U,V coordinates are used to
  65. apply the map.<br />
  66. See the [page:Textures texture constants] page for other mapping types.
  67. </p>
  68. <h3>[property:Integer channel]</h3>
  69. <p>
  70. Lets you select the uv attribute to map the texture to. `0` for `uv`,
  71. `1` for `uv1`, `2` for `uv2` and `3` for `uv3`.
  72. </p>
  73. <h3>[property:number wrapS]</h3>
  74. <p>
  75. This defines how the texture is wrapped horizontally and corresponds to
  76. *U* in UV mapping.<br />
  77. The default is [page:Textures THREE.ClampToEdgeWrapping], where the edge
  78. is clamped to the outer edge texels. The other two choices are
  79. [page:Textures THREE.RepeatWrapping] and [page:Textures THREE.MirroredRepeatWrapping].
  80. See the [page:Textures texture constants]
  81. page for details.
  82. </p>
  83. <h3>[property:number wrapT]</h3>
  84. <p>
  85. This defines how the texture is wrapped vertically and corresponds to *V*
  86. in UV mapping.<br />
  87. The same choices are available as for [property:number wrapS].<br /><br />
  88. NOTE: tiling of images in textures only functions if image dimensions are
  89. powers of two (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, ...) in
  90. terms of pixels. Individual dimensions need not be equal, but each must be
  91. a power of two. This is a limitation of WebGL, not three.js.
  92. </p>
  93. <h3>[property:number magFilter]</h3>
  94. <p>
  95. How the texture is sampled when a texel covers more than one pixel. The
  96. default is [page:Textures THREE.LinearFilter], which takes the four
  97. closest texels and bilinearly interpolates among them. The other option is
  98. [page:Textures THREE.NearestFilter], which uses the value of the closest
  99. texel.<br />
  100. See the [page:Textures texture constants] page for details.
  101. </p>
  102. <h3>[property:number minFilter]</h3>
  103. <p>
  104. How the texture is sampled when a texel covers less than one pixel. The
  105. default is [page:Textures THREE.LinearMipmapLinearFilter], which uses
  106. mipmapping and a trilinear filter. <br /><br />
  107. See the [page:Textures texture constants] page for all possible choices.
  108. </p>
  109. <h3>[property:number anisotropy]</h3>
  110. <p>
  111. The number of samples taken along the axis through the pixel that has the
  112. highest density of texels. By default, this value is `1`. A higher value
  113. gives a less blurry result than a basic mipmap, at the cost of more
  114. texture samples being used. Use [page:WebGLRenderer.capabilities renderer.capabilities.getMaxAnisotropy]()
  115. to find the maximum valid anisotropy value for the GPU; this value is usually a power of 2.
  116. </p>
  117. <h3>[property:number format]</h3>
  118. <p>
  119. The default is [page:Textures THREE.RGBAFormat].<br /><br />
  120. See the [page:Textures texture constants] page for details of other
  121. formats.
  122. </p>
  123. <h3>[property:String internalFormat]</h3>
  124. <p>
  125. The default value is obtained using a combination of [page:Texture.format .format] and [page:Texture.type .type].<br />
  126. The GPU format allows the developer to specify how the data is going to be
  127. stored on the GPU.<br /><br />
  128. See the [page:Textures texture constants] page for details regarding all
  129. supported internal formats.
  130. </p>
  131. <h3>[property:number type]</h3>
  132. <p>
  133. This must correspond to the [page:Texture.format .format]. The default is
  134. [page:Textures THREE.UnsignedByteType], which will be used for most
  135. texture formats.<br /><br />
  136. See the [page:Textures texture constants] page for details of other
  137. formats.
  138. </p>
  139. <h3>[property:Vector2 offset]</h3>
  140. <p>
  141. How much a single repetition of the texture is offset from the beginning,
  142. in each direction U and V. Typical range is `0.0` to `1.0`.
  143. </p>
  144. <h3>[property:Vector2 repeat]</h3>
  145. <p>
  146. How many times the texture is repeated across the surface, in each
  147. direction U and V. If repeat is set greater than 1 in either direction,
  148. the corresponding Wrap parameter should also be set to [page:Textures THREE.RepeatWrapping]
  149. or [page:Textures THREE.MirroredRepeatWrapping] to
  150. achieve the desired tiling effect.
  151. </p>
  152. <h3>[property:number rotation]</h3>
  153. <p>
  154. How much the texture is rotated around the center point, in radians.
  155. Positive values are counter-clockwise. Default is `0`.
  156. </p>
  157. <h3>[property:Vector2 center]</h3>
  158. <p>
  159. The point around which rotation occurs. A value of (0.5, 0.5) corresponds
  160. to the center of the texture. Default is (0, 0), the lower left.
  161. </p>
  162. <h3>[property:Boolean matrixAutoUpdate]</h3>
  163. <p>
  164. Whether to update the texture's uv-transform [page:Texture.matrix .matrix]
  165. from the texture properties [page:Texture.offset .offset],
  166. [page:Texture.repeat .repeat], [page:Texture.rotation .rotation], and
  167. [page:Texture.center .center]. True by default. Set this to false if you
  168. are specifying the uv-transform matrix directly.
  169. </p>
  170. <h3>[property:Matrix3 matrix]</h3>
  171. <p>
  172. The uv-transform matrix for the texture. Updated by the renderer from the
  173. texture properties [page:Texture.offset .offset], [page:Texture.repeat .repeat],
  174. [page:Texture.rotation .rotation], and [page:Texture.center .center]
  175. when the texture's [page:Texture.matrixAutoUpdate .matrixAutoUpdate]
  176. property is true. When [page:Texture.matrixAutoUpdate .matrixAutoUpdate]
  177. property is false, this matrix may be set manually.
  178. Default is the identity matrix.
  179. </p>
  180. <h3>[property:Boolean generateMipmaps]</h3>
  181. <p>
  182. Whether to generate mipmaps (if possible) for a texture. True by default.
  183. Set this to false if you are creating mipmaps manually.
  184. </p>
  185. <h3>[property:Boolean premultiplyAlpha]</h3>
  186. <p>
  187. If set to `true`, the alpha channel, if present, is multiplied into the
  188. color channels when the texture is uploaded to the GPU. Default is
  189. `false`.<br /><br />
  190. Note that this property has no effect for
  191. [link:https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap ImageBitmap].
  192. You need to configure on bitmap creation instead. See
  193. [page:ImageBitmapLoader].
  194. </p>
  195. <h3>[property:Boolean flipY]</h3>
  196. <p>
  197. If set to `true`, the texture is flipped along the vertical axis when
  198. uploaded to the GPU. Default is `true`.<br /><br />
  199. Note that this property has no effect for
  200. [link:https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap ImageBitmap].
  201. You need to configure on bitmap creation instead. See
  202. [page:ImageBitmapLoader].
  203. </p>
  204. <h3>[property:number unpackAlignment]</h3>
  205. <p>
  206. 4 by default. Specifies the alignment requirements for the start of each
  207. pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows
  208. aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on
  209. double-word boundaries). See
  210. [link:http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml glPixelStorei] for more information.
  211. </p>
  212. <h3>[property:string colorSpace]</h3>
  213. <p>
  214. [page:Textures THREE.NoColorSpace] is the default. Textures containing color data should be
  215. annotated with [page:Textures THREE.SRGBColorSpace] or
  216. [page:Textures THREE.LinearSRGBColorSpace].
  217. </p>
  218. <h3>[property:Integer version]</h3>
  219. <p>
  220. This starts at `0` and counts how many times [page:Texture.needsUpdate .needsUpdate] is set to `true`.
  221. </p>
  222. <h3>[property:Function onUpdate]</h3>
  223. <p>
  224. A callback function, called when the texture is updated (e.g., when
  225. needsUpdate has been set to true and then the texture is used).
  226. </p>
  227. <h3>[property:Boolean needsUpdate]</h3>
  228. <p>
  229. Set this to `true` to trigger an update next time the texture is used.
  230. Particularly important for setting the wrap mode.
  231. </p>
  232. <h3>[property:Object userData]</h3>
  233. <p>
  234. An object that can be used to store custom data about the texture. It
  235. should not hold references to functions as these will not be cloned.
  236. Default is an empty object `{}`.
  237. </p>
  238. <h3>[property:Source source]</h3>
  239. <p>
  240. The data definition of a texture. A reference to the data source can be
  241. shared across textures. This is often useful in context of spritesheets
  242. where multiple textures render the same data but with different texture
  243. transformations.
  244. </p>
  245. <h2>Methods</h2>
  246. <p>
  247. [page:EventDispatcher EventDispatcher] methods are available on this
  248. class.
  249. </p>
  250. <h3>[method:undefined updateMatrix]()</h3>
  251. <p>
  252. Update the texture's uv-transform [page:Texture.matrix .matrix] from the
  253. texture properties [page:Texture.offset .offset], [page:Texture.repeat .repeat],
  254. [page:Texture.rotation .rotation], and [page:Texture.center .center].
  255. </p>
  256. <h3>[method:Texture clone]()</h3>
  257. <p>
  258. Make copy of the texture. Note this is not a "deep copy", the image is
  259. shared. Besides, cloning a texture does not automatically mark it for a
  260. texture upload. You have to set [page:Texture.needsUpdate .needsUpdate] to
  261. true as soon as its image property (the data source) is fully loaded or
  262. ready.
  263. </p>
  264. <h3>[method:Object toJSON]( [param:Object meta] )</h3>
  265. <p>
  266. meta -- optional object containing metadata.<br />
  267. Convert the texture to three.js
  268. [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format].
  269. </p>
  270. <h3>[method:undefined dispose]()</h3>
  271. <p>
  272. Frees the GPU-related resources allocated by this instance. Call this
  273. method whenever this instance is no longer used in your app.
  274. </p>
  275. <h3>[method:Vector2 transformUv]( [param:Vector2 uv] )</h3>
  276. <p>
  277. Transform the uv based on the value of this texture's [page:Texture.offset .offset],
  278. [page:Texture.repeat .repeat], [page:Texture.wrapS .wrapS],
  279. [page:Texture.wrapT .wrapT] and [page:Texture.flipY .flipY] properties.
  280. </p>
  281. <h2>Source</h2>
  282. <p>
  283. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  284. </p>
  285. </body>
  286. </html>