importing_scenes.rst 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. .. _doc_importing_3d_scenes:
  2. Importing 3D Scenes
  3. ==================
  4. Godot Scene Importer
  5. --------------------
  6. When dealing with 3D assets, Godot has a very flexible and configurable importer.
  7. Godot works with *scenes*. This means that the entire scene being worked on in your favorite 3D DCC will be
  8. transfered as close as possible.
  9. Godot supports the following 3D *scene file fomats*:
  10. * DAE (Collada), which is currently the most mature workflow.
  11. * GLTF 2.0. Both text and binary formats are supported. Godot has full support for it, but the format is new and gaining traction.
  12. * OBJ (Wavefront) formats. It is also fully supported, but pretty limited (no support for pivots, skeletons, etc).
  13. Just copy the scene file together with the texture to the project repository, and Godot will do a full import.
  14. Why not FBX?
  15. ~~~~~~~~~~~~
  16. Most game engines use the FBX format for importing 3D scenes, which is
  17. definitely one of the most standardized in the industry. However, this
  18. format requires the use of a closed library from Autodesk which is
  19. distributed with a more restrictive licensing terms than Godot.
  20. The plan is, sometime in the future, to offer a binary plug-in using GDNative.
  21. Exporting DAE files from Maya and 3DS Max
  22. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. Autodesk added built-in collada support to Maya and 3DS Max, but it's
  24. broken by default and should not be used. The best way to export this format
  25. is by using the
  26. `OpenCollada <https://github.com/KhronosGroup/OpenCOLLADA/wiki/OpenCOLLADA-Tools>`__
  27. plugins. They work really well, although they are not always up-to date
  28. with the latest version of the software.
  29. Exporting DAE files from Blender
  30. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  31. Blender has built-in collada support too, but it's also broken and
  32. should not be used.
  33. Godot provides a `Python
  34. Plugin <https://github.com/godotengine/collada-exporter>`__
  35. that will do a much better job of exporting the scenes.
  36. Import workflows
  37. ----------------
  38. Godot scene importer allows different workflows regarding how data is imported. Depending on many options, it is possible to
  39. import a scene with:
  40. * External materials (default): Where each material is saved to a file resource. Modifications to them are kept.
  41. * External meshes: Where each mesh is saved to a different file. Many users prefer to deal with meshes directly.
  42. * External animations: Allowing saved animations to be modified and merged when sources change.
  43. * External scenes: Save the root nodes of the imported scenes each as a separate scene.
  44. * Single Scene: A single scene file with everything built in.
  45. .. image:: /img/scene_import1.png
  46. As different developers have different needs, this import process is highly customizable.
  47. Import Options
  48. ---------------
  49. The importer has several options, which will be discussed below:
  50. .. image:: /img/scene_import2.png
  51. Nodes:
  52. ~~~~~~~
  53. Root Type
  54. ^^^^^^^^^
  55. By default, the type of the root node in imported scenes is "Spatial", but this can be modified.
  56. Root Name
  57. ^^^^^^^^^
  58. Allows setting a specific name to the generated root node.
  59. Custom Script
  60. ^^^^^^^^^^^^^
  61. A special script to process the whole scene after import can be provided.
  62. This is great for post processing, changing materials, doing funny stuff
  63. with the geometry etc.
  64. Create a script that basically looks like this:
  65. ::
  66. tool # needed so it runs in editor
  67. extends EditorScenePostImport
  68. func post_import(scene):
  69. # do your stuff here
  70. return scene # remember to return the imported scene
  71. The post-import function takes the imported scene as argument (the
  72. parameter is actually the root node of the scene). The scene that
  73. will finally be used must be returned. It can be a different one.
  74. Storage
  75. ^^^^^^^
  76. By default, Godot imports a single scene. This option allows specifying
  77. that nodes below the root will each be a separate scene and instanced
  78. into the imported one.
  79. Of course, instancing such imported scenes in other places manually works too.
  80. Materials
  81. ~~~~~~~~~
  82. Location
  83. ^^^^^^^^
  84. Godot supports materials in meshes or nodes. By default, materials will be put
  85. on each node.
  86. Storage
  87. ^^^^^^^
  88. Materials can be stored within the scene or in external files. By default,
  89. they are stored in external files so editing them is possible. This is because
  90. most 3D DCCs don't have the same material options as those present in Godot.
  91. When materials are built-in, they will be lost each time the source scene
  92. is modified and re-imported.
  93. Keep on Reimport
  94. ^^^^^^^^^^^^^^^^
  95. Once materials are edited to use Godot features, the importer will keep the
  96. edited ones and ignore the ones coming from the source scene. This option
  97. is only present if materials are saved as files.
  98. Compress
  99. ^^^^^^^^
  100. Makes meshes compact 3D vertices to more efficient data types for rendering.
  101. In few cases, this might lead to loss of precision so disabling this option
  102. is allowed.
  103. Meshes
  104. ~~~~~~~
  105. Ensure Tangents
  106. ^^^^^^^^^^^^^^^
  107. If textures with normalmapping are to be used, meshes need to have tangent arrays.
  108. This option ensures that these are generated if not present in the source scene.
  109. Godot uses Mikktspace for this, but it's always better to have them generated in
  110. the exporter.
  111. Storage
  112. ^^^^^^^
  113. Meshes can be stored in separate files (resources) instead of built-in. This does
  114. not have much practical use unless one wants to build objects with them directly.
  115. This option is provided to help those who prefer working directly with meshes
  116. instead of scenes.
  117. External Files
  118. ~~~~~~~~~~~~~~
  119. Generated meshes and materials can be optionally stored in a subdirectory with the
  120. name of the scene.
  121. Animation Options
  122. ------------------
  123. Godot provides many options regarding how animation data is dealt with. Some exporters
  124. (such as Blender), can generate many animations in a single file. Others, such as
  125. 3DS Max or Maya, need many animations put into the same timeline or, at worst, put
  126. each animation in a separate file.
  127. .. image:: /img/scene_import3.png
  128. Import of animations is enabled by default.
  129. Animation : FPS
  130. ~~~~~~~~~~~~~~~
  131. Most 3D export formats store animation timeline in seconds instead of frames. To ensure
  132. animations are imported as faithfully as possible, please specify the frames per second
  133. used to edit them. Failing to do this may result in minimal jitter.
  134. Animation : Filter Script
  135. ~~~~~~~~~~~~~~~~~~~~~~~~~
  136. It is possible to specify a filter script in a special syntax to decide which tracks from which
  137. animations should be kept. (@TODO this needs documentation)
  138. Animation : Storage
  139. ~~~~~~~~~~~~~~~~~~~
  140. By default, animations are saved as built-in. It is possible to save them to a file instead. This
  141. allows adding custom tracks to the animations and keeping them after a reimport.
  142. Animation : Optimizer
  143. ~~~~~~~~~~~~~~~~~~~~~
  144. When animations are imported, an optimizer is run which reduces the size of the animation considerably.
  145. In general, this should always be turned on unless you suspect that an animation might be broken due to it being enabled.
  146. Animation : Clips
  147. ~~~~~~~~~~~~~~~~~~~~~
  148. It is possible to specify multiple animations from a single timeline as clips. Just specify from which frame to which frame each
  149. clip must be taken (and, of course, don't forget to specify the FPS option above).
  150. Scene Inheritance
  151. -----------------
  152. In many cases, it may be desired to do modifications to the imported scene. By default, this is not really possible because
  153. if the source asset changes (source .dae,.gltf,.obj file re-exported from 3D modelling app), Godot will re-import the whole scene.
  154. It is possible, however, to do local modifications by using *Scene Inheritance*. Just try to open the imported scene and the
  155. following dialog will appear:
  156. .. image:: /img/scene_import4.png
  157. In inherited scenes, the only limitations for modifications are:
  158. * Nodes can't be removed (but can be added anywhere).
  159. * Sub-Resources can't be edited (save them externally as described above for this)
  160. Other than that, everything is allowed!
  161. Import Hints
  162. ------------
  163. Many times, when editing a scene, there are common tasks that need to be done after exporting:
  164. * Adding collision detection to objects:
  165. * Setting objects as navigation meshes
  166. * Deleting nodes that are not used in the game engine (like specific lights used for modelling)
  167. To simplify this workflow, Godot offers a few suffixes that can be added to the names of the
  168. objects in your 3D modelling software. When imported, Godot will detect them and perform
  169. actions automatically:
  170. Remove nodes (-noimp)
  171. ~~~~~~~~~~~~~~~~~~~~
  172. Node names that have this suffix will be removed at import time, mo
  173. matter what their type is. They will not appear in the imported scene.
  174. Create collisions (-col, -colonly)
  175. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  176. Option "-col" will work only for Mesh nodes. If it is detected, a child
  177. static collision node will be added, using the same geometry as the mesh.
  178. However, it is often the case that the visual geometry is too complex or
  179. too un-smooth for collisions, which ends up not working well.
  180. To solve this, the "-colonly" modifier exists, which will remove the mesh upon
  181. import and create a :ref:`class_staticbody` collision instead.
  182. This helps the visual mesh and actual collision to be separated.
  183. Option "-colonly" can be also used with Blender's empty objects.
  184. On import it will create a :ref:`class_staticbody` with
  185. collision node as a child. Collision node will have one of predefined shapes,
  186. depending on the Blender's empty draw type:
  187. .. image:: /img/3dimp_BlenderEmptyDrawTypes.png
  188. - Single arrow will create :ref:`class_rayshape`
  189. - Cube will create :ref:`class_boxshape`
  190. - Image will create :ref:`class_planeshape`
  191. - Sphere (and other non-listed) will create :ref:`class_sphereshape`
  192. For better visibility in Blender's editor user can set "X-Ray" option on collision
  193. empties and set some distinct color for them in User Preferences / Themes / 3D View / Empty.
  194. Create navigatopm (-navmesh)
  195. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  196. A mesh node with this suffix will be converted to a navigation mesh. Original Mesh node will be
  197. removed.
  198. Rigid Body (-rigid)
  199. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  200. Creates a rigid body from this mesh