importing_scenes.rst 41 KB

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