OBJLoader2.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1>
  12. <p class="desc">A loader for loading a <em>.obj</em> resource.<br />
  13. The <a href="https://en.wikipedia.org/wiki/Wavefront_.obj_file">OBJ file format</a> is a simple data-format
  14. that represents 3D geometry in a human redeable format as, the position of each vertex, the UV position of
  15. each texture coordinate vertex, vertex normals, and the faces that make each polygon defined as a list of
  16. vertices, and texture vertices.
  17. </p>
  18. <h2>Examples</h2>
  19. <code>
  20. // instantiate the loader
  21. var loader = new THREE.OBJLoader2();
  22. // function called on successful load
  23. var callbackOnLoad = function ( event ) {
  24. scene.add( event.detail.loaderRootNode );
  25. };
  26. // load a resource from provided URL synchronously
  27. loader.load( 'obj/female02/female02.obj', callbackOnLoad, null, null, null, false );
  28. </code>
  29. [example:webgl_loader_obj2] - Simple example <br>
  30. [example:webgl_loader_obj2_options] - Example for multiple use-cases (parse, load and run with instructions (sync and async)<br>
  31. [example:webgl_loader_obj2_run_director] - Advanced example using [page:LoaderSupport.LoaderWorkerDirector] for orchestration of multiple workers.
  32. <h2>Constructor</h2>
  33. <h3>[name]( [param:LoadingManager manager], [param:LoaderSupport.ConsoleLogger logger] )</h3>
  34. <p>
  35. [page:LoadingManager manager] - The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br>
  36. [page:LoaderSupport.ConsoleLogger logger] - logger to be used
  37. </p>
  38. <p>
  39. Use [name] to load OBJ data from files or to parse OBJ data from arraybuffer or text.
  40. </p>
  41. <h2>Methods</h2>
  42. <h3>[method:Object3D parse]( {[param:arraybuffer content]|[param:String content]] )</h3>
  43. <p>
  44. [[page:arraybuffer content]|[page:String content]] OBJ data as Uint8Array or String
  45. </p>
  46. <p>
  47. Parses OBJ data synchronously from arraybuffer or string and returns the [page:Object3D loaderRoorNode].
  48. </p>
  49. <h3>[method:Object3D parseAsync]( [param:arraybuffer content], [param:Function onLoad] )</h3>
  50. <p>
  51. [page:arraybuffer content] - OBJ data as Uint8Array<br>
  52. [page:Function onLoad] - Called after worker successfully completed loading<br>
  53. </p>
  54. <p>
  55. Parses OBJ content asynchronously from arraybuffer.
  56. </p>
  57. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:Function onMeshAlter], [param:boolean useAsync] )</h3>
  58. <p>
  59. [page:String url] - A string containing the path/URL of the file to be loaded.<br>
  60. [page:Function onLoad] - A function to be called after loading is successfully completed. The function receives loaded [page:Object3D] as an argument.<br>
  61. [page:Function onProgress] - (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains [page:Integer total] and [page:Integer loaded] bytes.<br>
  62. [page:Function onError] - (optional) A function to be called if an error occurs during loading. The function receives the error as an argument.<br>
  63. [page:Function onMeshAlter] - (optional) A function to be called after a new mesh raw data becomes available for alteration.<br>
  64. [page:boolean useAsync] - (optional) If true, uses async loading with worker, if false loads data synchronously.
  65. </p>
  66. <p>
  67. Use this convenient method to load a file at the given URL. By default the fileLoader uses an ArrayBuffer.
  68. </p>
  69. <h3>[method:null run]( [param:LoaderSupport.PrepData params], [param:LoaderSupport.WorkerSupport workerSupportExternal] )</h3>
  70. <p>
  71. [page:LoaderSupport.PrepData params] - prepData All parameters and resources required for execution<br>
  72. [page:LoaderSupport.WorkerSupport workerSupportExternal] - Use pre-existing WorkerSupport
  73. </p>
  74. <p>
  75. Run the loader according the provided instructions.
  76. </p>
  77. <h3>[method:null setLogging]( [param:Boolean enabled], [param:Boolean debug] )</h3>
  78. <p>
  79. [page:Boolean enabled] True or false.<br>
  80. [page:Boolean debug] True or false.
  81. </p>
  82. <p>
  83. Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
  84. </p>
  85. <h3>[method:null setModelName] ( [param:String modelName] )</h3>
  86. <p>
  87. [page:String modelName]
  88. </p>
  89. <p>
  90. Set the name of the model.
  91. </p>
  92. <h3>[method:null setPath] ( [param:String path] )</h3>
  93. <p>
  94. [page:String path] - URL
  95. </p>
  96. <p>
  97. The URL of the base path.
  98. </p>
  99. <h3>[method:null setResourcePath] ( [param:String resourcePath] )</h3>
  100. <p>
  101. [page:String resourcePath] - URL
  102. </p>
  103. <p>
  104. Allows to specify resourcePath for dependencies of specified resource.
  105. </p>
  106. <h3>[method:null setStreamMeshesTo] ( [param:Object3D streamMeshesTo] )</h3>
  107. <p>
  108. [page:Object3D streamMeshesTo] - Object already attached to scenegraph where new meshes will be attached to
  109. </p>
  110. <p>
  111. Set the node where the loaded objects will be attached directly.
  112. </p>
  113. <h3>[method:null setMaterials] ( Array of [param:Material materials] )</h3>
  114. <p>
  115. Array of [page:Material materials] - Array of [page:Material Materials]
  116. </p>
  117. <p>
  118. Set materials loaded by MTLLoader or any other supplier of an Array of [page:Material Materials].
  119. </p>
  120. <h3>[method:null setUseIndices]( [param:Boolean useIndices] )</h3>
  121. <p>
  122. [page:Boolean useIndices]
  123. </p>
  124. <p>
  125. Instructs loaders to create indexed [page:BufferGeometry].
  126. </p>
  127. <h3>[method:null setDisregardNormals]( [param:Boolean disregardNormals] )</h3>
  128. <p>
  129. [page:Boolean disregardNormals]
  130. </p>
  131. <p>
  132. Tells whether normals should be completely disregarded and regenerated.
  133. </p>
  134. <h3>[method:null setMaterialPerSmoothingGroup] ( [param:boolean materialPerSmoothingGroup] )</h3>
  135. <p>
  136. [page:boolean materialPerSmoothingGroup]
  137. </p>
  138. <p>
  139. Tells whether a material shall be created per smoothing group.
  140. </p>
  141. <h3>[method:null onProgress]( [param:String type], [param:String text], [param:Number numericalValue] )</h3>
  142. <p>
  143. [page:String type] - The type of event<br>
  144. [page:String text] - Textual description of the event<br>
  145. [page:Number numericalValue] - Numerical value describing the progress
  146. </p>
  147. <p>
  148. Announce feedback which is give to the registered [page:LoaderSupport.Callbacks].
  149. </p>
  150. <h3>[method:null loadMtl]( [param:String url], [param:Object content], [param:Function callbackOnLoad], [param:String crossOrigin], [param:Object materialOptions]) </h3>
  151. <p>
  152. [page:String url] - URL to the file<br>
  153. [page:Object content] - The file content as arraybuffer or text<br>
  154. [page:Function onLoad] - Callback to be called after successful load<br>
  155. [page:Function onProgress] - (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains [page:Integer total] and [page:Integer loaded] bytes.<br>
  156. [page:Function onError] - (optional) A function to be called if an error occurs during loading. The function receives the error as an argument.<br>
  157. [page:String crossOrigin] - (optional) CORS value<br>
  158. [page:Function materialOptions] - (optional) Set material loading options for MTLLoader
  159. </p>
  160. <p>
  161. Utility method for loading an mtl file according resource description. Provide url or content.
  162. </p>
  163. <h2>Source</h2>
  164. [link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/OBJLoader2.js examples/js/loaders/OBJLoader2.js]
  165. </body>
  166. </html>