123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599 |
- .. _doc_importing_3d_scenes:
- Importing 3D scenes
- ===================
- Godot scene importer
- --------------------
- When dealing with 3D assets, Godot has a flexible and configurable importer.
- Godot works with *scenes*. This means that the entire scene being worked on in your favorite 3D DCC will be
- transferred as close as possible.
- Godot supports the following 3D *scene file formats*:
- - glTF 2.0 **(recommended)**. Godot has full support for both text (``.gltf``) and binary (``.glb``) formats.
- - ``.blend`` (Blender). This works by calling Blender to export to glTF in a
- transparent manner (requires Blender to be installed).
- - DAE (COLLADA), an older format that is fully supported.
- - OBJ (Wavefront) format + their MTL material files. This is also fully
- supported, but pretty limited given the format's limitations (no support for
- pivots, skeletons, animations, UV2, PBR materials, ...).
- - FBX, supported via `FBX2glTF <https://github.com/godotengine/FBX2glTF>`__ integration.
- This requires installing an external program that links against the proprietary FBX SDK,
- so we recommend using other formats listed above (if suitable for your workflow).
- Just copy the scene file together with the texture to the project repository, and Godot will do a full import.
- It is important that the mesh is not deformed by bones when exporting. Make sure that the skeleton is reset to its T-pose
- or default rest pose before exporting with your favorite 3D editor.
- Exporting glTF 2.0 files from Blender (recommended)
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- There are 3 ways to export glTF files from Blender:
- - As a glTF binary file (``.glb``).
- - As a glTF text-based file with embedded binary data (``.gltf`` file)
- - As a glTF text-based file with separate binary data and textures (``.gltf``
- file + ``.bin`` file + textures).
- glTF binary files (``.glb``) are the smallest of the three options. They include
- the mesh and textures set up in Blender. When brought into Godot the textures
- are part of the object's material file.
- glTF embedded files (``.gltf``) function the same way as binary files. They
- don't provide extra functionality in Godot, and shouldn't be used since they
- have a larger file size.
- There are two reasons to use glTF with the textures separate. One is to have the
- scene description in a text based format and the binary data in a separate
- binary file. This can be useful for version control if you want to review
- changes in a text-based format. The second is you need the texture files
- separate from the material file. If you don't need either of those, glTF binary
- files are fine.
- .. warning::
- If your model contains blend shapes (also known as "shape keys" and "morph
- targets"), your glTF export setting **Export Deformation Bones Only** needs
- to be configured to **Enabled** under the Animation export configurations.
- Exporting non-deforming bones anyway will lead to incorrect shading.
- .. note::
- Blender versions older than 3.2 do not export emissive textures with the
- glTF file. If your model uses one and you're using an older version of
- Blender, it must be brought in separately.
- By default, Blender has backface culling disabled on materials and will
- export materials to match how they render in Blender. This means that
- materials in Godot will have their cull mode set to **Disabled**. This can
- decrease performance since backfaces will be rendered, even when they are
- being culled by other faces. To resolve this, enable **Backface Culling** in
- Blender's Materials tab, then export the scene to glTF again.
- Importing ``.blend`` files directly within Godot
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- .. note::
-
- This functionality requires Blender 3.0 or later.
- From Godot 4.0 onwards, the editor can directly import ``.blend`` files by
- calling `Blender <https://www.blender.org/>`__'s glTF export functionality in a
- transparent manner.
- This allows you to iterate on your 3D scenes faster, as you can save the scene
- in Blender, alt-tab back to Godot then see your changes immediately. When
- working with version control, this is also more efficient as you no longer need
- to commit a copy of the exported glTF file to version control.
- To use ``.blend`` import, you must install Blender before opening the Godot
- editor (if opening a project that already contains ``.blend`` files). If you
- keep Blender installed at its default location, Godot should be able to detect
- its path automatically. If this isn't the case, configure the path to the
- Blender executable in the Editor Settings (**Filesystem > Import > Blender >
- Blender 3 Path**).
- If you keep ``.blend`` files within your project folder but don't want them to
- be imported by Godot, disable **Filesystem > Import > Blender > Enabled** in the
- advanced Project Settings.
- .. note::
- When working in a team, keep in mind using ``.blend`` files in your project
- will require *all* team members to have Blender installed. While Blender is
- a free download, this may add friction when working on the project.
- ``.blend`` import is also not available on the Android and web editors, as
- these platforms can't call external programs.
-
- If this is problematic, consider using glTF scenes exported from Blender
- instead.
- Exporting DAE files from Blender
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Blender has built-in COLLADA support, but it does not work properly for the
- needs of game engines and shouldn't be used as-is. However, scenes exported with
- the built-in Collada support may still work for simple scenes without animation.
- For complex scenes or scenes that contain animations, Godot provides a
- `Blender plugin <https://github.com/godotengine/collada-exporter>`_
- that will correctly export COLLADA scenes for use in Godot.
- Importing OBJ files in Godot
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- OBJ is one of the simplest 3D formats out there, so Godot should be able to
- import most OBJ files successfully. However, OBJ is also a very limited format:
- it doesn't support skinning, animation, UV2 or PBR materials.
- There are 2 ways to use OBJ meshes in Godot:
- - Load them directly in a MeshInstance3D node, or any other property that
- expects as mesh (such as GPUParticles3D). This is the default mode.
- - Change their import mode to **OBJ as Scene** in the Import dock then restart
- the editor. This allows you to use the same import options as glTF or Collada
- scenes, such as unwrapping UV2 on import (for :ref:`doc_baked_lightmaps`).
- .. note::
- Blender 3.4 and later can export RGB vertex colors in OBJ files (this is a
- nonstandard extension of the OBJ format). Godot is able to import those
- vertex colors since Godot 4.0, but they will not be displayed on the
- material unless you enable **Vertex Color > Use As Albedo** on the material.
- Vertex colors from OBJ meshes keep their original color space once imported
- (sRGB/linear), but their brightness is clamped to 1.0 (they can't be
- overbright).
- Importing FBX files in Godot
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- When opening a project containing FBX scenes, you will see a dialog asking you
- to configure FBX import. Click the link in the dialog to download a fbx2gltf
- binary, then extract the ZIP archive, place the binary anywhere you wish, then
- specify its path in the dialog.
- If you keep ``.fbx`` files within your project folder but don't want them to
- be imported by Godot, disable **Filesystem > Import > FBX > Enabled** in the
- advanced Project Settings.
- .. seealso::
- The full installation process for using FBX in Godot is described on the
- `FBX import page of the Godot website <https://godotengine.org/fbx-import>`__.
- Exporting textures separately
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- While textures can be exported with a model in certain file formats, such as glTF 2.0, you can also export them
- separately. Godot uses PBR (physically based rendering) for its materials, so if a texturing program can export PBR
- textures they can work in Godot. This includes the `Substance suite <https://www.substance3d.com/>`__,
- `ArmorPaint (open source) <https://armorpaint.org/>`__, and `Material Maker (open source) <https://github.com/RodZill4/material-maker>`__.
- .. note:: For more information on Godot's materials, see :ref:`doc_standard_material_3d`.
- Exporting considerations
- ~~~~~~~~~~~~~~~~~~~~~~~~
- Since GPUs can only render triangles, meshes that contain quads or N-gons have
- to be *triangulated* before they can be rendered. Godot can triangulate meshes
- on import, but results may be unpredictable or incorrect, especially with
- N-gons. Regardless of the target application, triangulating *before* exporting
- the scene will lead to more consistent results and should be done whenever
- possible.
- To avoid issues with incorrect triangulation after importing in Godot, it is
- recommended to make the 3D DCC triangulate objects on its own. In Blender, this
- can be done by adding a Triangulate modifier to your objects and making sure
- **Apply Modifiers** is checked in the export dialog. Alternatively, depending on
- the exporter, you may be able to find and enable a **Triangulate Faces** option
- in the export dialog.
- To avoid issues with 3D selection in the editor, it is recommended to apply the
- object transform in the 3D DCC before exporting the scene.
- Import workflows
- ----------------
- Godot scene importer allows different workflows regarding how data is imported. Depending on many options, it is possible to
- import a scene with:
- * External materials (default): Where each material is saved to a file resource. Modifications to them are kept.
- * External meshes: Where each mesh is saved to a different file. Many users prefer to deal with meshes directly.
- * External animations: Allowing saved animations to be modified and merged when sources change.
- * External scenes: Save each of the root nodes of the imported scenes as a separate scene.
- * Single scene: A single scene file with everything built in.
- .. image:: img/scene_import1.png
- As different developers have different needs, this import process is highly customizable.
- Import options
- --------------
- The importer has several options, which will be discussed below:
- .. image:: img/scene_import2.png
- Nodes
- ~~~~~
- Root Type
- ^^^^^^^^^
- By default, the type of the root node in imported scenes is "Node3D", but this can be modified.
- Root Name
- ^^^^^^^^^
- Allows setting a specific name to the generated root node.
- Root Scale
- ^^^^^^^^^^
- The scale of the root node.
- Custom Script
- ^^^^^^^^^^^^^
- A special script to process the whole scene after import can be provided.
- This is great for post processing, changing materials, doing funny stuff
- with the geometry etc.
- Create a script like this:
- ::
- tool # Needed so it runs in the editor.
- extends EditorScenePostImport
- func post_import(scene):
- # Do your stuff here.
- return scene # remember to return the imported scene
- The ``post_import`` function takes the imported scene as argument (the
- parameter is actually the root node of the scene). The scene that
- will finally be used must be returned. It can be a different one.
- Storage
- ^^^^^^^
- By default, Godot imports a single scene. This option allows specifying
- that nodes below the root will each be a separate scene and instanced
- into the imported one.
- Of course, instancing such imported scenes in other places manually works, too.
- Materials
- ~~~~~~~~~
- Location
- ^^^^^^^^
- Godot supports materials in meshes or nodes. By default, materials will be put
- on each node.
- Storage
- ^^^^^^^
- Materials can be stored within the scene or in external files. By default,
- they are stored in external files so editing them is possible. This is because
- most 3D DCCs don't have the same material options as those present in Godot.
- When materials are built-in, they will be lost each time the source scene
- is modified and re-imported.
- .. note::
- Godot will not reimport materials that are stored in external files unless
- you remove the associated ``.material`` file before reimporting.
- To force reimporting materials every time the 3D scene is reimported, change
- the material storage mode in the 3D scene by selecting it in the FileSystem
- dock, going to the Import dock then setting **Material > Storage** to
- **Built-In** instead of **Files**.
- Keep On Reimport
- ^^^^^^^^^^^^^^^^
- Once materials are edited to use Godot features, the importer will keep the
- edited ones and ignore the ones coming from the source scene. This option
- is only present if materials are saved as files.
- Meshes
- ~~~~~~
- Compress
- ^^^^^^^^
- Makes meshes use less precise numbers for multiple aspects of the mesh in order
- to save space.
- These are:
- * Transform Matrix (Location, rotation, and scale) : 32-bit float to 16-bit signed integer.
- * Vertices : 32-bit float to 16-bit signed integer.
- * Normals : 32-bit float to 32-bit unsigned integer.
- * Tangents : 32-bit float to 32-bit unsigned integer.
- * Vertex Colors : 32-bit float to 32-bit unsigned integer.
- * UV : 32-bit float to 32-bit unsigned integer.
- * UV2 : 32-bit float to 32-bit unsigned integer.
- * Vertex weights : 32-bit float to 16-bit unsigned integer.
- * Armature bones : 32-bit float to 16-bit unsigned integer.
- * Array index : 32-bit or 16-bit unsigned integer based on how many elements there are.
- Additional info:
- * UV2 = The second UV channel for detail textures and baked lightmap textures.
- * Array index = An array of numbers that number each element of the arrays above; i.e. they number the vertices and normals.
- In some cases, this might lead to loss of precision, so disabling this option
- may be needed. For instance, if a mesh is very big or there are multiple meshes
- being imported that cover a large area, compressing the import of this mesh(es)
- may lead to gaps in geometry or vertices not being exactly where they should be.
- Ensure Tangents
- ^^^^^^^^^^^^^^^
- If textures with normal mapping are to be used, meshes need to have tangent arrays.
- This option ensures that these are generated if not present in the source scene.
- Godot uses `Mikktspace <http://www.mikktspace.com/>`__ for this,
- but it's always better to have them generated in the exporter.
- Storage
- ^^^^^^^
- Meshes can be stored in separate files (resources) instead of built-in. This does
- not have much practical use unless one wants to build objects with them directly.
- This option is provided to help those who prefer working directly with meshes
- instead of scenes.
- Light Baking
- ^^^^^^^^^^^^
- Whether or not the mesh is used in baked lightmaps.
- - **Disabled:** The mesh is not used in baked lightmaps.
- - **Enable:** The mesh is used in baked lightmaps.
- - **Gen Lightmaps:** The mesh is used in baked lightmaps, and unwraps a second UV layer for lightmaps.
- .. note:: For more information on light baking see :ref:`doc_using_lightmap_gi`.
- External Files
- ~~~~~~~~~~~~~~
- Generated meshes and materials can be optionally stored in a subdirectory with the
- name of the scene.
- Animation options
- -----------------
- Godot provides many options regarding how animation data is dealt with. Some exporters
- (such as Blender) can generate many animations in a single file. Others, such as
- 3DS Max or Maya, need many animations put into the same timeline or, at worst, put
- each animation in a separate file.
- .. image:: img/scene_import3.png
- Import of animations is enabled by default.
- .. attention::
- To modify animations from an imported 3D scene, you need to change the animation
- storage option from **Built-In** to **Files** in the Import dock. Otherwise,
- changes made to animations from Godot will be lost when the project is run.
- FPS
- ~~~
- Most 3D export formats store animation timeline in seconds instead of frames. To ensure
- animations are imported as faithfully as possible, please specify the frames per second
- used to edit them. Failing to do this may result in shaky animations.
- Filter Script
- ~~~~~~~~~~~~~
- It is possible to specify a filter script in a special syntax to decide which tracks from which
- animations should be kept.
- The filter script is executed against each imported animation. The syntax consists of two types of
- statements, the first for choosing which animations to filter, and the second for filtering
- individual tracks within the matched animation. All name patterns are performed using a case
- insensitive expression match, using ``?`` and ``*`` wildcards (using ``String.matchn()`` under the
- hood).
- The script must start with an animation filter statement (as denoted by the line beginning with an
- ``@``). For example, if we would like to apply filters to all imported animations which have a name
- ending in ``"_Loop"``::
- @+*_Loop
- Similarly, additional patterns can be added to the same line, separated by commas. Here is a
- modified example to additionally *include* all animations with names that begin with ``"Arm_Left"``,
- but also *exclude* all animations which have names ending in ``"Attack"``::
- @+*_Loop, +Arm_Left*, -*Attack
- Following the animation selection filter statement, we add track filtering patterns to indicate
- which animation tracks should be kept or discarded. If no track filter patterns are specified, then
- all tracks within the matched animations will be discarded!
- It's important to note that track filter statements are applied in order for each track within the
- animation, this means that one line may include a track, a later rule can still discard it.
- Similarly, a track excluded by an early rule may then be re-included once again by a filter rule
- further down in the filter script.
- For example: include all tracks in animations with names ending in ``"_Loop"``, but discard any
- tracks affecting a ``"Skeleton"`` which end in ``"Control"``, unless they have ``"Arm"`` in their
- name::
- @+*_Loop
- +*
- -Skeleton:*Control
- +*Arm*
- In the above example, tracks like ``"Skeleton:Leg_Control"`` would be discarded, while tracks such
- as ``"Skeleton:Head"`` or ``"Skeleton:Arm_Left_Control"`` would be retained.
- Any track filter lines that do not begin with a ``+`` or ``-`` are ignored.
- Storage
- ~~~~~~~
- By default, animations are saved as built-in. It is possible to save them to a file instead. This
- allows adding custom tracks to the animations and keeping them after a reimport.
- Optimizer
- ~~~~~~~~~
- When animations are imported, an optimizer is run, which reduces the size of the animation considerably.
- In general, this should always be turned on unless you suspect that an animation might be broken due to it being enabled.
- Clips
- ~~~~~
- It is possible to specify multiple animations from a single timeline as clips. For this to work, the model
- must have only one animation that is named ``default``. To create clips, change the clip amount to something
- greater than zero. You can then name a clip, specify which frames it starts and stops on, and choose whether
- the animation loops or not.
- .. If this PR (https://github.com/godotengine/godot/pull/36709) is merged for Godot 4.0 this section must
- be updated to reflect that for the 4.0 documentation.
- Scene inheritance
- -----------------
- In many cases, it may be desired to make modifications to the imported scene. By default, this is not possible because
- if the source asset changes (source ``.dae``, ``.gltf``, ``.obj`` file re-exported from 3D modelling app), Godot will re-import the whole scene.
- It is possible, however, to make local modifications by using *Scene Inheritance*. Try to open the imported scene and the
- following dialog will appear:
- .. image:: img/scene_import4.png
- In inherited scenes, the only limitations for modifications are:
- * Nodes can't be removed (but can be added anywhere).
- * Sub-Resources can't be edited (save them externally as described above for this)
- Other than that, everything is allowed!
- Import hints
- ------------
- Many times, when editing a scene, there are common tasks that need to be done after exporting:
- - Adding collision detection to objects.
- - Setting objects as navigation meshes.
- - Deleting nodes that are not used in the game engine (like specific lights used for modelling).
- To simplify this workflow, Godot offers several suffixes that can be added to
- the names of the objects in your 3D modelling software. When imported, Godot
- will detect suffixes in object names and will perform actions automatically.
- .. note::
- All the suffixes described below are *case-sensitive*.
- Remove nodes (-noimp)
- ~~~~~~~~~~~~~~~~~~~~~
- Objects that have the ``-noimp`` suffix will be removed at import-time no matter
- what their type is. They will not appear in the imported scene.
- Create collisions (-col, -convcol, -colonly, -convcolonly)
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- The option ``-col`` will work only for Mesh objects. If it is detected, a child
- static collision node will be added, using the same geometry as the mesh. This
- will create a triangle mesh collision shape, which is a slow, but accurate
- option for collision detection. This option is usually what you want for level
- geometry (but see also ``-colonly`` below).
- The option ``-convcol`` will create a :ref:`class_ConvexPolygonShape3D` instead of
- a :ref:`class_ConcavePolygonShape3D`. Unlike triangle meshes which can be concave,
- a convex shape can only accurately represent a shape that doesn't have any
- concave angles (a pyramid is convex, but a hollow box is concave). Due to this,
- convex collision shapes are generally not suited for level geometry. When
- representing simple enough meshes, convex collision shapes can result in better
- performance compared to a triangle collision shape. This option is ideal for
- simple or dynamic objects that require mostly-accurate collision detection.
- However, in both cases, the visual geometry may be too complex or not smooth
- enough for collisions. This can create physics glitches and slow down the engine
- unnecessarily.
- To solve this, the ``-colonly`` modifier exists. It will remove the mesh upon
- importing and will create a :ref:`class_StaticBody3D` collision instead.
- This helps the visual mesh and actual collision to be separated.
- The option ``-convcolonly`` works in a similar way, but will create a :ref:`class_ConvexPolygonShape3D` instead.
- With Collada files the option ``-colonly`` can also be used with Blender's empty objects.
- On import, it will create a :ref:`class_StaticBody3D` with
- a collision node as a child. The collision node will have one of a number of predefined shapes,
- depending on Blender's empty draw type:
- .. image:: img/3dimp_BlenderEmptyDrawTypes.png
- - Single arrow will create a :ref:`class_SeparationRayShape3D`.
- - Cube will create a :ref:`class_BoxShape3D`.
- - Image will create a :ref:`class_WorldBoundaryShape3D`.
- - Sphere (and the others not listed) will create a :ref:`class_SphereShape3D`.
- When possible, **try to use a few primitive collision shapes** instead of triangle
- mesh or convex shapes. Primitive shapes often have the best performance and
- reliability.
- .. note::
- For better visibility on Blender's editor, you can set the "X-Ray" option
- on collision empties and set some distinct color for them by changing
- **Edit > Preferences > Themes > 3D Viewport > Empty**.
- If using Blender 2.79 or older, follow these steps instead:
- **User Preferences > Themes > 3D View > Empty**.
- .. seealso::
- See :ref:`doc_collision_shapes_3d` for a comprehensive overview of collision
- shapes.
- Create navigation (-navmesh)
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- A mesh node with the ``-navmesh`` suffix will be converted to a navigation mesh.
- The original Mesh object will be removed at import-time.
- Create a VehicleBody (-vehicle)
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- A mesh node with the ``-vehicle`` suffix will be imported as a child to a
- :ref:`class_VehicleBody3D` node.
- Create a VehicleWheel (-wheel)
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- A mesh node with the ``-wheel`` suffix will be imported as a child to a
- :ref:`class_VehicleWheel3D` node.
- Rigid Body (-rigid)
- ~~~~~~~~~~~~~~~~~~~
- A mesh node with the ``-rigid`` suffix will be imported as a :ref:`class_RigidBody3D`.
- Animation loop (-loop, -cycle)
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Animation clips in the COLLADA document that start or end with the token ``loop`` or ``cycle``
- will be imported as a Godot Animation with the loop flag set.
- **Unlike the other suffixes described above, this does not require a hyphen.**
- In Blender, this requires using the NLA Editor and naming the Action with the ``loop`` or
- ``cycle`` prefix or suffix.
|