importing_scenes.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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 formats*:
  10. * glTF 2.0. Godot has full support for text and binary formats.
  11. * DAE (COLLADA), an older format that is fully supported.
  12. * OBJ (Wavefront) formats. It is also fully supported, but pretty limited (no support for pivots, skeletons, etc).
  13. * ESCN, a Godot specific format that Blender can export with a plugin.
  14. * FBX, supported via the Open Asset Import library. However, FBX is proprietary, so we recommend using other formats
  15. listed above, if suitable for your workflow.
  16. Just copy the scene file together with the texture to the project repository, and Godot will do a full import.
  17. It is important that the mesh is not deformed by bones when exporting. Make sure that the skeleton is reset to its T-pose
  18. or default rest pose before exporting with your favorite 3D editor.
  19. Exporting DAE files from Maya and 3DS Max
  20. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. Autodesk added built-in COLLADA support to Maya and 3DS Max, but it's
  22. broken by default and should not be used. The best way to export this format
  23. is by using the
  24. `OpenCollada <https://github.com/KhronosGroup/OpenCOLLADA/wiki/OpenCOLLADA-Tools>`__
  25. plugins. They work well, although they are not always up-to date
  26. with the latest version of the software.
  27. Exporting glTF 2.0 files from Blender
  28. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. There are three ways to export glTF files from Blender. As a glTF binary (``.glb`` file), glTF embedded (``.gltf`` file),
  30. and with textures (``gltf`` + ``.bin`` + textures).
  31. glTF binary files are the smallest of the three options. They include the mesh and textures set up in Blender.
  32. When brought into Godot the textures are part of the object's material file.
  33. glTF embedded files function the same way as binary files. They don't provide extra functionality in Godot,
  34. and shouldn't be used since they have a larger file size.
  35. There are two reasons to use glTF with the textures separate. One is to have the scene description in a
  36. text based format and the binary data in a separate binary file. This can be useful for version control if you want to review
  37. changes in a text based format. The second is you need the texture files separate from the material file. If you don't need
  38. either of those glTF binary files are fine.
  39. .. note:: Blender does not export emissive textures with the glTF file. If your model uses one it must be brought in separately.
  40. Exporting DAE files from Blender
  41. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. Blender has built-in COLLADA support, but it does not work properly for the needs of game engines
  43. and should not be used as is.
  44. Godot provides a `Blender plugin <https://github.com/godotengine/collada-exporter>`_
  45. that will correctly export COLLADA scenes for use in Godot. It does not work in Blender 2.8 or
  46. newer, but there are plans to update it in the future.
  47. Exporting ESCN files from Blender
  48. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49. The most powerful one, called `godot-blender-exporter
  50. <https://github.com/godotengine/godot-blender-exporter>`__.
  51. It uses a .escn file, which is kind of another name for a .tscn file (Godot scene file);
  52. it keeps as much information as possible from a Blender scene. However, it is considered
  53. experimental.
  54. The ESCN exporter has a detailed `document <escn_exporter/index.html>`__ describing
  55. its functionality and usage.
  56. Import workflows
  57. ----------------
  58. Godot scene importer allows different workflows regarding how data is imported. Depending on many options, it is possible to
  59. import a scene with:
  60. * External materials (default): Where each material is saved to a file resource. Modifications to them are kept.
  61. * External meshes: Where each mesh is saved to a different file. Many users prefer to deal with meshes directly.
  62. * External animations: Allowing saved animations to be modified and merged when sources change.
  63. * External scenes: Save each of the root nodes of the imported scenes as a separate scene.
  64. * Single scene: A single scene file with everything built in.
  65. .. image:: img/scene_import1.png
  66. As different developers have different needs, this import process is highly customizable.
  67. Import options
  68. --------------
  69. The importer has several options, which will be discussed below:
  70. .. image:: img/scene_import2.png
  71. Nodes
  72. ~~~~~
  73. Root Type
  74. ^^^^^^^^^
  75. By default, the type of the root node in imported scenes is "Spatial", but this can be modified.
  76. Root Name
  77. ^^^^^^^^^
  78. Allows setting a specific name to the generated root node.
  79. Root Scale
  80. ^^^^^^^^^^
  81. The scale of the root node.
  82. Custom Script
  83. ^^^^^^^^^^^^^
  84. A special script to process the whole scene after import can be provided.
  85. This is great for post processing, changing materials, doing funny stuff
  86. with the geometry etc.
  87. Create a script like this:
  88. ::
  89. tool # Needed so it runs in the editor.
  90. extends EditorScenePostImport
  91. func post_import(scene):
  92. # Do your stuff here.
  93. return scene # remember to return the imported scene
  94. The ``post_import`` function takes the imported scene as argument (the
  95. parameter is actually the root node of the scene). The scene that
  96. will finally be used must be returned. It can be a different one.
  97. Storage
  98. ^^^^^^^
  99. By default, Godot imports a single scene. This option allows specifying
  100. that nodes below the root will each be a separate scene and instanced
  101. into the imported one.
  102. Of course, instancing such imported scenes in other places manually works, too.
  103. Materials
  104. ~~~~~~~~~
  105. Location
  106. ^^^^^^^^
  107. Godot supports materials in meshes or nodes. By default, materials will be put
  108. on each node.
  109. Storage
  110. ^^^^^^^
  111. Materials can be stored within the scene or in external files. By default,
  112. they are stored in external files so editing them is possible. This is because
  113. most 3D DCCs don't have the same material options as those present in Godot.
  114. When materials are built-in, they will be lost each time the source scene
  115. is modified and re-imported.
  116. Keep On Reimport
  117. ^^^^^^^^^^^^^^^^
  118. Once materials are edited to use Godot features, the importer will keep the
  119. edited ones and ignore the ones coming from the source scene. This option
  120. is only present if materials are saved as files.
  121. Meshes
  122. ~~~~~~
  123. Compress
  124. ^^^^^^^^
  125. Makes meshes use less precise numbers for multiple aspects of the mesh in order
  126. to save space.
  127. These are:
  128. * Transform Matrix (Location, rotation, and scale) : 32-bit float to 16-bit signed integer.
  129. * Vertices : 32-bit float to 16-bit signed integer.
  130. * Normals : 32-bit float to 32-bit unsigned integer.
  131. * Tangents : 32-bit float to 32-bit unsigned integer.
  132. * Vertex Colors : 32-bit float to 32-bit unsigned integer.
  133. * UV : 32-bit float to 32-bit unsigned integer.
  134. * UV2 : 32-bit float to 32-bit unsigned integer.
  135. * Vertex weights : 32-bit float to 16-bit unsigned integer.
  136. * Armature bones : 32-bit float to 16-bit unsigned integer.
  137. * Array index : 32-bit or 16-bit unsigned integer based on how many elements there are.
  138. Additional info:
  139. * UV2 = The second UV channel for detail textures and baked lightmap textures.
  140. * Array index = An array of numbers that number each element of the arrays above; i.e. they number the vertices and normals.
  141. In some cases, this might lead to loss of precision, so disabling this option
  142. may be needed. For instance, if a mesh is very big or there are multiple meshes
  143. being imported that cover a large area, compressing the import of this mesh(es)
  144. may lead to gaps in geometry or vertices not being exactly where they should be.
  145. Ensure Tangents
  146. ^^^^^^^^^^^^^^^
  147. If textures with normal mapping are to be used, meshes need to have tangent arrays.
  148. This option ensures that these are generated if not present in the source scene.
  149. Godot uses Mikktspace for this, but it's always better to have them generated in
  150. the exporter.
  151. Storage
  152. ^^^^^^^
  153. Meshes can be stored in separate files (resources) instead of built-in. This does
  154. not have much practical use unless one wants to build objects with them directly.
  155. This option is provided to help those who prefer working directly with meshes
  156. instead of scenes.
  157. Light Baking
  158. ^^^^^^^^^^^^
  159. Whether or not the mesh is used in baked lightmaps.
  160. - **Disabled:** The mesh is not used in baked lightmaps.
  161. - **Enable:** The mesh is used in baked lightmaps.
  162. - **Gen Lightmaps:** The mesh is used in baked lightmaps, and unwraps a second UV layer for lightmaps.
  163. .. note:: For more information on light baking see :ref:`doc_baked_lightmaps`.
  164. External Files
  165. ~~~~~~~~~~~~~~
  166. Generated meshes and materials can be optionally stored in a subdirectory with the
  167. name of the scene.
  168. Animation options
  169. -----------------
  170. Godot provides many options regarding how animation data is dealt with. Some exporters
  171. (such as Blender) can generate many animations in a single file. Others, such as
  172. 3DS Max or Maya, need many animations put into the same timeline or, at worst, put
  173. each animation in a separate file.
  174. .. image:: img/scene_import3.png
  175. Import of animations is enabled by default.
  176. FPS
  177. ~~~
  178. Most 3D export formats store animation timeline in seconds instead of frames. To ensure
  179. animations are imported as faithfully as possible, please specify the frames per second
  180. used to edit them. Failing to do this may result in shaky animations.
  181. Filter Script
  182. ~~~~~~~~~~~~~
  183. It is possible to specify a filter script in a special syntax to decide which tracks from which
  184. animations should be kept.
  185. The filter script is executed against each imported animation. The syntax consists of two types of
  186. statements, the first for choosing which animations to filter, and the second for filtering
  187. individual tracks within the matched animation. All name patterns are performed using a case
  188. insensitive expression match, using ``?`` and ``*`` wildcards (using ``String.matchn()`` under the
  189. hood).
  190. The script must start with an animation filter statement (as denoted by the line beginning with an
  191. ``@``). For example, if we would like to apply filters to all imported animations which have a name
  192. ending in ``"_Loop"``::
  193. @+*_Loop
  194. Similarly, additional patterns can be added to the same line, separated by commas. Here is a
  195. modified example to additionally *include* all animations with names that begin with ``"Arm_Left"``,
  196. but also *exclude* all animations which have names ending in ``"Attack"``::
  197. @+*_Loop, +Arm_Left*, -*Attack
  198. Following the animation selection filter statement, we add track filtering patterns to indicate
  199. which animation tracks should be kept or discarded. If no track filter patterns are specified, then
  200. all tracks within the matched animations will be discarded!
  201. It's important to note that track filter statements are applied in order for each track within the
  202. animation, this means that one line may include a track, a later rule can still discard it.
  203. Similarly, a track excluded by an early rule may then be re-included once again by a filter rule
  204. further down in the filter script.
  205. For example: include all tracks in animations with names ending in ``"_Loop"``, but discard any
  206. tracks affecting a ``"Skeleton"`` which end in ``"Control"``, unless they have ``"Arm"`` in their
  207. name::
  208. @+*_Loop
  209. +*
  210. -Skeleton:*Control
  211. +*Arm*
  212. In the above example, tracks like ``"Skeleton:Leg_Control"`` would be discarded, while tracks such
  213. as ``"Skeleton:Head"`` or ``"Skeleton:Arm_Left_Control"`` would be retained.
  214. Any track filter lines that do not begin with a ``+`` or ``-`` are ignored.
  215. Storage
  216. ~~~~~~~
  217. By default, animations are saved as built-in. It is possible to save them to a file instead. This
  218. allows adding custom tracks to the animations and keeping them after a reimport.
  219. Optimizer
  220. ~~~~~~~~~
  221. When animations are imported, an optimizer is run, which reduces the size of the animation considerably.
  222. In general, this should always be turned on unless you suspect that an animation might be broken due to it being enabled.
  223. Clips
  224. ~~~~~
  225. It is possible to specify multiple animations from a single timeline as clips. For this to work, the model
  226. must have only one animation that is named ``default``. To create clips, change the clip amount to something
  227. greater than zero. You can then name a clip, specify which frames it starts and stops on, and choose whether
  228. the animation loops or not.
  229. .. If this PR (https://github.com/godotengine/godot/pull/36709) is merged for Godot 4.0 this section must
  230. be updated to reflect that for the 4.0 documentation.
  231. Scene inheritance
  232. -----------------
  233. In many cases, it may be desired to make modifications to the imported scene. By default, this is not possible because
  234. if the source asset changes (source ``.dae``, ``.gltf``, ``.obj`` file re-exported from 3D modelling app), Godot will re-import the whole scene.
  235. It is possible, however, to make local modifications by using *Scene Inheritance*. Try to open the imported scene and the
  236. following dialog will appear:
  237. .. image:: img/scene_import4.png
  238. In inherited scenes, the only limitations for modifications are:
  239. * Nodes can't be removed (but can be added anywhere).
  240. * Sub-Resources can't be edited (save them externally as described above for this)
  241. Other than that, everything is allowed!
  242. Import hints
  243. ------------
  244. Many times, when editing a scene, there are common tasks that need to be done after exporting:
  245. * Adding collision detection to objects
  246. * Setting objects as navigation meshes
  247. * Deleting nodes that are not used in the game engine (like specific lights used for modelling)
  248. To simplify this workflow, Godot offers a few suffixes that can be added to the names of the
  249. objects in your 3D modelling software. When imported, Godot will detect them and perform
  250. actions automatically:
  251. Remove nodes (-noimp)
  252. ~~~~~~~~~~~~~~~~~~~~~
  253. Node names that have this suffix will be removed at import time, no
  254. matter what their type is. They will not appear in the imported scene.
  255. Create collisions (-col, -convcol, -colonly, -convcolonly)
  256. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  257. Option "-col" will work only for Mesh nodes. If it is detected, a child
  258. static collision node will be added, using the same geometry as the mesh.
  259. Option "-convcol" will create a :ref:`class_convexpolygonshape` instead of a :ref:`class_concavepolygonshape`.
  260. However, it is often the case that the visual geometry is too complex or
  261. too un-smooth for collisions, which ends up not working well.
  262. To solve this, the "-colonly" modifier exists, which will remove the mesh upon
  263. import and create a :ref:`class_staticbody` collision instead.
  264. This helps the visual mesh and actual collision to be separated.
  265. Option "-convcolonly" works in a similar way but will create a :ref:`class_convexpolygonshape` instead.
  266. Option "-colonly" can also be used with Blender's empty objects.
  267. On import, it will create a :ref:`class_staticbody` with
  268. a collision node as a child. The collision node will have one of a number of predefined shapes,
  269. depending on Blender's empty draw type:
  270. .. image:: img/3dimp_BlenderEmptyDrawTypes.png
  271. - Single arrow will create a :ref:`class_rayshape`
  272. - Cube will create a :ref:`class_boxshape`
  273. - Image will create a :ref:`class_worldmarginshape`
  274. - Sphere (and the others not listed) will create a :ref:`class_sphereshape`
  275. For better visibility in Blender's editor, the user can set "X-Ray" option on collision
  276. empties and set some distinct color for them in User Preferences / Themes / 3D View / Empty.
  277. Create navigation (-navmesh)
  278. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  279. A mesh node with this suffix will be converted to a navigation mesh. Original Mesh node will be
  280. removed.
  281. Create a VehicleBody (-vehicle)
  282. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  283. A mesh node with this suffix will be imported as a child to a :ref:`VehicleBody <class_VehicleBody>` node.
  284. Create a VehicleWheel (-wheel)
  285. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  286. A mesh node with this suffix will be imported as a child to a :ref:`VehicleWheel <class_VehicleWheel>` node.
  287. Rigid Body (-rigid)
  288. ~~~~~~~~~~~~~~~~~~~
  289. Creates a rigid body from this mesh.
  290. Animation loop (-loop, -cycle)
  291. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  292. Animation clips in the COLLADA document that start or end with the token "loop" or "cycle"
  293. will be imported as a Godot Animation with the loop flag set. This is case-sensitive and
  294. does not require a hyphen.
  295. In Blender, this requires using the NLA Editor and naming the Action with the "loop" or
  296. "cycle" prefix or suffix.