importing_scenes.rst 41 KB

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