importing_scenes.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. Exporting ESCN files from Blender
  37. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  38. The most powerful one, called `godot-blender-exporter
  39. <https://github.com/godotengine/godot-blender-exporter>`__.
  40. It uses .escn files which is kind of another name of .tscn file(Godot scene file),
  41. it keeps as much information as possible from a Blender scene.
  42. ESCN exporter has a detailed `document <escn_exporter/index.html>`__ describing
  43. its functionality and usage.
  44. Import workflows
  45. ----------------
  46. Godot scene importer allows different workflows regarding how data is imported. Depending on many options, it is possible to
  47. import a scene with:
  48. * External materials (default): Where each material is saved to a file resource. Modifications to them are kept.
  49. * External meshes: Where each mesh is saved to a different file. Many users prefer to deal with meshes directly.
  50. * External animations: Allowing saved animations to be modified and merged when sources change.
  51. * External scenes: Save the root nodes of the imported scenes each as a separate scene.
  52. * Single Scene: A single scene file with everything built in.
  53. .. image:: img/scene_import1.png
  54. As different developers have different needs, this import process is highly customizable.
  55. Import options
  56. --------------
  57. The importer has several options, which will be discussed below:
  58. .. image:: img/scene_import2.png
  59. Nodes
  60. ~~~~~
  61. Root Type
  62. ^^^^^^^^^
  63. By default, the type of the root node in imported scenes is "Spatial", but this can be modified.
  64. Root Name
  65. ^^^^^^^^^
  66. Allows setting a specific name to the generated root node.
  67. Custom Script
  68. ^^^^^^^^^^^^^
  69. A special script to process the whole scene after import can be provided.
  70. This is great for post processing, changing materials, doing funny stuff
  71. with the geometry etc.
  72. Create a script that like this:
  73. ::
  74. tool # needed so it runs in editor
  75. extends EditorScenePostImport
  76. func post_import(scene):
  77. # do your stuff here
  78. return scene # remember to return the imported scene
  79. The post-import function takes the imported scene as argument (the
  80. parameter is actually the root node of the scene). The scene that
  81. will finally be used must be returned. It can be a different one.
  82. Storage
  83. ^^^^^^^
  84. By default, Godot imports a single scene. This option allows specifying
  85. that nodes below the root will each be a separate scene and instanced
  86. into the imported one.
  87. Of course, instancing such imported scenes in other places manually works too.
  88. Materials
  89. ~~~~~~~~~
  90. Location
  91. ^^^^^^^^
  92. Godot supports materials in meshes or nodes. By default, materials will be put
  93. on each node.
  94. Storage
  95. ^^^^^^^
  96. Materials can be stored within the scene or in external files. By default,
  97. they are stored in external files so editing them is possible. This is because
  98. most 3D DCCs don't have the same material options as those present in Godot.
  99. When materials are built-in, they will be lost each time the source scene
  100. is modified and re-imported.
  101. Keep on Reimport
  102. ^^^^^^^^^^^^^^^^
  103. Once materials are edited to use Godot features, the importer will keep the
  104. edited ones and ignore the ones coming from the source scene. This option
  105. is only present if materials are saved as files.
  106. Compress
  107. ^^^^^^^^
  108. Makes meshes use less precise numbers for multiple aspects of the mesh in order
  109. to save space.
  110. These are:
  111. * Transform Matrix (Location, rotation, and scale) : 32-bit float to 16-bit signed integer.
  112. * Vertices : 32-bit float to 16-bit signed integer.
  113. * Normals : 32-bit float to 32-bit unsigned integer.
  114. * Tangents : 32-bit float to 32-bit unsigned integer.
  115. * Vertex Colors : 32-bit float to 32-bit unsigned integer.
  116. * UV : 32-bit float to 32-bit unsigned integer.
  117. * UV2 : 32-bit float to 32-bit unsigned integer.
  118. * Vertex weights : 32-bit float to 16-bit unsigned integer.
  119. * Armature bones : 32-bit float to 16-bit unsigned integer.
  120. * Array index : 32-bit or 16-bit unsigned integer based on how many elements there are.
  121. Additional info:
  122. * UV2 = The second UV channel for detail textures and baked lightmap textures.
  123. * Array index = An array of numbers that number each element of the arrays above; i.e. they number the vertices and normals.
  124. In some cases, this might lead to loss of precision so disabling this option
  125. may be needed. For instance, if a mesh is very big or there are multiple meshes
  126. being imported that cover a large area, compressing the import of this mesh(s)
  127. may lead to gaps in geometry or vertices not being exactly where they should be.
  128. Meshes
  129. ~~~~~~
  130. Ensure Tangents
  131. ^^^^^^^^^^^^^^^
  132. If textures with normalmapping are to be used, meshes need to have tangent arrays.
  133. This option ensures that these are generated if not present in the source scene.
  134. Godot uses Mikktspace for this, but it's always better to have them generated in
  135. the exporter.
  136. Storage
  137. ^^^^^^^
  138. Meshes can be stored in separate files (resources) instead of built-in. This does
  139. not have much practical use unless one wants to build objects with them directly.
  140. This option is provided to help those who prefer working directly with meshes
  141. instead of scenes.
  142. External Files
  143. ~~~~~~~~~~~~~~
  144. Generated meshes and materials can be optionally stored in a subdirectory with the
  145. name of the scene.
  146. Animation Options
  147. -----------------
  148. Godot provides many options regarding how animation data is dealt with. Some exporters
  149. (such as Blender), can generate many animations in a single file. Others, such as
  150. 3DS Max or Maya, need many animations put into the same timeline or, at worst, put
  151. each animation in a separate file.
  152. .. image:: img/scene_import3.png
  153. Import of animations is enabled by default.
  154. FPS
  155. ~~~
  156. Most 3D export formats store animation timeline in seconds instead of frames. To ensure
  157. animations are imported as faithfully as possible, please specify the frames per second
  158. used to edit them. Failing to do this may result in minimal jitter.
  159. Filter Script
  160. ~~~~~~~~~~~~~
  161. It is possible to specify a filter script in a special syntax to decide which tracks from which
  162. animations should be kept. (@TODO this needs documentation)
  163. Storage
  164. ~~~~~~~
  165. By default, animations are saved as built-in. It is possible to save them to a file instead. This
  166. allows adding custom tracks to the animations and keeping them after a reimport.
  167. Optimizer
  168. ~~~~~~~~~
  169. When animations are imported, an optimizer is run which reduces the size of the animation considerably.
  170. In general, this should always be turned on unless you suspect that an animation might be broken due to it being enabled.
  171. Clips
  172. ~~~~~
  173. It is possible to specify multiple animations from a single timeline as clips. Specify from which frame to which frame each
  174. clip must be taken (and, of course, don't forget to specify the FPS option above).
  175. Scene inheritance
  176. -----------------
  177. In many cases, it may be desired to do modifications to the imported scene. By default, this is not possible because
  178. if the source asset changes (source .dae,.gltf,.obj file re-exported from 3D modelling app), Godot will re-import the whole scene.
  179. It is possible, however, to do local modifications by using *Scene Inheritance*. Try to open the imported scene and the
  180. following dialog will appear:
  181. .. image:: img/scene_import4.png
  182. In inherited scenes, the only limitations for modifications are:
  183. * Nodes can't be removed (but can be added anywhere).
  184. * Sub-Resources can't be edited (save them externally as described above for this)
  185. Other than that, everything is allowed!
  186. Import hints
  187. ------------
  188. Many times, when editing a scene, there are common tasks that need to be done after exporting:
  189. * Adding collision detection to objects:
  190. * Setting objects as navigation meshes
  191. * Deleting nodes that are not used in the game engine (like specific lights used for modelling)
  192. To simplify this workflow, Godot offers a few suffixes that can be added to the names of the
  193. objects in your 3D modelling software. When imported, Godot will detect them and perform
  194. actions automatically:
  195. Remove nodes (-noimp)
  196. ~~~~~~~~~~~~~~~~~~~~~
  197. Node names that have this suffix will be removed at import time, no
  198. matter what their type is. They will not appear in the imported scene.
  199. Create collisions (-col, -colonly, -convcolonly)
  200. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  201. Option "-col" will work only for Mesh nodes. If it is detected, a child
  202. static collision node will be added, using the same geometry as the mesh.
  203. However, it is often the case that the visual geometry is too complex or
  204. too un-smooth for collisions, which ends up not working well.
  205. To solve this, the "-colonly" modifier exists, which will remove the mesh upon
  206. import and create a :ref:`class_staticbody` collision instead.
  207. This helps the visual mesh and actual collision to be separated.
  208. Option "-convcolonly" will create :ref:`class_convexpolygonshape` instead of :ref:`class_concavepolygonshape`.
  209. Option "-colonly" can be also used with Blender's empty objects.
  210. On import it will create a :ref:`class_staticbody` with
  211. collision node as a child. Collision node will have one of predefined shapes,
  212. depending on the Blender's empty draw type:
  213. .. image:: img/3dimp_BlenderEmptyDrawTypes.png
  214. - Single arrow will create :ref:`class_rayshape`
  215. - Cube will create :ref:`class_boxshape`
  216. - Image will create :ref:`class_planeshape`
  217. - Sphere (and other non-listed) will create :ref:`class_sphereshape`
  218. For better visibility in Blender's editor user can set "X-Ray" option on collision
  219. empties and set some distinct color for them in User Preferences / Themes / 3D View / Empty.
  220. Create navigation (-navmesh)
  221. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  222. A mesh node with this suffix will be converted to a navigation mesh. Original Mesh node will be
  223. removed.
  224. Rigid Body (-rigid)
  225. ~~~~~~~~~~~~~~~~~~~
  226. Creates a rigid body from this mesh.