importing_scenes.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. .. _doc_importing_3d_scenes:
  2. Importing 3D Scenes
  3. ===================
  4. Godot Scene Importer
  5. --------------------
  6. When dealing with 3D assets, Godot has a 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. transferred 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 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 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 use less precise numbers for multiple aspects of the mesh in order
  101. to save space.
  102. These are:
  103. * Transform Matrix (Location, rotation, and scale) : 32-bit float to 16-bit signed integer.
  104. * Vertices : 32-bit float to 16-bit signed integer.
  105. * Normals : 32-bit float to 32-bit unsigned integer.
  106. * Tangents : 32-bit float to 32-bit unsigned integer.
  107. * Vertex Colors : 32-bit float to 32-bit unsigned integer.
  108. * UV : 32-bit float to 32-bit unsigned integer.
  109. * UV2 : 32-bit float to 32-bit unsigned integer.
  110. * Vertex weights : 32-bit float to 16-bit unsigned integer.
  111. * Armature bones : 32-bit float to 16-bit unsigned integer.
  112. * Array index : 32-bit or 16-bit unsigned integer based on how many elements there are.
  113. Additional info:
  114. * UV2 = The second UV channel for detail textures and baked lightmap textures.
  115. * Array index = An array of numbers that number each element of the arrays above; i.e. they number the vertices and normals.
  116. In some cases, this might lead to loss of precision so disabling this option
  117. may be needed. For instance, if a mesh is very big or there are multiple meshes
  118. being imported that cover a large area, compressing the import of this mesh(s)
  119. may lead to gaps in geometry or vertices not being exactly where they should be.
  120. Meshes
  121. ~~~~~~~
  122. Ensure Tangents
  123. ^^^^^^^^^^^^^^^
  124. If textures with normalmapping are to be used, meshes need to have tangent arrays.
  125. This option ensures that these are generated if not present in the source scene.
  126. Godot uses Mikktspace for this, but it's always better to have them generated in
  127. the exporter.
  128. Storage
  129. ^^^^^^^
  130. Meshes can be stored in separate files (resources) instead of built-in. This does
  131. not have much practical use unless one wants to build objects with them directly.
  132. This option is provided to help those who prefer working directly with meshes
  133. instead of scenes.
  134. External Files
  135. ~~~~~~~~~~~~~~
  136. Generated meshes and materials can be optionally stored in a subdirectory with the
  137. name of the scene.
  138. Animation Options
  139. ------------------
  140. Godot provides many options regarding how animation data is dealt with. Some exporters
  141. (such as Blender), can generate many animations in a single file. Others, such as
  142. 3DS Max or Maya, need many animations put into the same timeline or, at worst, put
  143. each animation in a separate file.
  144. .. image:: img/scene_import3.png
  145. Import of animations is enabled by default.
  146. FPS
  147. ~~~~~~~~~~~~~~~
  148. Most 3D export formats store animation timeline in seconds instead of frames. To ensure
  149. animations are imported as faithfully as possible, please specify the frames per second
  150. used to edit them. Failing to do this may result in minimal jitter.
  151. Filter Script
  152. ~~~~~~~~~~~~~~~~~~~~~~~~~
  153. It is possible to specify a filter script in a special syntax to decide which tracks from which
  154. animations should be kept. (@TODO this needs documentation)
  155. Storage
  156. ~~~~~~~~~~~~~~~~~~~
  157. By default, animations are saved as built-in. It is possible to save them to a file instead. This
  158. allows adding custom tracks to the animations and keeping them after a reimport.
  159. Optimizer
  160. ~~~~~~~~~~~~~~~~~~~~~
  161. When animations are imported, an optimizer is run which reduces the size of the animation considerably.
  162. In general, this should always be turned on unless you suspect that an animation might be broken due to it being enabled.
  163. Clips
  164. ~~~~~~~~~~~~~~~~~~~~~
  165. It is possible to specify multiple animations from a single timeline as clips. Specify from which frame to which frame each
  166. clip must be taken (and, of course, don't forget to specify the FPS option above).
  167. Scene Inheritance
  168. -----------------
  169. In many cases, it may be desired to do modifications to the imported scene. By default, this is not possible because
  170. if the source asset changes (source .dae,.gltf,.obj file re-exported from 3D modelling app), Godot will re-import the whole scene.
  171. It is possible, however, to do local modifications by using *Scene Inheritance*. Try to open the imported scene and the
  172. following dialog will appear:
  173. .. image:: img/scene_import4.png
  174. In inherited scenes, the only limitations for modifications are:
  175. * Nodes can't be removed (but can be added anywhere).
  176. * Sub-Resources can't be edited (save them externally as described above for this)
  177. Other than that, everything is allowed!
  178. Import Hints
  179. ------------
  180. Many times, when editing a scene, there are common tasks that need to be done after exporting:
  181. * Adding collision detection to objects:
  182. * Setting objects as navigation meshes
  183. * Deleting nodes that are not used in the game engine (like specific lights used for modelling)
  184. To simplify this workflow, Godot offers a few suffixes that can be added to the names of the
  185. objects in your 3D modelling software. When imported, Godot will detect them and perform
  186. actions automatically:
  187. Remove nodes (-noimp)
  188. ~~~~~~~~~~~~~~~~~~~~~
  189. Node names that have this suffix will be removed at import time, mo
  190. matter what their type is. They will not appear in the imported scene.
  191. Create collisions (-col, -colonly, -convcolonly)
  192. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  193. Option "-col" will work only for Mesh nodes. If it is detected, a child
  194. static collision node will be added, using the same geometry as the mesh.
  195. However, it is often the case that the visual geometry is too complex or
  196. too un-smooth for collisions, which ends up not working well.
  197. To solve this, the "-colonly" modifier exists, which will remove the mesh upon
  198. import and create a :ref:`class_staticbody` collision instead.
  199. This helps the visual mesh and actual collision to be separated.
  200. Option "-convcolonly" will create :ref:`class_convexpolygonshape` instead of :ref:`class_concavepolygonshape`.
  201. Option "-colonly" can be also used with Blender's empty objects.
  202. On import it will create a :ref:`class_staticbody` with
  203. collision node as a child. Collision node will have one of predefined shapes,
  204. depending on the Blender's empty draw type:
  205. .. image:: img/3dimp_BlenderEmptyDrawTypes.png
  206. - Single arrow will create :ref:`class_rayshape`
  207. - Cube will create :ref:`class_boxshape`
  208. - Image will create :ref:`class_planeshape`
  209. - Sphere (and other non-listed) will create :ref:`class_sphereshape`
  210. For better visibility in Blender's editor user can set "X-Ray" option on collision
  211. empties and set some distinct color for them in User Preferences / Themes / 3D View / Empty.
  212. Create navigatopm (-navmesh)
  213. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  214. A mesh node with this suffix will be converted to a navigation mesh. Original Mesh node will be
  215. removed.
  216. Rigid Body (-rigid)
  217. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218. Creates a rigid body from this mesh.