Kuesa Runtime

Kuesa Custom Materials

Kuesa provides a mecanism to extend the type of materials available in glTF files. This mecanism relies on 2 parts:

  1. Generating C++ Classes for the custom Material
  2. Registering the material classes against the glTF importer

Generating Material Classes

The process of generating C++ Qt3D compatible material classes has been simplified in Kuesa through the use of a class generator.

This generator expects a JSON based description of the material. It expects you to define:

 {
     "type": "CustomPainting",
     "doc": "Description of what the material does"
     "properties": [
         { "name": "color", "type": "vec3", "doc": "Specifies the output color" },
      ],
     "shaders": [
         {
             "format": { "api": "OpenGLES", "major": 2, "minor": 0 },
             "type": "Vertex",
             "code": "..."
         },
         {
             "format": { "api": "OpenGLES", "major": 3, "minor": 0 },
             "type": "Vertex",
             "code": "..."
         },
         {
             "format": { "api": "OpenGL", "major": 3, "minor": 2 },
             "type": "Vertex",
             "graph": "qrc:/..."
         },
         {
             "format": { "api": "OpenGLES", "major": 2, "minor": 0 },
             "type": "Fragment",
             "code": "..."
         },
         {
             "format": { "api": "OpenGLES", "major": 3, "minor": 0 },
             "type": "Fragment",
             "code": "..."
         },
         {
             "format": { "api": "OpenGL", "major": 3, "minor": 2 },
             "type": "Fragment",
             "graph": "qrc:/..."
         }
     ]
 }

Once the description file has been created, the C++ classes can be generated by calling the script file custom_material_class_generator.py

 custom_material_class_generator.py CustomPainting.json

This will generate a sub directory custompainting containing a .pri file. That .pri file should be included to the project's .pro to get the material classes built.

Registering new Material Classes

The second step to adding a new custom material to Kuesa is to register it with the glTF importer.

To do so, you'll have to call GLTF2Importer::registerCustomMaterial providing the material, properties and effect classes as well as the name of the glTF material it maps to.

 #include <Kuesa/GLTF2Importer>

 ...

 GLTF2Importer::registerCustomMaterial<CustomPaintingMaterial, CustomPaintingProperties, CustomPaintingEffect>(QStringLiteral("CustomPainting"));

Please note that this needs to be done prior to any importing.

Registering with QML

If you wish to be able to instantiate the Material classes on the QML side or access them by retrieving them from the load glTF tree, you'll also have to register the C++ classes using the usual qmlRegisterType function.