importing_scenes.rst 39 KB

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