Loading-3D-models.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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/jsm/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://www.blender.org/" target="_blank" rel="noopener">Blender</a> by the Blender Foundation</li>
  48. <li><a href="https://www.allegorithmic.com/products/substance-painter" target="_blank" rel="noopener">Substance Painter</a> by Allegorithmic</li>
  49. <li><a href="https://www.foundry.com/products/modo" target="_blank" rel="noopener">Modo</a> by Foundry</li>
  50. <li><a href="https://www.marmoset.co/toolbag/" target="_blank" rel="noopener">Toolbag</a> by Marmoset</li>
  51. <li><a href="https://www.sidefx.com/products/houdini/" target="_blank" rel="noopener">Houdini</a> by SideFX</li>
  52. <li><a href="https://labs.maxon.net/?p=3360" target="_blank" rel="noopener">Cinema 4D</a> by MAXON</li>
  53. <li><a href="https://github.com/KhronosGroup/COLLADA2GLTF" target="_blank" rel="noopener">COLLADA2GLTF</a> by the Khronos Group</li>
  54. <li><a href="https://github.com/facebookincubator/FBX2glTF" target="_blank" rel="noopener">FBX2GLTF</a> by Facebook</li>
  55. <li><a href="https://github.com/AnalyticalGraphicsInc/obj2gltf" target="_blank" rel="noopener">OBJ2GLTF</a> by Analytical Graphics Inc</li>
  56. <li>&hellip;and <a href="http://github.khronos.org/glTF-Project-Explorer/" 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 app individually.
  71. </p>
  72. <code>
  73. import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
  74. </code>
  75. <p>
  76. Once you've imported a loader, you're ready to add a model to your scene. Syntax varies among
  77. different loaders — when using another format, check the examples and documentation for that
  78. loader. For glTF, usage with global scripts would be:
  79. </p>
  80. <code>
  81. var loader = new GLTFLoader();
  82. loader.load( 'path/to/model.glb', function ( gltf ) {
  83. scene.add( gltf.scene );
  84. }, undefined, function ( error ) {
  85. console.error( error );
  86. } );
  87. </code>
  88. <p>
  89. See [page:GLTFLoader GLTFLoader documentation] for further details.
  90. </p>
  91. <h2>Troubleshooting</h2>
  92. <p>
  93. You've spent hours modeling an artisanal masterpiece, you load it into
  94. the webpage, and — oh no! 😭 It's distorted, miscolored, or missing entirely.
  95. Start with these troubleshooting steps:
  96. </p>
  97. <ol>
  98. <li>
  99. Check the JavaScript console for errors, and make sure you've used an
  100. <em>onError</em> callback when calling <em>.load()</em> to log the result.
  101. </li>
  102. <li>
  103. View the model in another application. For glTF, drag-and-drop viewers
  104. are available for
  105. <a href="https://gltf-viewer.donmccurdy.com/" target="_blank" rel="noopener">three.js</a> and
  106. <a href="http://sandbox.babylonjs.com/" target="_blank" rel="noopener">babylon.js</a>. If the model
  107. appears correctly in one or more applications,
  108. <a href="https://github.com/mrdoob/three.js/issues/new" target="_blank" rel="noopener">file a bug against three.js</a>.
  109. If the model cannot be shown in any application, we strongly encourage
  110. filing a bug with the application used to create the model.
  111. </li>
  112. <li>
  113. Try scaling the model up or down by a factor of 1000. Many models are
  114. scaled differently, and large models may not appear if the camera is
  115. inside the model.
  116. </li>
  117. <li>
  118. Try to add and position a light source. The model may be hidden in the dark.
  119. </li>
  120. <li>
  121. Look for failed texture requests in the network tab, like
  122. <em>C:\\Path\To\Model\texture.jpg</em>. Use paths relative to your
  123. model instead, such as <em>images/texture.jpg</em> — this may require
  124. editing the model file in a text editor.
  125. </li>
  126. </ol>
  127. <h2>Asking for help</h2>
  128. <p>
  129. If you've gone through the troubleshooting process above and your model
  130. still isn't working, the right approach to asking for help will get you to
  131. a solution faster. Post a question on the
  132. <a href="https://discourse.threejs.org/" target="_blank" rel="noopener">three.js forum</a> and, whenever possible,
  133. include your model (or a simpler model with the same problem) in any formats
  134. you have available. Include enough information for someone else to reproduce
  135. the issue quickly — ideally, a live demo.
  136. </p>
  137. </body>
  138. </html>