Loading-3D-models.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. <br />
  13. <p>
  14. 3D models are available in hundreds of file formats, each with different
  15. purposes, assorted features, and varying complexity. Although
  16. <a href="https://github.com/mrdoob/three.js/tree/dev/examples/js/loaders" target="_blank" rel="noopener">
  17. three.js provides many loaders</a>, choosing the right format and
  18. workflow will save time and frustration later on. Some formats are
  19. difficult to work with, inefficient for realtime experiences, or simply not
  20. fully supported at this time.
  21. </p>
  22. <p>
  23. This guide provides a workflow recommended for most users, and suggestions
  24. for what to try if things don't go as expected.
  25. </p>
  26. <h2>Before we start</h2>
  27. <p>
  28. If you're new to running a local server, begin with
  29. [link:#manual/introduction/How-to-run-things-locally how to run things locally]
  30. first. Many common errors viewing 3D models can be avoided by hosting files
  31. correctly.
  32. </p>
  33. <h2>Recommended workflow</h2>
  34. <p>
  35. Where possible, we recommend using glTF (GL Transmission Format). Both
  36. <small>.GLB</small> and <small>.GLTF</small> versions of the format are
  37. well supported. Because glTF is focused on runtime asset delivery, it is
  38. compact to transmit and fast to load. Features include meshes, materials,
  39. textures, skins, skeletons, morph targets, animations, lights, and
  40. cameras.
  41. </p>
  42. <p>
  43. Public-domain glTF files are available on sites like
  44. <a href="https://sketchfab.com/models?features=downloadable&sort_by=-likeCount&type=models" target="_blank" rel="noopener">
  45. Sketchfab</a>, or various tools include glTF export:
  46. </p>
  47. <ul>
  48. <li><a href="https://github.com/KhronosGroup/glTF-Blender-Exporter" target="_blank" rel="noopener">glTF-Blender-Exporter</a> by the Khronos Group</li>
  49. <li><a href="https://github.com/KhronosGroup/COLLADA2GLTF" target="_blank" rel="noopener">COLLADA2GLTF</a> by the Khronos Group</li>
  50. <li><a href="https://github.com/facebookincubator/FBX2glTF" target="_blank" rel="noopener">FBX2GLTF</a> by Facebook</li>
  51. <li><a href="https://github.com/AnalyticalGraphicsInc/obj2gltf" target="_blank" rel="noopener">OBJ2GLTF</a> by Analytical Graphics Inc</li>
  52. <li><a href="https://www.allegorithmic.com/products/substance-painter" target="_blank" rel="noopener">Substance Painter</a> by Allegorithmic</li>
  53. <li><a href="https://www.foundry.com/products/modo" target="_blank" rel="noopener">Modo</a> by Foundry</li>
  54. <li><a href="https://www.marmoset.co/toolbag/" target="_blank" rel="noopener">Toolbag</a> by Marmoset</li>
  55. <li>&hellip;and <a href="https://github.com/khronosgroup/gltf#gltf-tools" target="_blank" rel="noopener">many more</a></li>
  56. </ul>
  57. <p>
  58. If your preferred tools do not support glTF, consider requesting glTF
  59. export from the authors, or posting on
  60. <a href="https://github.com/KhronosGroup/glTF/issues/1051" target="_blank" rel="noopener">the glTF roadmap thread</a>.
  61. </p>
  62. <p>
  63. When glTF is not an option, popular formats such as FBX, OBJ, or COLLADA
  64. are also available and regularly maintained.
  65. </p>
  66. <h2>Loading</h2>
  67. <p>
  68. Only a few loaders ([page:ObjectLoader] and [page:JSONLoader]) are included by default with
  69. three.js — others should be added to your page individually. Depending on your
  70. preference and comfort with build tools, choose one of the following:
  71. </p>
  72. <code>
  73. // global script
  74. &lt;script src="GLTFLoader.js"&gt;&lt;/script&gt;
  75. // commonjs
  76. var THREE = window.THREE = require('three');
  77. require('three/examples/js/loaders/GLTFLoader');
  78. </code>
  79. <p>
  80. Currently three.js examples are not available as ES modules (import &hellip; from '&hellip;').
  81. Several workarounds are discussed in
  82. <a href="https://github.com/KhronosGroup/glTF/issues/9562" target="_blank" rel="noopener">#9562</a>.
  83. </p>
  84. <p>
  85. Once you've imported a loader, you're ready to add a model to your scene. Syntax varies among
  86. different loaders — when using another format, check the examples and documentation for that
  87. loader. For glTF, basic usage would be:
  88. </p>
  89. <code>
  90. var loader = new THREE.GLTFLoader();
  91. loader.load( 'path/to/model.glb', function ( gltf ) {
  92. scene.add( gltf.scene );
  93. }, undefined, function ( error ) {
  94. console.error( error );
  95. } );
  96. </code>
  97. <p>
  98. See [page:GLTFLoader GLTFLoader documentation] for further details.
  99. </p>
  100. <h2>Troubleshooting</h2>
  101. <p>
  102. You've spent hours modeling an artisanal masterpiece, you load it into
  103. the webpage, and — oh no! 😭 It's distorted, miscolored, or missing entirely.
  104. Start with these troubleshooting steps:
  105. </p>
  106. <ol>
  107. <li>
  108. Check the JavaScript console for errors, and make sure you've used an
  109. <em>onError</em> callback when calling <em>.load()</em> to log the result.
  110. </li>
  111. <li>
  112. View the model in another application. For glTF, drag-and-drop viewers
  113. are available for
  114. <a href="https://gltf-viewer.donmccurdy.com/" target="_blank" rel="noopener">three.js</a> and
  115. <a href="http://sandbox.babylonjs.com/" target="_blank" rel="noopener">babylon.js</a>. If the model
  116. appears correctly in one or more applications,
  117. <a href="https://github.com/mrdoob/three.js/issues/new" target="_blank" rel="noopener">file a bug against three.js</a>.
  118. If the model cannot be shown in any application, we strongly encourage
  119. filing a bug with the application used to create the model.
  120. </li>
  121. <li>
  122. Try scaling the model up or down by a factor of 1000. Many models are
  123. scaled differently, and large models may not appear if the camera is
  124. inside the model.
  125. </li>
  126. <li>
  127. Look for failed texture requests in the network tab, like
  128. <em>C:\\Path\To\Model\texture.jpg</em>. Use paths relative to your
  129. model instead, such as <em>images/texture.jpg</em> — this may require
  130. editing the model file in a text editor.
  131. </li>
  132. </ol>
  133. <h2>Asking for help</h2>
  134. <p>
  135. If you've gone through the troubleshooting process above and your model
  136. still isn't working, the right approach to asking for help will get you to
  137. a solution faster. Post a question on the
  138. <a href="https://discourse.threejs.org/" target="_blank" rel="noopener">three.js forum</a> and, whenever possible,
  139. include your model (or a simpler model with the same problem) in any formats
  140. you have available. Include enough information for someone else to reproduce
  141. the issue quickly — ideally, a live demo.
  142. </p>
  143. </body>
  144. </html>