MTLLoader.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>MTLLoader - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="Loader.html">Loader</a> → </p>
  13. <h1 translate="no">MTLLoader</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>A loader for the MTL format.</p>
  17. <p>The Material Template Library format (MTL) or .MTL File Format is a companion file format
  18. to OBJ that describes surface shading (material) properties of objects within one or more
  19. OBJ files.</p></div>
  20. <h2>Code Example</h2>
  21. <div translate="no"><pre><code class="language-js">const loader = new MTLLoader();
  22. const materials = await loader.loadAsync( 'models/obj/male02/male02.mtl' );
  23. const objLoader = new OBJLoader();
  24. objLoader.setMaterials( materials );
  25. </code></pre></div>
  26. </header>
  27. <article>
  28. <h2 class="subsection-title">Import</h2>
  29. <p><span translate="no">MTLLoader</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
  30. <pre><code class="language-js">import { MTLLoader } from 'three/addons/loaders/MTLLoader.js';</code></pre>
  31. <div class="container-overview">
  32. <h2>Constructor</h2>
  33. <h3 class="name name-method" id="MTLLoader" translate="no">new <a href="#MTLLoader">MTLLoader</a><span class="signature">()</span> </h3>
  34. <div class="method">
  35. </div>
  36. </div>
  37. <h2 class="subsection-title">Methods</h2>
  38. <h3 class="name name-method" id="load" translate="no">.<a href="#load">load</a><span class="signature">( url : <span class="param-type">string</span>, onLoad : <span class="param-type">function</span>, onProgress : <span class="param-type">onProgressCallback</span>, onError : <span class="param-type">onErrorCallback</span> )</span> </h3>
  39. <div class="method">
  40. <div class="description">
  41. <p>Starts loading from the given URL and passes the loaded MTL asset
  42. to the <code>onLoad()</code> callback.</p>
  43. </div>
  44. <table class="params">
  45. <tbody>
  46. <tr>
  47. <td class="name"><code>url</code></td>
  48. <td class="description last"><p>The path/URL of the file to be loaded. This can also be a data URI.</p></td>
  49. </tr>
  50. <tr>
  51. <td class="name"><code>onLoad</code></td>
  52. <td class="description last"><p>Executed when the loading process has been finished.</p></td>
  53. </tr>
  54. <tr>
  55. <td class="name"><code>onProgress</code></td>
  56. <td class="description last"><p>Executed while the loading is in progress.</p></td>
  57. </tr>
  58. <tr>
  59. <td class="name"><code>onError</code></td>
  60. <td class="description last"><p>Executed when errors occur.</p></td>
  61. </tr>
  62. </tbody>
  63. </table>
  64. <dl class="details">
  65. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Loader.html#load">Loader#load</a></dt>
  66. </dl>
  67. </div>
  68. <h3 class="name name-method" id="parse" translate="no">.<a href="#parse">parse</a><span class="signature">( text : <span class="param-type">string</span>, path : <span class="param-type">string</span> )</span><span class="type-signature"> : MaterialCreator</span> </h3>
  69. <div class="method">
  70. <div class="description">
  71. <p>Parses the given MTL data and returns the resulting material creator.</p>
  72. </div>
  73. <table class="params">
  74. <tbody>
  75. <tr>
  76. <td class="name"><code>text</code></td>
  77. <td class="description last"><p>The raw MTL data as a string.</p></td>
  78. </tr>
  79. <tr>
  80. <td class="name"><code>path</code></td>
  81. <td class="description last"><p>The URL base path.</p></td>
  82. </tr>
  83. </tbody>
  84. </table>
  85. <dl class="details">
  86. <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Loader.html#parse">Loader#parse</a></dt>
  87. </dl>
  88. <dl class="details">
  89. <dt class="tag-returns"><strong>Returns:</strong> The material creator.</dt>
  90. </dl>
  91. </div>
  92. <h3 class="name name-method" id="setMaterialOptions" translate="no">.<a href="#setMaterialOptions">setMaterialOptions</a><span class="signature">( value : <span class="param-type">MTLLoader~MaterialOptions</span> )</span><span class="type-signature"> : <a href="MTLLoader.html">MTLLoader</a></span> </h3>
  93. <div class="method">
  94. <div class="description">
  95. <p>Sets the material options.</p>
  96. </div>
  97. <table class="params">
  98. <tbody>
  99. <tr>
  100. <td class="name"><code>value</code></td>
  101. <td class="description last"><p>The material options.</p></td>
  102. </tr>
  103. </tbody>
  104. </table>
  105. <dl class="details">
  106. <dt class="tag-returns"><strong>Returns:</strong> A reference to this loader.</dt>
  107. </dl>
  108. </div>
  109. <h2 class="subsection-title">Type Definitions</h2>
  110. <div class="member">
  111. <h3 class="name" id="~MaterialOptions" translate="no">.<a href="#~MaterialOptions">MaterialOptions</a> </h3>
  112. <div class="description">
  113. <p>Material options of <code>MTLLoader</code>.</p>
  114. </div>
  115. <h5 class="subsection-title">Properties:</h5>
  116. <table class="props">
  117. <thead>
  118. <tr>
  119. <th>Name</th>
  120. <th>Type</th>
  121. <th>Attributes</th>
  122. <th>Default</th>
  123. <th class="last">Description</th>
  124. </tr>
  125. </thead>
  126. <tbody>
  127. <tr>
  128. <td class="name"><code>side</code></td>
  129. <td class="type">
  130. <span class="param-type"><a href="global.html#FrontSide">FrontSide</a></span>
  131. |
  132. <span class="param-type"><a href="global.html#BackSide">BackSide</a></span>
  133. |
  134. <span class="param-type"><a href="global.html#DoubleSide">DoubleSide</a></span>
  135. </td>
  136. <td class="attributes">
  137. &lt;optional><br>
  138. </td>
  139. <td class="default">
  140. FrontSide
  141. </td>
  142. <td class="description last"><p>Which side to apply the material.</p></td>
  143. </tr>
  144. <tr>
  145. <td class="name"><code>wrap</code></td>
  146. <td class="type">
  147. <span class="param-type"><a href="global.html#RepeatWrapping">RepeatWrapping</a></span>
  148. |
  149. <span class="param-type"><a href="global.html#ClampToEdgeWrapping">ClampToEdgeWrapping</a></span>
  150. |
  151. <span class="param-type"><a href="global.html#MirroredRepeatWrapping">MirroredRepeatWrapping</a></span>
  152. </td>
  153. <td class="attributes">
  154. &lt;optional><br>
  155. </td>
  156. <td class="default">
  157. RepeatWrapping
  158. </td>
  159. <td class="description last"><p>What type of wrapping to apply for textures.</p></td>
  160. </tr>
  161. <tr>
  162. <td class="name"><code>normalizeRGB</code></td>
  163. <td class="type">
  164. <span class="param-type">boolean</span>
  165. </td>
  166. <td class="attributes">
  167. &lt;optional><br>
  168. </td>
  169. <td class="default">
  170. false
  171. </td>
  172. <td class="description last"><p>Whether RGB colors should be normalized to <code>0-1</code> from <code>0-255</code>.</p></td>
  173. </tr>
  174. <tr>
  175. <td class="name"><code>ignoreZeroRGBs</code></td>
  176. <td class="type">
  177. <span class="param-type">boolean</span>
  178. </td>
  179. <td class="attributes">
  180. &lt;optional><br>
  181. </td>
  182. <td class="default">
  183. false
  184. </td>
  185. <td class="description last"><p>Ignore values of RGBs (Ka,Kd,Ks) that are all 0's.</p></td>
  186. </tr>
  187. </tbody>
  188. </table>
  189. </div>
  190. <h2 class="subsection-title">Source</h2>
  191. <p>
  192. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/MTLLoader.js" target="_blank" rel="noopener" translate="no">examples/jsm/loaders/MTLLoader.js</a>
  193. </p>
  194. </article>
  195. </section>
  196. <script src="../scripts/linenumber.js"></script>
  197. <script src="../scripts/page.js"></script>
  198. </body>
  199. </html>
粤ICP备19079148号