Loading-3D-models.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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-IO" target="_blank" rel="noopener">glTF-Blender-IO</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><a href="https://www.sidefx.com/products/houdini/" target="_blank" rel="noopener">Houdini</a> by SideFX</li>
  56. <li><a href="https://labs.maxon.net/?p=3360" target="_blank" rel="noopener">Cinema 4D</a> by MAXON</li>
  57. <li>&hellip;and <a href="https://github.com/khronosgroup/gltf#gltf-tools" target="_blank" rel="noopener">many more</a></li>
  58. </ul>
  59. <p>
  60. If your preferred tools do not support glTF, consider requesting glTF
  61. export from the authors, or posting on
  62. <a href="https://github.com/KhronosGroup/glTF/issues/1051" target="_blank" rel="noopener">the glTF roadmap thread</a>.
  63. </p>
  64. <p>
  65. When glTF is not an option, popular formats such as FBX, OBJ, or COLLADA
  66. are also available and regularly maintained.
  67. </p>
  68. <h2>Loading</h2>
  69. <p>
  70. Only a few loaders (e.g. [page:ObjectLoader]) are included by default with
  71. three.js — others should be added to your page individually. Depending on your
  72. preference and comfort with build tools, choose one of the following:
  73. </p>
  74. <code>
  75. // global script
  76. &lt;script src="GLTFLoader.js"&gt;&lt;/script&gt;
  77. // commonjs
  78. var THREE = window.THREE = require('three');
  79. require('three/examples/js/loaders/GLTFLoader');
  80. </code>
  81. <p>
  82. Currently three.js examples are not available as ES modules (import &hellip; from '&hellip;').
  83. Several workarounds are discussed in
  84. <a href="https://github.com/mrdoob/three.js/issues/9562" target="_blank" rel="noopener">#9562</a>.
  85. </p>
  86. <p>
  87. Once you've imported a loader, you're ready to add a model to your scene. Syntax varies among
  88. different loaders — when using another format, check the examples and documentation for that
  89. loader. For glTF, basic usage would be:
  90. </p>
  91. <code>
  92. var loader = new THREE.GLTFLoader();
  93. loader.load( 'path/to/model.glb', function ( gltf ) {
  94. scene.add( gltf.scene );
  95. }, undefined, function ( error ) {
  96. console.error( error );
  97. } );
  98. </code>
  99. <p>
  100. See [page:GLTFLoader GLTFLoader documentation] for further details.
  101. </p>
  102. <h2>Troubleshooting</h2>
  103. <p>
  104. You've spent hours modeling an artisanal masterpiece, you load it into
  105. the webpage, and — oh no! 😭 It's distorted, miscolored, or missing entirely.
  106. Start with these troubleshooting steps:
  107. </p>
  108. <ol>
  109. <li>
  110. Check the JavaScript console for errors, and make sure you've used an
  111. <em>onError</em> callback when calling <em>.load()</em> to log the result.
  112. </li>
  113. <li>
  114. View the model in another application. For glTF, drag-and-drop viewers
  115. are available for
  116. <a href="https://gltf-viewer.donmccurdy.com/" target="_blank" rel="noopener">three.js</a> and
  117. <a href="http://sandbox.babylonjs.com/" target="_blank" rel="noopener">babylon.js</a>. If the model
  118. appears correctly in one or more applications,
  119. <a href="https://github.com/mrdoob/three.js/issues/new" target="_blank" rel="noopener">file a bug against three.js</a>.
  120. If the model cannot be shown in any application, we strongly encourage
  121. filing a bug with the application used to create the model.
  122. </li>
  123. <li>
  124. Try scaling the model up or down by a factor of 1000. Many models are
  125. scaled differently, and large models may not appear if the camera is
  126. inside the model.
  127. </li>
  128. <li>
  129. Look for failed texture requests in the network tab, like
  130. <em>C:\\Path\To\Model\texture.jpg</em>. Use paths relative to your
  131. model instead, such as <em>images/texture.jpg</em> — this may require
  132. editing the model file in a text editor.
  133. </li>
  134. </ol>
  135. <h2>Asking for help</h2>
  136. <p>
  137. If you've gone through the troubleshooting process above and your model
  138. still isn't working, the right approach to asking for help will get you to
  139. a solution faster. Post a question on the
  140. <a href="https://discourse.threejs.org/" target="_blank" rel="noopener">three.js forum</a> and, whenever possible,
  141. include your model (or a simpler model with the same problem) in any formats
  142. you have available. Include enough information for someone else to reproduce
  143. the issue quickly — ideally, a live demo.
  144. </p>
  145. </body>
  146. </html>