2 Blender_to_Godot
Xantulon edited this page 6 months ago

Exporting from Blender 3.2 to Godot 4.0:

Importing 3D scenes - Godot scene importer

Set the frame rate to 60 fps in the Output Properties.

Selection_733.png

Meshes:

In Blender:

  • Check backface culling in the materials setting for meshes.

Selection_731.png

  • Add a Triangulate modifier to meshes and make sure Apply Modifiers is checked in the export dialog.

Selection_732.png

Selection_734.png

Import Hints:

Naming objects in Blender:

  • Append -noimp to object names for objects that you don't want imported to Godot. Lights, cameras, and helper objects for example.

Selection_736.png

  • Append -loop to NLA track names for looping animations.

Selection_737.png

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 class_convexpolygonshape instead of a class_concavepolygonshape. 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 class_staticbody 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 class_convexpolygonshape instead.

With Collada files the option -colonly can also be used with Blender's empty objects. On import, it will create a class_staticbody 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:

3dimp_BlenderEmptyDrawTypes.png

  • Single arrow will create a class_rayshape.
  • Cube will create a class_boxshape.
  • Image will create a class_worldmarginshape.
  • Sphere (and the others not listed) will create a class_sphereshape.

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.

See also See 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 class_VehicleBody node.

Create a VehicleWheel (-wheel)

A mesh node with the -wheel suffix will be imported as a child to a class_VehicleWheel node.

Rigid Body (-rigid)

A mesh node with the -rigid suffix will be imported as a class_RigidBody.

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.

Exporting glTF 2.0 files from Blender

There are three ways to export glTF files from Blender. As a glTF binary (.glb file), glTF embedded (.gltf file), and with textures (gltf + .bin + textures).

glTF binary files 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 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.

Note Blender does not export emissive textures with the glTF file. If your model uses one, 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.

TODO

  • baking animations from the control rig to the game rig