Loading-3D-models.html 6.6 KB

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