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.
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
.gltf formats) to
TCastleScene. See manual about viewports and scenes.
You can also open the glTF file with view3dscene.
Blender documentation of the glTF exporter documents how to setup your models in Blender to export correctly to glTF.
Details about Castle Game Engine support for glTF. We support most glTF features, including physical materials and skinned animation.
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.
Moreover select "Keep Original" or edit the "Textures" directory in the export dialog, so that glTF file will refer to your existing textures by relative filenames. In the simplest case, if your textures are already in the same directory as your glTF file, you don’t need to do anything, "glTF Separate (.gltf + .bin + textures)" will just use these textures.
This means that glTF file will only refer to your texture files. This allows to share textures between various models and keeps importing fast. It also allows to easily edit the textures in other applications, without the need to export glTF again.
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)
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:
See our demo-models, subdirectories
blender/custom_properties_2/, for sample models.
See examples/short_api_samples/metadata/metadata_use.dpr for sample Pascal code getting/setting metadata from Pascal.
Usage of custom properties:
Custom properties on Blender materials are imported as metadata on X3D material nodes, like
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
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.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.
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.
Copyright Michalis Kamburelis and Castle Game Engine Contributors.
This webpage is also open-source and we welcome pull requests to improve it.