importing_scenes.rst 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  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
  8. your favorite 3D modeling software will be 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``)
  11. and binary (``.glb``) formats.
  12. - ``.blend`` (Blender). This works by calling Blender to export to glTF in a
  13. transparent manner (requires Blender to be installed).
  14. - DAE (COLLADA), an older format that is fully supported.
  15. - OBJ (Wavefront) format + their MTL material files. This is also fully
  16. supported, but pretty limited given the format's limitations (no support for
  17. pivots, skeletons, animations, UV2, PBR materials, ...).
  18. - FBX, supported via `FBX2glTF <https://github.com/godotengine/FBX2glTF>`__ integration.
  19. This requires installing an external program that links against the proprietary FBX SDK,
  20. so we recommend using other formats listed above (if suitable for your workflow).
  21. Copy the scene file together with the textures and mesh data (if separate) to
  22. the project repository, then Godot will do a full import when focusing the
  23. editor window.
  24. 3D asset direction conventions
  25. ------------------------------
  26. Godot uses a right-handed, Y-is-up coordinate system, with the -Z axis as
  27. the camera's forward direction. This is the same as OpenGL. This implies
  28. that +Z is back, +X is right, and -X is left for a camera.
  29. The convention for 3D assets is to face the opposite direction as the camera,
  30. so that characters and other assets are facing the camera by default.
  31. This convention is extremely common in 3D modeling applications, and is
  32. `codified in glTF as part of the glTF 2.0 specification <https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#coordinate-system-and-units>`__.
  33. This means that for oriented 3D assets (such as characters),
  34. the +Z axis is the direction of the front, so -Z is the rear,
  35. +X is the left side, and -X is the right side for a 3D asset.
  36. In Blender, this means that +Y is rear and -Y is front for an asset.
  37. When rotating an oriented 3D asset in Godot, use the ``use_model_front``
  38. option on the ``look_at`` functions, and use the ``Vector3.MODEL_*``
  39. constants to perform calculations in the oriented asset's local space.
  40. For assets without an intrinsic front side or forward direction, such as
  41. a game map or terrain, take note of the cardinal directions instead.
  42. The convention in Godot and the vast majority of other applications is
  43. that +X is east and -X is west. Due to Godot's right-handed Y-is-up
  44. coordinate system, this implies that +Z is south and -Z is north.
  45. In Blender, this means that +Y is north and -Y is south.
  46. Exporting glTF 2.0 files from Blender (recommended)
  47. ---------------------------------------------------
  48. There are 3 ways to export glTF files from Blender:
  49. - As a glTF binary file (``.glb``).
  50. - As a glTF text-based file with embedded binary data (``.gltf`` file)
  51. - As a glTF text-based file with separate binary data and textures (``.gltf``
  52. file + ``.bin`` file + textures).
  53. glTF binary files (``.glb``) are the smallest of the three options. They include
  54. the mesh and textures set up in Blender. When brought into Godot the textures
  55. are part of the object's material file.
  56. glTF embedded files (``.gltf``) function the same way as binary files. They
  57. don't provide extra functionality in Godot, and shouldn't be used since they
  58. have a larger file size.
  59. There are two reasons to use glTF with the textures separate. One is to have the
  60. scene description in a text based format and the binary data in a separate
  61. binary file. This can be useful for version control if you want to review
  62. changes in a text-based format. The second is you need the texture files
  63. separate from the material file. If you don't need either of those, glTF binary
  64. files are fine.
  65. .. warning::
  66. If your model contains blend shapes (also known as "shape keys" and "morph
  67. targets"), your glTF export setting **Export Deformation Bones Only** needs
  68. to be configured to **Enabled** under the Animation export configurations.
  69. Exporting non-deforming bones anyway will lead to incorrect shading.
  70. .. note::
  71. Blender versions older than 3.2 do not export emissive textures with the
  72. glTF file. If your model uses one and you're using an older version of
  73. Blender, it must be brought in separately.
  74. By default, Blender has backface culling disabled on materials and will
  75. export materials to match how they render in Blender. This means that
  76. materials in Godot will have their cull mode set to **Disabled**. This can
  77. decrease performance since backfaces will be rendered, even when they are
  78. being culled by other faces. To resolve this, enable **Backface Culling** in
  79. Blender's Materials tab, then export the scene to glTF again.
  80. Importing ``.blend`` files directly within Godot
  81. ------------------------------------------------
  82. .. note::
  83. This functionality requires Blender 3.0 or later.
  84. From Godot 4.0 onwards, the editor can directly import ``.blend`` files by
  85. calling `Blender <https://www.blender.org/>`__'s glTF export functionality in a
  86. transparent manner.
  87. This allows you to iterate on your 3D scenes faster, as you can save the scene
  88. in Blender, alt-tab back to Godot then see your changes immediately. When
  89. working with version control, this is also more efficient as you no longer need
  90. to commit a copy of the exported glTF file to version control.
  91. To use ``.blend`` import, you must install Blender before opening the Godot
  92. editor (if opening a project that already contains ``.blend`` files). If you
  93. keep Blender installed at its default location, Godot should be able to detect
  94. its path automatically. If this isn't the case, configure the path to the
  95. Blender executable in the Editor Settings (**Filesystem > Import > Blender >
  96. Blender 3 Path**).
  97. If you keep ``.blend`` files within your project folder but don't want them to
  98. be imported by Godot, disable **Filesystem > Import > Blender > Enabled** in the
  99. advanced Project Settings.
  100. .. note::
  101. When working in a team, keep in mind using ``.blend`` files in your project
  102. will require *all* team members to have Blender installed. While Blender is
  103. a free download, this may add friction when working on the project.
  104. ``.blend`` import is also not available on the Android and web editors, as
  105. these platforms can't call external programs.
  106. If this is problematic, consider using glTF scenes exported from Blender
  107. instead.
  108. Exporting DAE files from Blender
  109. --------------------------------
  110. Blender has built-in COLLADA support, but it does not work properly for the
  111. needs of game engines and shouldn't be used as-is. However, scenes exported with
  112. the built-in Collada support may still work for simple scenes without animation.
  113. For complex scenes or scenes that contain animations, Godot provides a
  114. `Blender plugin <https://github.com/godotengine/collada-exporter>`_
  115. that will correctly export COLLADA scenes for use in Godot.
  116. Importing OBJ files in Godot
  117. ----------------------------
  118. OBJ is one of the simplest 3D formats out there, so Godot should be able to
  119. import most OBJ files successfully. However, OBJ is also a very limited format:
  120. it doesn't support skinning, animation, UV2 or PBR materials.
  121. There are 2 ways to use OBJ meshes in Godot:
  122. - Load them directly in a MeshInstance3D node, or any other property that
  123. expects as mesh (such as GPUParticles3D). This is the default mode.
  124. - Change their import mode to **OBJ as Scene** in the Import dock then restart
  125. the editor. This allows you to use the same import options as glTF or Collada
  126. scenes, such as unwrapping UV2 on import (for :ref:`doc_using_lightmap_gi`).
  127. .. note::
  128. Blender 3.4 and later can export RGB vertex colors in OBJ files (this is a
  129. nonstandard extension of the OBJ format). Godot is able to import those
  130. vertex colors since Godot 4.0, but they will not be displayed on the
  131. material unless you enable **Vertex Color > Use As Albedo** on the material.
  132. Vertex colors from OBJ meshes keep their original color space once imported
  133. (sRGB/linear), but their brightness is clamped to 1.0 (they can't be
  134. overbright).
  135. Importing FBX files in Godot
  136. ----------------------------
  137. When opening a project containing FBX scenes, you will see a dialog asking you
  138. to configure FBX import. Click the link in the dialog to download a fbx2gltf
  139. binary, then extract the ZIP archive, place the binary anywhere you wish, then
  140. specify its path in the dialog.
  141. If you keep ``.fbx`` files within your project folder but don't want them to
  142. be imported by Godot, disable **Filesystem > Import > FBX > Enabled** in the
  143. advanced Project Settings.
  144. .. seealso::
  145. The full installation process for using FBX in Godot is described on the
  146. `FBX import page of the Godot website <https://godotengine.org/fbx-import>`__.
  147. Exporting textures separately
  148. -----------------------------
  149. While textures can be exported with a model in certain file formats, such as glTF 2.0, you can also export them
  150. separately. Godot uses PBR (physically based rendering) for its materials, so if a texturing program can export PBR
  151. textures they can work in Godot. This includes the `Substance suite <https://www.substance3d.com/>`__,
  152. `ArmorPaint (open source) <https://armorpaint.org/>`__, and `Material Maker (open source) <https://github.com/RodZill4/material-maker>`__.
  153. .. note:: For more information on Godot's materials, see :ref:`doc_standard_material_3d`.
  154. Exporting considerations
  155. ------------------------
  156. Since GPUs can only render triangles, meshes that contain quads or N-gons have
  157. to be *triangulated* before they can be rendered. Godot can triangulate meshes
  158. on import, but results may be unpredictable or incorrect, especially with
  159. N-gons. Regardless of the target application, triangulating *before* exporting
  160. the scene will lead to more consistent results and should be done whenever
  161. possible.
  162. To avoid issues with incorrect triangulation after importing in Godot, it is
  163. recommended to make the 3D modeling software triangulate objects on its own. In
  164. Blender, this can be done by adding a Triangulate modifier to your objects and
  165. making sure **Apply Modifiers** is checked in the export dialog. Alternatively,
  166. depending on the exporter, you may be able to find and enable a **Triangulate
  167. Faces** option in the export dialog.
  168. To avoid issues with 3D selection in the editor, it is recommended to apply the
  169. object transform in the 3D modeling software before exporting the scene.
  170. .. note::
  171. It is important that the mesh is not deformed by bones when exporting. Make sure
  172. that the skeleton is reset to its T-pose or default rest pose before exporting
  173. with your favorite 3D editor.
  174. Import workflows
  175. ----------------
  176. Since Godot can only save its own scene format (``.tscn``/``.scn``), Godot
  177. cannot save over the original 3D scene file (which uses a different format).
  178. This is also a safer approach as it avoids making accidental changes to the
  179. source file.
  180. To allow customizing the scene and its materials, Godot's scene importer allows
  181. for different workflows regarding how data is imported.
  182. .. figure:: img/importing_3d_scenes_import_dock.webp
  183. :align: center
  184. :alt: Import dock after selecting a 3D scene in the FileSystem dock
  185. Import dock after selecting a 3D scene in the FileSystem dock
  186. This import process is customizable using 3 separate interfaces, depending on your needs:
  187. - The **Import** dock, after selecting the 3D scene by clicking it once in the
  188. FileSystem dock.
  189. - The **Advanced Import Settings** dialog, which can be accessed by double-clicking
  190. the 3D scene in the FileSystem dock or by clicking the **Advanced…** button in
  191. the Import dock. This allows you to customize per-object options in Godot.
  192. - :ref:`Import hints <doc_importing_3d_scenes_import_hints>`, which are special
  193. suffixes added to object names in the 3D modeling software. This allows you to
  194. customize per-object options in the 3D modeling software.
  195. For basic customization, using the Import dock suffices. However, for more
  196. complex operations such as defining material overrides on a per-material basis,
  197. you'll need to use the Advanced Import Settings dialog, import hints, or possibly both.
  198. .. _doc_importing_3d_scenes_using_the_import_dock:
  199. Using the Import dock
  200. ^^^^^^^^^^^^^^^^^^^^^
  201. The following options can be adjusted in the Import dock after selecting a 3D
  202. scene in the FileSystem dock:
  203. - **Root Type:** The node type to use as a root node. Using node types that
  204. inherit from Node3D is recommended. Otherwise, you'll lose the ability to
  205. position the node directly in the 3D editor.
  206. - **Root Name:** The name of the root node in the imported scene. This is
  207. generally not noticeable when instancing the scene in the editor (or
  208. drag-and-dropping from the FileSystem dock), as the root node is renamed to
  209. match the filename in this case.
  210. - **Apply Root Scale:** If enabled, **Root Scale** will be *applied* on the
  211. meshes and animations directly, while keeping the root node's scale to the
  212. default `(1, 1, 1)`. This means that if you add a child node later on within
  213. the imported scene, it won't be scaled. If disabled, **Root Scale** will
  214. multiply the scale of the root node instead.
  215. **Meshes**
  216. - **Ensure Tangents:** If checked, generate vertex tangents using
  217. `Mikktspace <http://www.mikktspace.com/>`__ if the input meshes don't have
  218. tangent data. When possible, it's recommended to let the 3D modeling software
  219. generate tangents on export instead on relying on this option. Tangents are
  220. required for correct display of normal and height maps, along with any
  221. material/shader features that require tangents. If you don't need material
  222. features that require tangents, disabling this can reduce output file size and
  223. speed up importing if the source 3D file doesn't contain tangents.
  224. - **Generate LODs:** If checked, generates lower detail variants of the
  225. mesh which will be displayed in the distance to improve rendering performance.
  226. Not all meshes benefit from LOD, especially if they are never rendered from
  227. far away. Disabling this can reduce output file size and speed up importing.
  228. See :ref:`doc_mesh_lod` for more information.
  229. - **Create Shadow Meshes:** If checked, enables the generation of
  230. shadow meshes on import. This optimizes shadow rendering without reducing
  231. quality by welding vertices together when possible. This in turn reduces the
  232. memory bandwidth required to render shadows. Shadow mesh generation currently
  233. doesn't support using a lower detail level than the source mesh (but shadow
  234. rendering will make use of LODs when relevant).
  235. - **Light Baking:** Configures the meshes'
  236. :ref:`global illumination mode <class_GeometryInstance3D_property_gi_mode>`
  237. in the 3D scene. If set to **Static Lightmaps**, sets the meshes' GI mode to
  238. **Static** and generates UV2 on import for :ref:`lightmap baking <doc_using_lightmap_gi>`.
  239. - **Lightmap Texel Size:** Only visible if **Light Baking** is set to **Static
  240. Lightmaps**. Controls the size of each texel on the baked lightmap. A smaller
  241. value results in more precise lightmaps, at the cost of larger lightmap sizes
  242. and longer bake times.
  243. **Skins**
  244. - **Use Named Skins:** If checked, use named :ref:`Skins <class_Skin>` for animation.
  245. The :ref:`class_MeshInstance3D` node contains 3 properties of relevance here: a skeleton
  246. NodePath pointing to the Skeleton3D node (usually ``..``), a mesh, and a skin:
  247. - The :ref:`class_Skeleton3D` node contains a list of bones with names, their pose and rest,
  248. a name and a parent bone.
  249. - The mesh is all of the raw vertex data needed to display a mesh. In terms of the mesh,
  250. it knows how vertices are weight-painted and uses some internal numbering
  251. often imported from 3D modeling software.
  252. - The skin contains the information necessary to bind this mesh onto this Skeleton3D.
  253. For every one of the internal bone IDs chosen by the 3D modeling software, it contains two things.
  254. Firstly, a Matrix known as the Bind Pose Matrix, Inverse Bind Matrix, or IBM for short.
  255. Secondly, the Skin contains each bone's name (if **Use Named Skins** is enabled),
  256. or the bone's index within the Skeleton3D list (if **Use Named Skins** is disabled).
  257. Together, this information is enough to tell Godot how to use the bone poses in
  258. the Skeleton3D node to render the mesh from each MeshInstance3D. Note that each
  259. MeshInstance3D may share binds, as is common in models exported from Blender, or
  260. each MeshInstance3D may use a separate Skin object, as is common in models
  261. exported from other tools such as Maya.
  262. **Animation**
  263. - **Import:** If checked, import animations from the 3D scene.
  264. - **FPS:** The number of frames per second to use for baking animation curves to
  265. a series of points with linear interpolation. It's recommended to configure
  266. this value to match the value you're using as a baseline in your 3D modeling
  267. software. Higher values result in more precise animation with fast movement
  268. changes, at the cost of higher file sizes and memory usage. Thanks to
  269. interpolation, there is usually not much benefit in going above 30 FPS (as the
  270. animation will still appear smooth at higher rendering framerates).
  271. - **Trimming:** Trim the beginning and end of animations if there are no
  272. keyframe changes. This can reduce output file size and memory usage with
  273. certain 3D scenes, depending on the contents of their animation tracks.
  274. - **Remove Immutable Tracks:** Remove animation tracks that only contain default
  275. values. This can reduce output file size and memory usage with certain 3D
  276. scenes, depending on the contents of their animation tracks.
  277. **Import Script**
  278. - **Path:** Path to an import script, which can run code *after*
  279. the import process has completed for custom processing.
  280. See :ref:`doc_importing_3d_scenes_import_script` for more information.
  281. **glTF**
  282. - **Embedded Texture Handling:** Controls how textures embedded within glTF
  283. scenes should be handled. **Discard All Textures** will not import any
  284. textures, which is useful if you wish to manually set up materials in Godot
  285. instead. **Extract Textures** extracts textures to external images, resulting
  286. in smaller file sizes and more control over import options. **Embed as Basis
  287. Universal** and **Embed as Uncompressed** keeps the textures embedded in the
  288. imported scene, with and without VRAM compression respectively.
  289. Using the Advanced Import Settings dialog
  290. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  291. The first tab you'll see is the **Scene** tab. The options available in the
  292. panel on the right are identical to the Import dock, but you have access to a 3D
  293. preview. The 3D preview can be rotated by holding down the left mouse button
  294. then dragging the mouse. Zoom can be adjusted using the mouse wheel.
  295. .. figure:: img/importing_3d_scenes_advanced_import_settings_scene.webp
  296. :align: center
  297. :alt: Advanced Import Settings dialog (Scene tab)
  298. Advanced Import Settings dialog (Scene tab).
  299. Credit: `Modern Arm Chair 01 - Poly Haven <https://polyhaven.com/a/modern_arm_chair_01>`__
  300. **Configuring node import options**
  301. You can select individual nodes that compose the scene while in the **Scene**
  302. tab using the tree view at the left:
  303. .. figure:: img/importing_3d_scenes_advanced_import_settings_node.webp
  304. :align: center
  305. :alt: Selecting a node in the Advanced Import Settings dialog (Scene tab)
  306. Selecting a node in the Advanced Import Settings dialog (Materials tab)
  307. This exposes several per-node import options:
  308. - **Skip Import:** If checked, the node will not be present in the final
  309. imported scene. Enabling this disables all other options.
  310. - **Generate > Physics:** If checked, generates a PhysicsBody3D *parent* node
  311. with collision shapes that are *siblings* to the MeshInstance3D node.
  312. - **Generate > NavMesh:** If checked, generates a NavigationRegion3D *child*
  313. node for :ref:`navigation <doc_navigation_overview_3d>`. **Mesh + NavMesh**
  314. will keep the original mesh visible, while **NavMesh Only** will only import
  315. the navigation mesh (without a visual representation). **NavMesh Only** is
  316. meant to be used when you've manually authored a simplified mesh for navigation.
  317. - **Generate > Occluder:** If checked, generates an OccluderInstance3D *sibling*
  318. node for :ref:`occlusion culling <doc_occlusion_culling>` using the mesh's
  319. geometry as a basis for the occluder's shape. **Mesh + Occluder** will keep
  320. the original mesh visible, while **Occluder Only** will only import the
  321. occluder (without a visual representation). **Occluder Only** is meant to be
  322. used when you've manually authored a simplified mesh for occlusion culling.
  323. These options are only visible if some of the above options are enabled:
  324. - **Physics > Body Type:** Only visible if **Generate > Physics** is enabled.
  325. Controls the PhysicsBody3D that should be created. **Static** creates a
  326. StaticBody3D, **Dynamic** creates a RigidBody3D, **Area** creates an Area3D.
  327. - **Physics > Shape Type:** Only visible if **Generate > Physics** is enabled.
  328. **Trimesh** allows for precise per-triangle collision, but it can only be used
  329. with a **Static** body type. Other types are less precise and may require
  330. manual configuration, but can be used with any body type. For static level
  331. geometry, use **Trimesh**. For dynamic geometry, use primitive shapes if
  332. possible for better performance, or use one of the convex decomposition modes
  333. if the shape is large and complex.
  334. - **Decomposition > Advanced:** Only visible if **Physics > Shape Type** is
  335. **Decompose Convex**. If checked, allows adjusting advanced decomposition
  336. options. If disabled, only a preset **Precision** can be adjusted (which is
  337. usually sufficient).
  338. - **Decomposition > Precision:** Only visible if **Physics > Shape Type** is
  339. **Decompose Convex**. Controls the precision to use for convex decomposition.
  340. Higher values result in more detailed collision, at the cost of slower
  341. generation and increased CPU usage during physics simulation. To improve
  342. performance, it's recommended to keep this value as low as possible for your
  343. use cases.
  344. - **Occluder > Simplification Distance:** Only visible if **Generate >
  345. Occluder** is set to **Mesh + Occluder** or **Occluder Only**. Higher values
  346. result in a occluder mesh with fewer vertices (resulting in decreased CPU
  347. utilization), at the cost of more occlusion culling issues (such as false
  348. positives or false negatives). If you run into objects disappearing when they
  349. shouldn't when the camera is near a certain mesh, try decreasing this value.
  350. **Configuring mesh and material import options**
  351. In the Advanced Import Settings dialog, there are 2 ways to select individual
  352. meshes or materials:
  353. - Switch to the **Meshes** or **Materials** tab in the top-left corner of the dialog.
  354. - Stay in the **Scene** tab, but unfold the options on the tree view on the
  355. left. After choosing a mesh or material, this presents the same information as
  356. the **Meshes** and **Materials** tabs, but in a tree view instead of a list.
  357. If you select a mesh, different options will appear in the panel on the right:
  358. .. figure:: img/importing_3d_scenes_advanced_import_settings_meshes.webp
  359. :align: center
  360. :alt: Advanced Import Settings dialog (Meshes tab)
  361. Advanced Import Settings dialog (Meshes tab)
  362. The options are as follows:
  363. - **Save to File:** Saves the :ref:`class_Mesh` *resource* to an external file
  364. (this isn't a scene file). You generally don't need to use this for placing
  365. the mesh in a 3D scene – instead, you should instance the 3D scene directly.
  366. However, having direct access to the Mesh resource is useful for specific
  367. nodes, such as :ref:`class_MeshInstance3D`, :ref:`class_MultiMeshInstance3D`,
  368. :ref:`class_GPUParticles3D` or :ref:`class_CPUParticles3D`.
  369. - You will also need to specify an output file path using the option that
  370. appears after enabling **Save to File**. It's recommended to use the ``.res``
  371. output file extension for smaller file sizes and faster loading speeds, as
  372. ``.tres`` is inefficient for writing large amounts of data.
  373. - **Generate > Shadow Meshes:** Per-mesh override for the **Meshes > Create
  374. Shadow Meshes** scene-wide import option described in
  375. :ref:`doc_importing_3d_scenes_using_the_import_dock`. **Default** will use the
  376. scene-wide import option, while **Enable** or **Disable** can forcibly enable
  377. or disable this behavior on a specific mesh.
  378. - **Generate > Lightmap UV:** Per-mesh override for the **Meshes > Light
  379. Baking** scene-wide import option described in
  380. :ref:`doc_importing_3d_scenes_using_the_import_dock`. **Default** will use the
  381. scene-wide import option, while **Enable** or **Disable** can forcibly enable
  382. or disable this behavior on a specific mesh.
  383. - Setting this to **Enable** on a scene with the **Static** light baking mode
  384. is equivalent to configuring this mesh to use **Static Lightmaps**. Setting this
  385. to **Disable** on a scene with the **Static Lightmaps** light baking mode is
  386. equivalent to configuring this mesh to use **Static** instead.
  387. - **Generate > LODs:** Per-mesh override for the **Meshes > Generate LODs**
  388. scene-wide import option described in
  389. :ref:`doc_importing_3d_scenes_using_the_import_dock`. **Default** will use the
  390. scene-wide import option, while **Enable** or **Disable** can forcibly enable
  391. or disable this behavior on a specific mesh.
  392. - **LODs > Normal Split Angle:** The minimum angle difference between two
  393. vertices required to preserve a geometry edge in mesh LOD generation. If
  394. running into visual issues with LOD generation, decreasing this value may help
  395. (at the cost of less efficient LOD generation).
  396. - **LODs > Normal Merge Angle:** The minimum angle difference between two
  397. vertices required to preserve a geometry edge in mesh LOD generation. If
  398. running into visual issues with LOD generation, decreasing this value may help
  399. (at the cost of less efficient LOD generation).
  400. If you select a material, only one option will appear in the panel on the right:
  401. .. figure:: img/importing_3d_scenes_advanced_import_settings_materials.webp
  402. :align: center
  403. :alt: Advanced Import Settings dialog (Materials tab)
  404. Advanced Import Settings dialog (Materials tab)
  405. When **Use External** is checked and an output path is specified, this lets you
  406. use an external material instead of the material that is included in the
  407. original 3D scene file; see the section below.
  408. Extracting materials to separate files
  409. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  410. While Godot can import materials authored in 3D modeling software, the default
  411. configuration may not be suitable for your needs. For example:
  412. - You want to configure material features not supported by your 3D application.
  413. - You want to use a different texture filtering mode, as this option is
  414. configured in the material since Godot 4.0 (and not in the image).
  415. - You want to replace one of the materials with an entirely different material,
  416. such as a custom shader.
  417. To be able to modify the 3D scene's materials in the Godot editor, you need to
  418. use *external* material resources.
  419. In the top-left corner of the Advanced Import Settings dialog, choose
  420. **Actions… > Extract Materials**:
  421. .. figure:: img/importing_3d_scenes_advanced_import_settings_extract_materials.webp
  422. :align: center
  423. :alt: Extracting all built-in materials to external resources in the Advanced Import Settings dialog
  424. Extracting all built-in materials to external resources in the Advanced Import Settings dialog
  425. After choosing this option, select a folder to extract material ``.tres`` files
  426. to, then confirm the extraction:
  427. .. figure:: img/importing_3d_scenes_advanced_import_settings_extract_materials_confirm.webp
  428. :align: center
  429. :alt: Confirming material extraction in the Advanced Import Settings subdialog
  430. Confirming material extraction in the Advanced Import Settings subdialog
  431. .. note::
  432. After extracting materials, the 3D scene will automatically be configured to
  433. use external material references. As a result, you don't need to manually
  434. enable **Use External** on every material to make the external ``.tres``
  435. material effective.
  436. When **Use External** is enabled, remember that the Advanced Import Settings
  437. dialog will keep displaying the mesh's original materials (the ones designed in
  438. the 3D modeling software). This means your customizations to the materials won't
  439. be visible within this dialog. To preview your modified materials, you need to
  440. place the imported 3D scene in another scene using the editor.
  441. Godot will not overwrite changes made to extracted materials when the source 3D
  442. scene is reimported. However, if the material name is changed in the source 3D
  443. file, the link between the original material and the extracted material will be
  444. lost. As a result, you'll need to use the Advanced Import Settings dialog to
  445. associate the renamed material to the existing extracted material.
  446. The above can be done in the dialog's **Materials** tab by selecting the
  447. material, enabling **Save to File**, then specifying the save path using the
  448. **Path** option that appears after enabling **Save to File**.
  449. .. _doc_importing_3d_scenes_import_script:
  450. Using import scripts for automation
  451. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  452. A special script to process the whole scene after import can be provided.
  453. This is great for post-processing, changing materials, doing funny stuff with
  454. the geometry, and more.
  455. Create a script that is not attached to any node by right-clicking in the
  456. FileSystem dock and choosing **New > Script…**. In the script editor, write the
  457. following:
  458. ::
  459. @tool # Needed so it runs in editor.
  460. extends EditorScenePostImport
  461. # This sample changes all node names.
  462. # Called right after the scene is imported and gets the root node.
  463. func _post_import(scene):
  464. # Change all node names to "modified_[oldnodename]"
  465. iterate(scene)
  466. return scene # Remember to return the imported scene
  467. # Recursive function that is called on every node
  468. # (for demonstration purposes; EditorScenePostImport only requires a `_post_import(scene)` function).
  469. func iterate(node):
  470. if node != null:
  471. print_rich("Post-import: [b]%s[/b] -> [b]%s[/b]" % [node.name, "modified_" + node.name])
  472. node.name = "modified_" + node.name
  473. for child in node.get_children():
  474. iterate(child)
  475. The ``_post_import(scene: Node)`` function takes the imported scene as argument
  476. (the parameter is actually the root node of the scene). The scene that will
  477. finally be used **must** be returned (even if the scene can be entirely different).
  478. Using animation libraries
  479. ^^^^^^^^^^^^^^^^^^^^^^^^^
  480. As of Godot 4.0, you can choose to import **only** animations from a glTF file and
  481. nothing else. This is used in some asset pipelines to distribute animations
  482. separately from models. For example, this allows you to use one set of
  483. animations for several characters, without having to duplicate animation data in
  484. every character.
  485. To do so, select the glTF file in the FileSystem dock, then change the import
  486. mode to Animation Library in the Import dock:
  487. .. figure:: img/importing_3d_scenes_changing_import_type.webp
  488. :align: center
  489. :alt: Changing the import type to Animation Library in the Import dock
  490. Changing the import type to Animation Library in the Import dock
  491. Click **Reimport** and restart the editor when prompted. After restarting, the
  492. glTF file will be imported as an :ref:`class_AnimationLibrary` instead of a
  493. :ref:`class_PackedScene`. This animation library can then be referenced in an
  494. :ref:`class_AnimationPlayer` node.
  495. The import options that are visible after changing the import mode to Animation
  496. Library act the same as when using the Scene import mode. See
  497. :ref:`doc_importing_3d_scenes_using_the_import_dock` for more information.
  498. Filter script
  499. ^^^^^^^^^^^^^
  500. It is possible to specify a filter script in a special syntax to decide which
  501. tracks from which animations should be kept.
  502. The filter script is executed against each imported animation. The syntax
  503. consists of two types of statements, the first for choosing which animations to
  504. filter, and the second for filtering individual tracks within the matched
  505. animation. All name patterns are performed using a case-insensitive expression
  506. match, with support for ``?`` and ``*`` wildcards (using
  507. :ref:`String.matchn() <class_String_method_matchn>` under the hood).
  508. The script must start with an animation filter statement (as denoted by the line
  509. beginning with an ``@``). For example, if we would like to apply filters to all
  510. imported animations which have a name ending in ``"_Loop"``::
  511. @+*_Loop
  512. Similarly, additional patterns can be added to the same line, separated by
  513. commas. Here is a modified example to additionally *include* all animations with
  514. names that begin with ``"Arm_Left"``, but also *exclude* all animations which
  515. have names ending in ``"Attack"``::
  516. @+*_Loop, +Arm_Left*, -*Attack
  517. Following the animation selection filter statement, we add track filtering
  518. patterns to indicate which animation tracks should be kept or discarded. If no
  519. track filter patterns are specified, then all tracks within the matched
  520. animations will be discarded!
  521. It's important to note that track filter statements are applied in order for
  522. each track within the animation, this means that one line may include a track, a
  523. later rule can still discard it. Similarly, a track excluded by an early rule
  524. may then be re-included once again by a filter rule further down in the filter
  525. script.
  526. For example: include all tracks in animations with names ending in ``"_Loop"``,
  527. but discard any tracks affecting a ``"Skeleton"`` which end in ``"Control"``,
  528. unless they have ``"Arm"`` in their name::
  529. @+*_Loop
  530. +*
  531. -Skeleton:*Control
  532. +*Arm*
  533. In the above example, tracks like ``"Skeleton:Leg_Control"`` would be discarded,
  534. while tracks such as ``"Skeleton:Head"`` or ``"Skeleton:Arm_Left_Control"``
  535. would be retained.
  536. Any track filter lines that do not begin with a ``+`` or ``-`` are ignored.
  537. Storage
  538. ^^^^^^^
  539. By default, animations are saved as built-in. It is possible to save them to a
  540. file instead. This allows adding custom tracks to the animations and keeping
  541. them after a reimport.
  542. Optimizer
  543. ^^^^^^^^^
  544. When animations are imported, an optimizer is run, which reduces the size of the
  545. animation considerably. In general, this should always be turned on unless you
  546. suspect that an animation might be broken due to it being enabled.
  547. Clips
  548. ^^^^^
  549. It is possible to specify multiple animations from a single timeline as clips.
  550. For this to work, the model must have only one animation that is named
  551. ``default``. To create clips, change the clip amount to something greater than
  552. zero. You can then name a clip, specify which frames it starts and stops on, and
  553. choose whether the animation loops or not.
  554. Scene inheritance
  555. -----------------
  556. In many cases, it may be desired to make manual modifications to the imported
  557. scene. By default, this is not possible because if the source 3D asset changes,
  558. Godot will re-import the *whole* scene.
  559. However, it is possible to make local modifications by using *scene
  560. inheritance*. If you try to open the imported scene using **Scene > Open
  561. Scene…** or **Scene > Quick Open Scene…**, the following dialog will appear:
  562. .. figure:: img/importing_3d_scenes_create_inherited_scene_dialog.webp
  563. :align: center
  564. :alt: Dialog when opening an imported 3D scene in the editor
  565. Dialog when opening an imported 3D scene in the editor
  566. In inherited scenes, the only limitations for modification are:
  567. - Nodes from the base scene can't be removed, but additional nodes can be added
  568. anywhere.
  569. - Subresources can't be edited. Instead, you need to save them externally as
  570. described above.
  571. Other than that, everything is allowed.
  572. .. _doc_importing_3d_scenes_import_hints:
  573. Import hints
  574. ------------
  575. Many times, when editing a scene, there are common tasks that need to be done
  576. after exporting:
  577. - Adding collision detection to objects.
  578. - Setting objects as navigation meshes.
  579. - Deleting nodes that are not used in the game engine (like specific lights used
  580. for modelling).
  581. To simplify this workflow, Godot offers several suffixes that can be added to
  582. the names of the objects in your 3D modelling software. When imported, Godot
  583. will detect suffixes in object names and will perform actions automatically.
  584. .. warning::
  585. All the suffixes described below are **case-sensitive**.
  586. Remove nodes (-noimp)
  587. ^^^^^^^^^^^^^^^^^^^^^
  588. Objects that have the ``-noimp`` suffix will be removed at import-time no matter
  589. what their type is. They will not appear in the imported scene.
  590. This is equivalent to enabling **Skip Import** for a node in the Advanced Import
  591. Settings dialog.
  592. Create collisions (-col, -convcol, -colonly, -convcolonly)
  593. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  594. The option ``-col`` will work only for Mesh objects. If it is detected, a child
  595. static collision node will be added, using the same geometry as the mesh. This
  596. will create a triangle mesh collision shape, which is a slow, but accurate
  597. option for collision detection. This option is usually what you want for level
  598. geometry (but see also ``-colonly`` below).
  599. The option ``-convcol`` will create a :ref:`class_ConvexPolygonShape3D` instead of
  600. a :ref:`class_ConcavePolygonShape3D`. Unlike triangle meshes which can be concave,
  601. a convex shape can only accurately represent a shape that doesn't have any
  602. concave angles (a pyramid is convex, but a hollow box is concave). Due to this,
  603. convex collision shapes are generally not suited for level geometry. When
  604. representing simple enough meshes, convex collision shapes can result in better
  605. performance compared to a triangle collision shape. This option is ideal for
  606. simple or dynamic objects that require mostly-accurate collision detection.
  607. However, in both cases, the visual geometry may be too complex or not smooth
  608. enough for collisions. This can create physics glitches and slow down the engine
  609. unnecessarily.
  610. To solve this, the ``-colonly`` modifier exists. It will remove the mesh upon
  611. importing and will create a :ref:`class_StaticBody3D` collision instead.
  612. This helps the visual mesh and actual collision to be separated.
  613. The option ``-convcolonly`` works in a similar way, but will create a
  614. :ref:`class_ConvexPolygonShape3D` instead using convex decomposition.
  615. With Collada files, the option ``-colonly`` can also be used with Blender's
  616. empty objects. On import, it will create a :ref:`class_StaticBody3D` with a
  617. collision node as a child. The collision node will have one of a number of
  618. predefined shapes, depending on Blender's empty draw type:
  619. .. figure:: img/importing_3d_scenes_blender_empty_draw_types.webp
  620. :align: center
  621. :alt: Choosing a draw type for an Empty on creation in Blender
  622. Choosing a draw type for an Empty on creation in Blender
  623. - Single arrow will create a :ref:`class_SeparationRayShape3D`.
  624. - Cube will create a :ref:`class_BoxShape3D`.
  625. - Image will create a :ref:`class_WorldBoundaryShape3D`.
  626. - Sphere (and the others not listed) will create a :ref:`class_SphereShape3D`.
  627. When possible, **try to use a few primitive collision shapes** instead of triangle
  628. mesh or convex shapes. Primitive shapes often have the best performance and
  629. reliability.
  630. .. note::
  631. For better visibility on Blender's editor, you can set the "X-Ray" option
  632. on collision empties and set some distinct color for them by changing
  633. **Edit > Preferences > Themes > 3D Viewport > Empty**.
  634. If using Blender 2.79 or older, follow these steps instead:
  635. **User Preferences > Themes > 3D View > Empty**.
  636. .. seealso::
  637. See :ref:`doc_collision_shapes_3d` for a comprehensive overview of collision
  638. shapes.
  639. Create navigation (-navmesh)
  640. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  641. A mesh node with the ``-navmesh`` suffix will be converted to a navigation mesh.
  642. The original Mesh object will be removed at import-time.
  643. Create a VehicleBody (-vehicle)
  644. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  645. A mesh node with the ``-vehicle`` suffix will be imported as a child to a
  646. :ref:`class_VehicleBody3D` node.
  647. Create a VehicleWheel (-wheel)
  648. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  649. A mesh node with the ``-wheel`` suffix will be imported as a child to a
  650. :ref:`class_VehicleWheel3D` node.
  651. Rigid Body (-rigid)
  652. ^^^^^^^^^^^^^^^^^^^
  653. A mesh node with the ``-rigid`` suffix will be imported as a :ref:`class_RigidBody3D`.
  654. Animation loop (-loop, -cycle)
  655. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  656. Animation clips in the source 3D file that start or end with the token ``loop`` or ``cycle``
  657. will be imported as a Godot :ref:`class_Animation` with the loop flag set.
  658. **Unlike the other suffixes described above, this does not require a hyphen.**
  659. In Blender, this requires using the NLA Editor and naming the Action with the ``loop`` or
  660. ``cycle`` prefix or suffix.