Creating Game Data

Blender

1. Introduction

Blender is a magnificent free open-source modeling software.

You can use Blender to create 3D and 2D models, with animations, and export them to glTF.

Level design in Blender Exporting from Blender to glTF Loaded level, designed in Blender, in Castle Game Engine

2. Exporting to glTF

Exporting from Blender to glTF 2.0 is the best way to use Blender with Castle Game Engine.

  • Export using the File → Export → glTF 2.0 menu item in Blender.

  • Load the resulting file (in .glb or .gltf formats) to TCastleScene. See manual about viewports and scenes.

  • You can also open the glTF file with view3dscene.

2.2. Advised glTF export settings

  • You usually want to check "Geometry → Apply Modifiers" in the export dialog.

  • "Remember Export Settings" is also usually useful.

  • For typical games (where you distribute the game data with your application) we recommend exporting to "glTF Separate (.gltf + .bin + textures)" variant. This allows to share textures between various models and keeps importing fast. You can edit the "Textures" directory in the export dialog, to make the glTF file just point to your existing texture directory.

2.3. Exporting normalmaps from Blender to glTF (and Castle Game Engine)

3. Advanced topics

3.1. Stashing animations

You may want to Stash animations to have them reliably exported, as is briefly mentioned by exporter docs. That is:

  • go to "Animation" view (or turn any Blender window into "Dope Sheet")

  • select Armature (e.g. by left-clicking in 3D view)

  • change "Dope Sheet" mode to "Action Editor"

  • select each animation (aka "action" in Blender) you want (repeat this for all animations you want to export)

  • click "Stash"

Stashing animations in Blender

3.2. Custom properties

Setting CastleCollision property in Blender

Blender can export Custom properties from various objects to glTF, and our engine reads them. You can access them by MetadataString and similar properties on X3D nodes. Demos:

Usage of custom properties:

  • Custom properties on Blender materials are imported as metadata on X3D material nodes, like TPhysicalMaterialNode.

    For example access them like:

    MyString := MyMaterial.MetadataString['material_property_name'];
  • Custom properties on Blender cameras are imported as metadata on X3D viewpoint nodes, like TViewpointNode.

  • Custom properties on Blender meshes are imported as metadata on the immediate parent Group of each X3D Shape node. Note that many X3D shapes may be part of one Blender mesh.

    For example, if you have a TShapeNode instance, you can look at parent group by TX3DNode.ParentFieldsNode property. To read metadata from the corresponding Blender mesh do this:

    if MyShape.ParentFieldsCount = 1 then
      MyString := MyShape.ParentFieldsNode[0].MetadataString['mesh_property_name']
    else
      WritelnWarning('Shape not created by glTF importer');
  • Custom properties on Blender objects are imported as metadata on the immediate parent Transform of each X3D Group representing Blender mesh. Note that one Blender mesh may be part of multiple Blender objects.

3.3. Controlling if the shape is collidable in Castle Game Engine

We recognize a special property CastleCollision at Blender mesh. It sets X3DShapeNode.collision field in X3D (TAbstractShapeNode.Collision in Pascal API). It accepts the following values:

  • none — non-collidable mesh.

  • box — mesh collides as a simple axis-aligned box (auto-calculated from bounding box of the shape, unless Shape.Bbox is explicitly specified).

  • default — mesh collides as a precise set of triangles.


To improve this documentation just edit the source of this page in AsciiDoctor (simple wiki-like syntax) and create a pull request to Castle Game Engine WWW (cge-www) repository.

Creating Game Data