Loading-3D-models.html 6.2 KB

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