Tutorial 11. Exporting Assets from Blender - gecko0307/dagon GitHub Wiki
Dagon version: >=0.12
Since Dagon 0.12, the recommended asset format for using with Dagon is glTF, a JSON-based scene description accompanied by a binary file that stores raw data such as vertex buffers.
glTF feature support in Dagon:
- ✔️ Scenes and nodes (interpreted as
Entityhierarchy) - ✔️ Meshes (Dagon implements a separate mesh system for glTF models, optimized for fast loading and rendering)
- ✔️ Materials and textures (Dagon's PBR materials are directly compatible with glTF)
- ❌ Skins and animations (WIP)
To export your models to glTF, you can use Blender. The workflow is straightforward and requires almost no specific actions. A number of compatibility issues exist:
- Dagon currently supports only
.gltf + .binform,.glbis not supported - Progressive encoding is not supported for JPEG images
- EEVEE-next (Blender 4.2) dropped support for alpha clipping (
"alphaMode":"MASK"in glTF). You should add it manually in your shader using nodes; see below.
TODO: add instructions on alpha clipping.
On the application side, a model is loaded via GLTFAsset object:
class Mycene: Scene
{
GLTFAsset model;
override void beforeLoad()
{
model = addGLTFAsset("assets/model.gltf");
}
}
The model cannot be used directly in the scene because it has its own node hierarchy, and it is not always the case that the model is used by the application entirely - it is possible to use only parts of the data, such as separate entities or meshes. You can choose which entities you want to add to the scene via useEntity. The simplest case is to use all of them:
override void afterLoad()
{
model.markTransparentEntities();
useEntity(model.rootEntity);
foreach(node; model.nodes)
{
useEntity(node.entity);
}
}
markTransparentEntities method is necessary in cases when glTF objects use alpha-blended materials, because in this scenario the engine must know which entities should be drawn in forward mode. This is not needed when all materials are opaque or alpha-clipped.
rootEntity represents the scene as a whole. GLTFAsset also provides all the data from glTF scene description in correspondings properties:
JSONDocument doc- parsed JSONArray!GLTFBuffer buffers- array of buffersArray!GLTFBufferView bufferViews- array of buffer viewsArray!GLTFAccessor accessors- array of accessorsArray!GLTFMesh meshes- array of meshes.GLTFMeshisDrawableand can be used with ordinary entitiesArray!TextureAsset images- array of images (represented asTextureAssetobjects)Array!Texture textures- array of textures (ordinary Dagon textures)Array!Material materials- array of materials (ordinary Dagon materials)Array!GLTFNode nodes- array of scene nodes. Each node holds anEntityArray!GLTFSkin skins- array of skins (WIP)Array!GLTFScene scenes- array of scenes. A scene is just a collection of nodes