Material Parser v1.1

1:10 pm in Tesla Engine by Starnick

Just pushed a series of commits to the subversion repository, which bring many enhancements (mostly minor) notably changes to material parsing. I completely redesigned and rewrote the parser to be better organized, more stable, and more efficient. In addition, it supports just about all the items left on my TODO list:

1. Comment parsing is a lot less finicky now. No need to space them, put them on new lines, etc.

2. Multiple materials are now allowed in a single script file.

3. Renderstates now can be fully configured.

4. Added support for the Color data type (R G B A format, integer values that get clamped to the 0-255 byte range)

To support multiple materials, the old material loader has been separated into two distinct content loading paths. Loading a single material script, or the very first material in a multiple material script file is exactly the same as it was. In order to load multiple materials, you must use a MaterialCollection object:


MaterialCollection materials = ContentManager.Load<MaterialCollection>("Materials/MyMaterialScript.tem");

foreach(Material mat in materials) {

//Do something with the material

}

The MaterialCollection is cached inside the content manager, not the individual materials. You can also exclusively use this way of loading, as TEM files with a single material can be loaded into a MaterialCollection. The collection will simply contain a single material.

I have compiled a nice little (well it’s quite large and comprehensive actually :) ) PDF documentation that goes over the correct syntax and all the features of a material script here. It has quite a few examples that should make it very easy to get started with scripting!

The last piece of the puzzle holding back the release is serializing materials into TEM files. Currently, serializing the scene graph works beautifully, but you’ll have to recreate materials manually when de-serializing the scene from the binary file. I aim to have some sort of option or hook (most likely tied to the unimplemented “WriteExternal<T>” ISavableWriter methods) so you have the option to either write materials to binary files (TEBO) or the text-based TEM files. This also includes writing our effects and textures to their own TEBO files. So there’s a few moving pieces here that I want to make sure all mesh nicely in the system.

There really isn’t a point saving everything into one giant file (can’t re-use anything and end up wasting disk space). On the other hand, you have to make sure you don’t overwrite files and lose data! Most likely, writing multiple files will be ideal for individual models and not for large scenes. In the latter case, a single file may be ideal (or some other level format).