importing_scenes.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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 **(recommended)**. Godot has full support for both text (``.gltf``) and binary (``.glb``) formats.
  11. * DAE (COLLADA), an older format that is fully supported.
  12. * OBJ (Wavefront) format + their MTL material files. This is also fully supported, but pretty limited (no support for pivots, skeletons, animations, PBR materials, ...).
  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. .. warning::
  40. Blend shape animations cannot be imported - they require manual animation within Godot.
  41. .. note::
  42. Blender versions older than 3.2 do not export emissive textures with the
  43. glTF file. If your model uses one and you're using an older version of
  44. Blender, it must be brought in separately.
  45. By default, Blender has backface culling disabled on materials and will
  46. export materials to match how they render in Blender. This means that
  47. materials in Godot will have their cull mode set to **Disabled**. This can
  48. decrease performance since backfaces will be rendered, even when they are
  49. being culled by other faces. To resolve this, enable **Backface Culling** in
  50. Blender's Materials tab, then export the scene to glTF again.
  51. Exporting DAE files from Blender
  52. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. Blender has built-in COLLADA support, but it does not work properly for the needs of game engines
  54. and should not be used as is.
  55. Godot provides a `Blender plugin <https://github.com/godotengine/collada-exporter>`_
  56. that will correctly export COLLADA scenes for use in Godot. It does not work in Blender 2.8 or
  57. newer, but there are plans to update it in the future.
  58. Exporting ESCN files from Blender
  59. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60. The most powerful one, called `godot-blender-exporter
  61. <https://github.com/godotengine/godot-blender-exporter>`__.
  62. It uses a .escn file, which is kind of another name for a .tscn file (Godot scene file);
  63. it keeps as much information as possible from a Blender scene. However, it is considered
  64. experimental.
  65. The ESCN exporter has a detailed `document <escn_exporter/index.html>`__ describing
  66. its functionality and usage.
  67. Exporting textures separately
  68. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  69. While textures can be exported with a model in certain file formats, such as glTF 2.0, you can also export them
  70. separately. Godot uses PBR (physically based rendering) for its materials, so if a texturing program can export PBR
  71. textures, they can work in Godot. This includes the `Substance suite <https://www.substance3d.com/>`__,
  72. `ArmorPaint (open source) <https://armorpaint.org/>`__, and `Material Maker (open source) <https://github.com/RodZill4/material-maker>`__.
  73. .. note:: For more information on Godot's materials, see :ref:`doc_spatial_material`.
  74. Exporting considerations
  75. ~~~~~~~~~~~~~~~~~~~~~~~~
  76. Since GPUs can only render triangles, meshes that contain quads or N-gons have
  77. to be *triangulated* before they can be rendered. Godot can triangulate meshes
  78. on import, but results may be unpredictable or incorrect, especially with
  79. N-gons. Regardless of the target application, triangulating *before* exporting
  80. the scene will lead to more consistent results and should be done whenever
  81. possible.
  82. To avoid issues with incorrect triangulation after importing in Godot, it is
  83. recommended to make the 3D DCC triangulate objects on its own. In Blender, this
  84. can be done by adding a Triangulate modifier to your objects and making sure
  85. **Apply Modifiers** is checked in the export dialog. Alternatively, depending on
  86. the exporter, you may be able to find and enable a **Triangulate Faces** option
  87. in the export dialog.
  88. To avoid issues with 3D selection in the editor, it is recommended to apply the
  89. object transform in the 3D DCC before exporting the scene.
  90. Import workflows
  91. ----------------
  92. Godot scene importer allows different workflows regarding how data is imported. Depending on many options, it is possible to
  93. import a scene with:
  94. * External materials (default): Where each material is saved to a file resource. Modifications to them are kept.
  95. * External meshes: Where each mesh is saved to a different file. Many users prefer to deal with meshes directly.
  96. * External animations: Allowing saved animations to be modified and merged when sources change.
  97. * External scenes: Save each of the root nodes of the imported scenes as a separate scene.
  98. * Single scene: A single scene file with everything built in.
  99. .. image:: img/scene_import1.png
  100. As different developers have different needs, this import process is highly customizable.
  101. Import options
  102. --------------
  103. The importer has several options, which will be discussed below:
  104. .. image:: img/scene_import2.png
  105. Nodes
  106. ~~~~~
  107. Root Type
  108. ^^^^^^^^^
  109. By default, the type of the root node in imported scenes is "Spatial", but this can be modified.
  110. Root Name
  111. ^^^^^^^^^
  112. Allows setting a specific name to the generated root node.
  113. Root Scale
  114. ^^^^^^^^^^
  115. The scale of the root node.
  116. Custom Script
  117. ^^^^^^^^^^^^^
  118. A special script to process the whole scene after import can be provided.
  119. This is great for post processing, changing materials, doing funny stuff
  120. with the geometry etc.
  121. Create a script like this:
  122. ::
  123. tool # Needed so it runs in the editor.
  124. extends EditorScenePostImport
  125. func post_import(scene):
  126. # Do your stuff here.
  127. return scene # remember to return the imported scene
  128. The ``post_import`` function takes the imported scene as argument (the
  129. parameter is actually the root node of the scene). The scene that
  130. will finally be used must be returned. It can be a different one.
  131. Storage
  132. ^^^^^^^
  133. By default, Godot imports a single scene. This option allows specifying
  134. that nodes below the root will each be a separate scene and instanced
  135. into the imported one.
  136. Of course, instancing such imported scenes in other places manually works, too.
  137. Materials
  138. ~~~~~~~~~
  139. Location
  140. ^^^^^^^^
  141. Godot supports materials in meshes or nodes. By default, materials will be put
  142. on each node.
  143. Storage
  144. ^^^^^^^
  145. Materials can be stored within the scene or in external files. By default,
  146. they are stored in external files so editing them is possible. This is because
  147. most 3D DCCs don't have the same material options as those present in Godot.
  148. When materials are built-in, they will be lost each time the source scene
  149. is modified and re-imported.
  150. .. note::
  151. Godot will not reimport materials that are stored in external files unless
  152. you remove the associated ``.material`` file before reimporting.
  153. To force reimporting materials every time the 3D scene is reimported, change
  154. the material storage mode in the 3D scene by selecting it in the FileSystem
  155. dock, going to the Import dock then setting **Material > Storage** to
  156. **Built-In** instead of **Files**.
  157. Keep On Reimport
  158. ^^^^^^^^^^^^^^^^
  159. Once materials are edited to use Godot features, the importer will keep the
  160. edited ones and ignore the ones coming from the source scene. This option
  161. is only present if materials are saved as files.
  162. Meshes
  163. ~~~~~~
  164. Compress
  165. ^^^^^^^^
  166. Makes meshes use less precise numbers for multiple aspects of the mesh in order
  167. to save space.
  168. These are:
  169. * Transform Matrix (Location, rotation, and scale) : 32-bit float to 16-bit signed integer.
  170. * Vertices : 32-bit float to 16-bit signed integer.
  171. * Normals : 32-bit float to 32-bit unsigned integer.
  172. * Tangents : 32-bit float to 32-bit unsigned integer.
  173. * Vertex Colors : 32-bit float to 32-bit unsigned integer.
  174. * UV : 32-bit float to 32-bit unsigned integer.
  175. * UV2 : 32-bit float to 32-bit unsigned integer.
  176. * Vertex weights : 32-bit float to 16-bit unsigned integer.
  177. * Armature bones : 32-bit float to 16-bit unsigned integer.
  178. * Array index : 32-bit or 16-bit unsigned integer based on how many elements there are.
  179. Additional info:
  180. * UV2 = The second UV channel for detail textures and baked lightmap textures.
  181. * Array index = An array of numbers that number each element of the arrays above; i.e. they number the vertices and normals.
  182. In some cases, this might lead to loss of precision, so disabling this option
  183. may be needed. For instance, if a mesh is very big or there are multiple meshes
  184. being imported that cover a large area, compressing the import of this mesh(es)
  185. may lead to gaps in geometry or vertices not being exactly where they should be.
  186. Ensure Tangents
  187. ^^^^^^^^^^^^^^^
  188. If textures with normal mapping are to be used, meshes need to have tangent arrays.
  189. This option ensures that these are generated if not present in the source scene.
  190. Godot uses `Mikktspace <http://www.mikktspace.com/>`__ for this,
  191. but it's always better to have them generated in the exporter.
  192. Storage
  193. ^^^^^^^
  194. Meshes can be stored in separate files (resources) instead of built-in. This does
  195. not have much practical use unless one wants to build objects with them directly.
  196. This option is provided to help those who prefer working directly with meshes
  197. instead of scenes.
  198. Light Baking
  199. ^^^^^^^^^^^^
  200. Whether or not the mesh is used in baked lightmaps.
  201. - **Disabled:** The mesh is not used in baked lightmaps.
  202. - **Enable:** The mesh is used in baked lightmaps.
  203. - **Gen Lightmaps:** The mesh is used in baked lightmaps, and unwraps a second UV layer for lightmaps.
  204. .. note:: For more information on light baking see :ref:`doc_baked_lightmaps`.
  205. External Files
  206. ~~~~~~~~~~~~~~
  207. Generated meshes and materials can be optionally stored in a subdirectory with the
  208. name of the scene.
  209. Animation options
  210. -----------------
  211. Godot provides many options regarding how animation data is dealt with. Some exporters
  212. (such as Blender) can generate many animations in a single file. Others, such as
  213. 3DS Max or Maya, need many animations put into the same timeline or, at worst, put
  214. each animation in a separate file.
  215. .. image:: img/scene_import3.png
  216. Import of animations is enabled by default.
  217. .. attention::
  218. To modify animations from an imported 3D scene, you need to change the animation
  219. storage option from **Built-In** to **Files** in the Import dock. Otherwise,
  220. changes made to animations from Godot will be lost when the project is run.
  221. FPS
  222. ~~~
  223. Most 3D export formats store animation timeline in seconds instead of frames. To ensure
  224. animations are imported as faithfully as possible, please specify the frames per second
  225. used to edit them. Failing to do this may result in shaky animations.
  226. Filter Script
  227. ~~~~~~~~~~~~~
  228. It is possible to specify a filter script in a special syntax to decide which tracks from which
  229. animations should be kept.
  230. The filter script is executed against each imported animation. The syntax consists of two types of
  231. statements, the first for choosing which animations to filter, and the second for filtering
  232. individual tracks within the matched animation. All name patterns are performed using a case
  233. insensitive expression match, using ``?`` and ``*`` wildcards (using ``String.matchn()`` under the
  234. hood).
  235. The script must start with an animation filter statement (as denoted by the line beginning with an
  236. ``@``). For example, if we would like to apply filters to all imported animations which have a name
  237. ending in ``"_Loop"``::
  238. @+*_Loop
  239. Similarly, additional patterns can be added to the same line, separated by commas. Here is a
  240. modified example to additionally *include* all animations with names that begin with ``"Arm_Left"``,
  241. but also *exclude* all animations which have names ending in ``"Attack"``::
  242. @+*_Loop, +Arm_Left*, -*Attack
  243. Following the animation selection filter statement, we add track filtering patterns to indicate
  244. which animation tracks should be kept or discarded. If no track filter patterns are specified, then
  245. all tracks within the matched animations will be discarded!
  246. It's important to note that track filter statements are applied in order for each track within the
  247. animation, this means that one line may include a track, a later rule can still discard it.
  248. Similarly, a track excluded by an early rule may then be re-included once again by a filter rule
  249. further down in the filter script.
  250. For example: include all tracks in animations with names ending in ``"_Loop"``, but discard any
  251. tracks affecting a ``"Skeleton"`` which end in ``"Control"``, unless they have ``"Arm"`` in their
  252. name::
  253. @+*_Loop
  254. +*
  255. -Skeleton:*Control
  256. +*Arm*
  257. In the above example, tracks like ``"Skeleton:Leg_Control"`` would be discarded, while tracks such
  258. as ``"Skeleton:Head"`` or ``"Skeleton:Arm_Left_Control"`` would be retained.
  259. Any track filter lines that do not begin with a ``+`` or ``-`` are ignored.
  260. Storage
  261. ~~~~~~~
  262. By default, animations are saved as built-in. It is possible to save them to a file instead. This
  263. allows adding custom tracks to the animations and keeping them after a reimport.
  264. Optimizer
  265. ~~~~~~~~~
  266. When animations are imported, an optimizer is run, which reduces the size of the animation considerably.
  267. In general, this should always be turned on unless you suspect that an animation might be broken due to it being enabled.
  268. Clips
  269. ~~~~~
  270. It is possible to specify multiple animations from a single timeline as clips. For this to work, the model
  271. must have only one animation that is named ``default``. To create clips, change the clip amount to something
  272. greater than zero. You can then name a clip, specify which frames it starts and stops on, and choose whether
  273. the animation loops or not.
  274. .. If this PR (https://github.com/godotengine/godot/pull/36709) is merged for Godot 4.0 this section must
  275. be updated to reflect that for the 4.0 documentation.
  276. Scene inheritance
  277. -----------------
  278. In many cases, it may be desired to make modifications to the imported scene. By default, this is not possible because
  279. if the source asset changes (source ``.dae``, ``.gltf``, ``.obj`` file re-exported from 3D modelling app), Godot will re-import the whole scene.
  280. It is possible, however, to make local modifications by using *Scene Inheritance*. Try to open the imported scene and the
  281. following dialog will appear:
  282. .. image:: img/scene_import4.png
  283. In inherited scenes, the only limitations for modifications are:
  284. * Nodes can't be removed (but can be added anywhere).
  285. * Sub-Resources can't be edited (save them externally as described above for this)
  286. Other than that, everything is allowed!
  287. .. _doc_importing_scenes_import_hints:
  288. Import hints
  289. ------------
  290. Many times, when editing a scene, there are common tasks that need to be done after exporting:
  291. - Adding collision detection to objects.
  292. - Setting objects as navigation meshes.
  293. - Deleting nodes that are not used in the game engine (like specific lights used for modelling).
  294. To simplify this workflow, Godot offers several suffixes that can be added to
  295. the names of the objects in your 3D modelling software. When imported, Godot
  296. will detect suffixes in object names and will perform actions automatically.
  297. .. note::
  298. All the suffixes described below are *case-sensitive*.
  299. Remove nodes (-noimp)
  300. ~~~~~~~~~~~~~~~~~~~~~
  301. Objects that have the ``-noimp`` suffix will be removed at import-time no matter
  302. what their type is. They will not appear in the imported scene.
  303. Create collisions (-col, -convcol, -colonly, -convcolonly)
  304. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  305. The option ``-col`` will work only for Mesh objects. If it is detected, a child
  306. static collision node will be added, using the same geometry as the mesh. This
  307. will create a triangle mesh collision shape, which is a slow, but accurate
  308. option for collision detection. This option is usually what you want for level
  309. geometry (but see also ``-colonly`` below).
  310. The option ``-convcol`` will create a :ref:`class_convexpolygonshape` instead of
  311. a :ref:`class_concavepolygonshape`. Unlike triangle meshes which can be concave,
  312. a convex shape can only accurately represent a shape that doesn't have any
  313. concave angles (a pyramid is convex, but a hollow box is concave). Due to this,
  314. convex collision shapes are generally not suited for level geometry. When
  315. representing simple enough meshes, convex collision shapes can result in better
  316. performance compared to a triangle collision shape. This option is ideal for
  317. simple or dynamic objects that require mostly-accurate collision detection.
  318. However, in both cases, the visual geometry may be too complex or not smooth
  319. enough for collisions. This can create physics glitches and slow down the engine
  320. unnecessarily.
  321. To solve this, the ``-colonly`` modifier exists. It will remove the mesh upon
  322. importing and will create a :ref:`class_staticbody` collision instead.
  323. This helps the visual mesh and actual collision to be separated.
  324. The option ``-convcolonly`` works in a similar way, but will create a :ref:`class_convexpolygonshape` instead.
  325. The option ``-colonly`` can also be used with Blender's empty objects.
  326. On import, it will create a :ref:`class_staticbody` with
  327. a collision node as a child. The collision node will have one of a number of predefined shapes,
  328. depending on Blender's empty draw type:
  329. .. image:: img/3dimp_BlenderEmptyDrawTypes.png
  330. - Single arrow will create a :ref:`class_rayshape`.
  331. - Cube will create a :ref:`class_boxshape`.
  332. - Image will create a :ref:`class_planeshape`.
  333. - Sphere (and the others not listed) will create a :ref:`class_sphereshape`.
  334. When possible, **try to use a few primitive collision shapes** instead of triangle
  335. mesh or convex shapes. Primitive shapes often have the best performance and
  336. reliability.
  337. .. note::
  338. For better visibility in Blender's editor, you can set the "X-Ray" option
  339. on collision empties and set some distinct color for them in Blender's
  340. **User Preferences > Themes > 3D View > Empty**.
  341. .. seealso::
  342. See :ref:`doc_collision_shapes_3d` for a comprehensive overview of collision
  343. shapes.
  344. Create navigation (-navmesh)
  345. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  346. A mesh node with the ``-navmesh`` suffix will be converted to a navigation mesh.
  347. The original Mesh object will be removed at import-time.
  348. Create a VehicleBody (-vehicle)
  349. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  350. A mesh node with the ``-vehicle`` suffix will be imported as a child to a
  351. :ref:`class_VehicleBody` node.
  352. Create a VehicleWheel (-wheel)
  353. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  354. A mesh node with the ``-wheel`` suffix will be imported as a child to a
  355. :ref:`class_VehicleWheel` node.
  356. Rigid Body (-rigid)
  357. ~~~~~~~~~~~~~~~~~~~
  358. A mesh node with the ``-rigid`` suffix will be imported as a :ref:`class_RigidBody`.
  359. Animation loop (-loop, -cycle)
  360. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  361. Animation clips in the COLLADA document that start or end with the token ``loop`` or ``cycle``
  362. will be imported as a Godot Animation with the loop flag set.
  363. **Unlike the other suffixes described above, this does not require a hyphen.**
  364. In Blender, this requires using the NLA Editor and naming the Action with the ``loop`` or
  365. ``cycle`` prefix or suffix.