1
0

OBJLoader.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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:Loader] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">A loader for loading a `.obj` resource.<br />
  13. The [link:https://en.wikipedia.org/wiki/Wavefront_.obj_file OBJ file format] is a simple data-format
  14. that represents 3D geometry in a human readable 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>Import</h2>
  19. <p>
  20. [name] is an add-on, and must be imported explicitly.
  21. See [link:#manual/introduction/Installation Installation / Addons].
  22. </p>
  23. <code>
  24. import { OBJLoader } from 'three/addons/loaders/OBJLoader.js';
  25. </code>
  26. <h2>Code Example</h2>
  27. <code>
  28. // instantiate a loader
  29. const loader = new OBJLoader();
  30. // load a resource
  31. loader.load(
  32. // resource URL
  33. 'models/monster.obj',
  34. // called when resource is loaded
  35. function ( object ) {
  36. scene.add( object );
  37. },
  38. // called when loading is in progresses
  39. function ( xhr ) {
  40. console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
  41. },
  42. // called when loading has errors
  43. function ( error ) {
  44. console.log( 'An error happened' );
  45. }
  46. );
  47. </code>
  48. <h2>Examples</h2>
  49. <p>
  50. [example:webgl_loader_obj]
  51. </p>
  52. <h2>Constructor</h2>
  53. <h3>[name]( [param:LoadingManager manager] )</h3>
  54. <p>
  55. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
  56. </p>
  57. <p>
  58. Creates a new [name].
  59. </p>
  60. <h2>Properties</h2>
  61. <p>See the base [page:Loader] class for common properties.</p>
  62. <h2>Methods</h2>
  63. <p>See the base [page:Loader] class for common methods.</p>
  64. <h3>[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  65. <p>
  66. [page:String url] — A string containing the path/URL of the `.obj` file.<br />
  67. [page:Function onLoad] — (optional) A function to be called after the loading is successfully completed. The function receives the loaded [page:Object3D] as an argument.<br />
  68. [page:Function onProgress] — (optional) A function to be called while the loading is in progress. The function receives a XMLHttpRequest instance, which contains [page:Integer total] and [page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.<br />
  69. [page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.<br />
  70. </p>
  71. <p>
  72. Begin loading from url and call onLoad with the parsed response content.
  73. </p>
  74. <h3>[method:Object3D parse]( [param:String text] )</h3>
  75. <p>
  76. [page:String text] — The textual `obj` structure to parse.
  77. </p>
  78. <p>
  79. Returns an [page:Object3D]. It contains the parsed meshes as [page:Mesh] and lines as [page:LineSegments].<br />
  80. All geometry is created as [page:BufferGeometry]. Default materials are created as [page:MeshPhongMaterial].<br />
  81. If an `obj` object or group uses multiple materials while declaring faces, geometry groups and an array of materials are used.
  82. </p>
  83. <h3>[method:this setMaterials]( [param:MTLLoader.MaterialCreator materials] )</h3>
  84. <p>
  85. [page:MTLLoaderMaterialCreator MTLLoader.MaterialCreator materials] - A MaterialCreator instance.
  86. </p>
  87. <p>
  88. Sets materials loaded by MTLLoader or any other supplier of a [page:MTLLoaderMaterialCreator MTLLoader.MaterialCreator].
  89. </p>
  90. <h2>Source</h2>
  91. <p>
  92. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/OBJLoader.js examples/jsm/loaders/OBJLoader.js]
  93. </p>
  94. </body>
  95. </html>