3D Models

From Maria GDK Wiki
Revision as of 15:54, 2 August 2024 by Ths (talk | contribs)
Jump to navigation Jump to search

3D models of various standard formats can be used in Maria 3D. Models can be used in various parts of the system, but the most common is to add a 3D model to a point object, such as a track or a point symbol.

In order to use a model it needs to be registered in the INative3DRenderingManager. Models are referenced by a string ID which can be set explicitly with AddModel, or it will be defined in the model config file.

When using the AddModelDirectory method all models with a corresponding model config file will be added.

Model config files

A 3D model can have an associated model config file. The model config file will define the ID and transform for a model, as well as optionally materials and multiple variants of the same model. There are two formats for this file which will be found as model.cfg or model.json. The JSON format is preferred and new models should only use this.

Example:

{
    "id": "pawn",
    "file": "pawn.fbx",

    "rotate": [ -90.0, 0.0, 0.0 ],
    "translate": [ 0.0, 0.0, 0.0 ],
    "scale": 1.0,

    "variants":
    [
         {
            "id": "pawn_blue",
            "material": "blue.mtl"
        },
        {
            "id": "pawn_red",
            "material": "red.mtl"
        },
        {
            "id": "pawn_green",
            "material": "green.mtl"
        },
        {
            "id": "pawn_yellow",
            "material": "yellow.mtl"
        }
    ]
}

This model has three variants. These will be registered with separate ID's so that if you use a model with id "pawn_green" in Maria 3D, you will get the Pawn model with the green materials applied.

Material files

The Material files are in an internal format tightly bound the "Silent Toolkit" scene graph and material system. This format has a quite rich set of options to modify a 3D mesh or parts of it with various settings, but we will only describe the basics here:

Example:

material {
   name = green
   shader {
      name = DefaultTextureShading
   }

   texture {
	  file = pawn_ao.png
	  min_filter = GL_LINEAR
	  mag_filter = GL_LINEAR
   }
   
   ambient = [ 0.4, 0.6, 0.4 ]
   diffuse = [ 0.6, 1.0, 0.6 ]
   specular = [ 0.0 0.0 0.0 ]
}

binding {
   material = green
}

Supported formats

In theory we support all formats that are supported by the assimp asset loading library, but in practice there are only a few formats that are generally well behaved. We have had most success with the following formats:

  • Autodesk FBX (.fbx)
  • Collada (.dae)
  • Wavefront OBJ (.obj)
  • Lightwave (.lwo)