Texture.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. <h1>纹理([name])</h1>
  11. <p class="desc">创建一个纹理贴图,将其应用到一个表面,或者作为反射/折射贴图。</p>
  12. <h2>构造函数</h2>
  13. <h3>[name]( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding )</h3>
  14. <h2>代码示例</h2>
  15. <code>
  16. // load a texture, set wrap mode to repeat
  17. const texture = new THREE.TextureLoader().load( "textures/water.jpg" );
  18. texture.wrapS = THREE.RepeatWrapping;
  19. texture.wrapT = THREE.RepeatWrapping;
  20. texture.repeat.set( 4, 4 );
  21. </code>
  22. <h2>属性</h2>
  23. <h3>[property:Integer id]</h3>
  24. <p>
  25. 只读 - 表示该纹理实例的唯一数字。
  26. </p>
  27. <h3>[property:Boolean isTexture]</h3>
  28. <p>
  29. Read-only flag to check if a given object is of type [name].
  30. </p>
  31. <h3>[property:String uuid]</h3>
  32. <p>
  33. 该对象实例的[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID]。
  34. 这个值是自动分配的,因此不应当对其进行编辑。
  35. </p>
  36. <h3>[property:String name]</h3>
  37. <p>
  38. 该对象的名称,可选,且无需唯一。默认值是一个空字符串。
  39. </p>
  40. <h3>[property:Image image]</h3>
  41. <p>
  42. 一个图片对象,通常由[page:TextureLoader.load]方法创建。
  43. 该对象可以是被three.js所支持的任意图片(例如PNG、JPG、GIF、DDS)或视频(例如MP4、OGG/OGV)格式。<br /><br />
  44. 要使用视频来作为纹理贴图,你需要有一个正在播放的HTML5 Video元素来作为你纹理贴图的源图像,
  45. 并在视频播放时不断地更新这个纹理贴图。——[page:VideoTexture VideoTexture] 类会对此自动进行处理。
  46. </p>
  47. <h3>[property:Array mipmaps]</h3>
  48. <p>
  49. 用户所给定的mipmap数组(可选)。
  50. </p>
  51. <h3>[property:number mapping]</h3>
  52. <p>
  53. 图像将如何应用到物体(对象)上。默认值是[page:Textures THREE.UVMapping]对象类型,
  54. 即UV坐标将被用于纹理映射。<br />
  55. 请参阅[page:Textures texture constants](映射模式常量)来了解其他映射类型。
  56. </p>
  57. <h3>[property:number wrapS]</h3>
  58. <p>
  59. 这个值定义了纹理贴图在水平方向上将如何包裹,在UV映射中对应于*U*。<br />
  60. 默认值是[page:Textures THREE.ClampToEdgeWrapping],即纹理边缘将被推到外部边缘的纹素。
  61. 其它的两个选项分别是[page:Textures THREE.RepeatWrapping]和[page:Textures THREE.MirroredRepeatWrapping]。
  62. 请参阅[page:Textures texture constants]来了解详细信息。
  63. </p>
  64. <h3>[property:number wrapT]</h3>
  65. <p>
  66. 这个值定义了纹理贴图在垂直方向上将如何包裹,在UV映射中对应于*V*。<br />
  67. 可以使用与[property:number wrapS]相同的选项。<br /><br />
  68. 请注意:纹理中图像的平铺,仅有当图像大小(以像素为单位)为2的幂(2、4、8、16、32、64、128、256、512、1024、2048、……)时才起作用。
  69. 宽度、高度无需相等,但每个维度的长度必须都是2的幂。
  70. 这是WebGL中的限制,不是由three.js所限制的。
  71. </p>
  72. <h3>[property:number magFilter]</h3>
  73. <p>
  74. 当一个纹素覆盖大于一个像素时,贴图将如何采样。默认值为[page:Textures THREE.LinearFilter],
  75. 它将获取四个最接近的纹素,并在他们之间进行双线性插值。
  76. 另一个选项是[page:Textures THREE.NearestFilter],它将使用最接近的纹素的值。<br />
  77. 请参阅[page:Textures texture constants]页面来了解详细信息。
  78. </p>
  79. <h3>[property:number minFilter]</h3>
  80. <p>
  81. 当一个纹素覆盖小于一个像素时,贴图将如何采样。默认值为[page:Textures THREE.LinearMipmapLinearFilter],
  82. 它将使用mipmapping以及三次线性滤镜。<br /><br />
  83. 请参阅[page:Textures texture constants]页面来了解所有可能的选项。
  84. </p>
  85. <h3>[property:number anisotropy]</h3>
  86. <p>
  87. 沿着轴,通过具有最高纹素密度的像素的样本数。
  88. 默认情况下,这个值为1。设置一个较高的值将会产生比基本的mipmap更清晰的效果,代价是需要使用更多纹理样本。
  89. 使用[page:WebGLRenderer.capabilities renderer.capabilities.getMaxAnisotropy]() 来查询GPU中各向异性的最大有效值;这个值通常是2的幂。
  90. </p>
  91. <h3>[property:number format]</h3>
  92. <p>
  93. 默认值为[page:Textures THREE.RGBAFormat]。<br /><br />
  94. 请参阅[page:Textures texture constants]页面来了解其它格式。
  95. </p>
  96. <h3>[property:String internalFormat]</h3>
  97. <p>
  98. 此项的默认值由[page:Texture.format .format]和[page:Texture.type .type]混合并决定。<br />
  99. 这项GPU格式设置允许开发者决定在GPU中的数据存储方式。<br /><br />
  100. 查看[page:Textures texture constants]页面来了解所有可用的Internal Formats以及其细节。
  101. </p>
  102. <h3>[property:number type]</h3>
  103. <p>
  104. 这个值必须与[page:Texture.format .format]相对应。默认值为[page:Textures THREE.UnsignedByteType],
  105. 它将会被用于绝大多数纹理格式。<br /><br />
  106. 请参阅[page:Textures texture constants]来了解其它格式。
  107. </p>
  108. <h3>[property:Vector2 offset]</h3>
  109. <p>
  110. 贴图单次重复中的起始偏移量,分别表示U和V。
  111. 一般范围是由`0.0`到`1.0`。
  112. </p>
  113. <p>
  114. 在此引擎中下列纹理共享`第一套`uv通道。
  115. 偏移量(以及重复次数)的设置项按照下列纹理进行优先级排列并共享:
  116. <ol>
  117. <li>color map</li>
  118. <li>specular map</li>
  119. <li>displacement map</li>
  120. <li>normal map</li>
  121. <li>bump map</li>
  122. <li>roughness map</li>
  123. <li>metalness map</li>
  124. <li>alpha map</li>
  125. <li>emissive map</li>
  126. <li>clearcoat map</li>
  127. <li>clearcoat normal map</li>
  128. <li>clearcoat roughnessMap map</li>
  129. </ol>
  130. </p>
  131. <p>
  132. 在此引擎中下列纹理类型共享`第二套`uv通道。
  133. 偏移量(以及重复次数)的设置项按照下列纹理进行优先级排列并共享:
  134. <ol>
  135. <li>ao map</li>
  136. <li>light map</li>
  137. </ol>
  138. </p>
  139. <h3>[property:Vector2 repeat]</h3>
  140. <p>
  141. 决定纹理在表面的重复次数,两个方向分别表示U和V,如果重复次数在任何方向上设置了超过1的数值,
  142. 对应的Wrap需要设置为[page:Textures THREE.RepeatWrapping]或者[page:Textures THREE.MirroredRepeatWrapping]来
  143. 达到想要的平铺效果。此项设置有和[page:.offset]一样的限制。
  144. </p>
  145. <h3>[property:number rotation]</h3>
  146. <p>
  147. 纹理将围绕中心点旋转多少度,单位为弧度(rad)。正值为逆时针方向旋转,默认值为*0*。
  148. </p>
  149. <h3>[property:Vector2 center]</h3>
  150. <p>
  151. 旋转中心点。(0.5, 0.5)对应纹理的正中心。默认值为(0,0),即左下角。
  152. </p>
  153. <h3>[property:Boolean matrixAutoUpdate]</h3>
  154. <p>
  155. 是否从纹理的[page:Texture.offset .offset]、[page:Texture.repeat .repeat]、[page:Texture.rotation .rotation]和[page:Texture.center .center]属性更新纹理的UV变换矩阵(uv-transform [page:Texture.matrix .matrix])。
  156. 默认值为true。
  157. 如果你要直接指定纹理的变换矩阵,请将其设为false。
  158. </p>
  159. <h3>[property:Matrix3 matrix]</h3>
  160. <p>
  161. 纹理的UV变换矩阵。
  162. 当纹理的[page:Texture.matrixAutoUpdate .matrixAutoUpdate]属性为true时,
  163. 由渲染器从纹理的[page:Texture.offset .offset]、[page:Texture.repeat .repeat]、[page:Texture.rotation .rotation]和[page:Texture.center .center]属性中进行更新。
  164. 当[page:Texture.matrixAutoUpdate .matrixAutoUpdate]属性为false时,该矩阵可以被手动设置。
  165. 默认值为单位矩阵。
  166. </p>
  167. <h3>[property:Boolean generateMipmaps]</h3>
  168. <p>
  169. 是否为纹理生成mipmap(如果可用)。默认为true。
  170. 如果你手动生成mipmap,请将其设为false。
  171. </p>
  172. <h3>[property:Boolean premultiplyAlpha]</h3>
  173. <p>
  174. 如果设置为*true*并且alpha通道存在的话,上传到GPU时alpha的数值将会与颜色通道的数值相乘。默认为*false*。<br /><br />
  175. 注意此项属性不会影响到[link:https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap ImageBitmap]。
  176. 如果你想要则需要在bitmap创建的时候进行配置,如何配置请查看[page:ImageBitmapLoader]。
  177. </p>
  178. <h3>[property:Boolean flipY]</h3>
  179. <p>
  180. 如果设置为*true*,纹理在上传到GPU的时候会进行纵向的翻转。默认值为*true*。<br /><br />
  181. 注意此项属性不会影响到[link:https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap ImageBitmap]。
  182. 如果你想要则需要在bitmap创建的时候进行配置,如何配置请查看[page:ImageBitmapLoader]。
  183. </p>
  184. <h3>[property:number unpackAlignment]</h3>
  185. <p>
  186. 默认为4。指定内存中每个像素行起点的对齐要求。
  187. 允许的值为1(字节对齐)、2(行对齐到偶数字节)、4(字对齐)和8(行从双字边界开始)。
  188. 请参阅[link:http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml glPixelStorei]来了解详细信息。
  189. </p>
  190. <h3>[property:number encoding]</h3>
  191. <p>
  192. 默认值为[page:Textures THREE.LinearEncoding]。
  193. 请参阅[page:Textures texture constants]来了解其他格式的详细信息。<br /><br />
  194. 请注意,如果在材质被使用之后,纹理贴图中这个值发生了改变,
  195. 需要触发Material.needsUpdate,来使得这个值在着色器中实现。
  196. </p>
  197. <h3>[property:Integer version]</h3>
  198. <p>
  199. 这个值起始值为*0*,计算[property:Boolean needsUpdate]被设置为*true*的次数。
  200. </p>
  201. <h3>[property:Function onUpdate]</h3>
  202. <p>
  203. 一个回调函数,在纹理被更新后调用。
  204. (例如,当needsUpdate被设为true且纹理被使用。)
  205. </p>
  206. <h3>[property:Boolean needsUpdate]</h3>
  207. <p>
  208. 将其设置为*true*,以便在下次使用纹理时触发一次更新。
  209. 这对于设置包裹模式尤其重要。
  210. </p>
  211. <h3>[property:Object userData]</h3>
  212. <p>
  213. 保存关于纹理的自定义信息的对象。不应该放函数引用,因为函数不会拷贝。
  214. </p>
  215. <h3>[property:Source source]</h3>
  216. <p>
  217. 纹理的数据源信息。可以在不同的纹理之间引用相同的数据源,这在使用精灵表的情况下很好用,因为在这种情况下不同的纹理只是使用了不同的偏移,但是其数据源是相同的。
  218. </p>
  219. <h2>方法</h2>
  220. <p>[page:EventDispatcher EventDispatcher]方法在这个类上可以使用。</p>
  221. <h3>[method:undefined updateMatrix]()</h3>
  222. <p>
  223. 从纹理的[page:Texture.offset .offset]、[page:Texture.repeat .repeat]、
  224. [page:Texture.rotation .rotation]和[page:Texture.center .center]属性来更新纹理的UV变换矩阵(uv-transform [page:Texture.matrix .matrix])。
  225. </p>
  226. <h3>[method:Texture clone]()</h3>
  227. <p>
  228. 拷贝纹理。请注意。这不是“深拷贝”,图像是共用的。
  229. 除此之外,拷贝一个纹理并不会将此纹理自动标记并上传。你需要在图片的属性变更或者源数据完全加载完的时候并准备好的时候将[page:Texture.needsUpdate]设置为true。
  230. </p>
  231. <h3>[method:Object toJSON]( [param:Object meta] )</h3>
  232. <p>
  233. meta -- 可选,包含有元数据的对象。<br />
  234. 将Texture对象转换为 three.js [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format](three.js JSON 物体/场景格式)。
  235. </p>
  236. <h3>[method:undefined dispose]()</h3>
  237. <p>
  238. 使用“废置”事件类型调用[page:EventDispatcher EventDispatcher].dispatchEvent。
  239. </p>
  240. <h3>[method:Vector2 transformUv]( [param:Vector2 uv] )</h3>
  241. <p>
  242. 基于纹理的[page:Texture.offset .offset]、[page:Texture.repeat .repeat]、
  243. [page:Texture.wrapS .wrapS]、[page:Texture.wrapT .wrapT]和[page:Texture.flipY .flipY]属性值来变换uv。
  244. </p>
  245. <h2>源代码</h2>
  246. <p>
  247. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  248. </p>
  249. </body>
  250. </html>