Material Definition Files - MacCurdyLab/OpenVCAD-Public GitHub Wiki

Material Files

The OpenVCAD modeling language allows designers to freely express materials using string based names. For example, the following code can be used to generate a sphere with radius 5 comprised of a single stiff material:

root((-5, -5, -5), (5, 5, 5), (0.25, 0.25, 0.25))
{
    sphere(5, "stiff");
}

Similarly, multi-material nodes can be used to create design that vary material composition over space. The example bellow shows the same sphere with a 80/20 flexible/ stiff composition.

root((-5, -5, -5), (5, 5, 5), (0.25, 0.25, 0.25))
{
	fgrade(["0.8", "0.2"], ["flexible", "stiff"], "prob")
	{
		sphere(5, "stiff");
	}
}

80/20 Sphere

The designer is free to use any custom material name except for "void" (more on that later). When compiled into PNG stacks however, a translation between material name and corresponding color must be made. For example, the "stiff" and "flexible" materials above must by mapped into some unique color that the 3D-printer will understand. The printer might be configured to map a pure red (255, 0, 0, 255) to material channel-a that is loaded will the stiff material.

To facilitate in this translation process, a .VCAD file is compiled with a material definition file. This JSON file contains an array called materials. This array may be any length and contains all the possible name to color mappings. An individual mapping in the array must have a name, r, g, b, and a value. These values are on the range 0 to 255. Bellow is an example of a material definition file for the above .VCAD scripts:

{
    "materials": [
        {
            "name": "stiff",
            "r": 255,
            "g": 0,
            "b": 0,
            "a": 255
        },
        {
            "name": "flexible",
            "r": 0,
            "g": 0,
            "b": 255,
            "a": 255
        },
        {
            "name": "void",
            "r": 0,
            "g": 0,
            "b": 0,
            "a": 0
        }
    ]
}

The "void" material

In OpenVCAD, void space is represented by the "void" material. These are areas of the model that do not contain any geometry. The "void" material will default to a clear color by default (0,0,0,0). However, some 3D-printers do not support reading image stacks that contain an alpha channel. As such, the designer can change the value of the "void" material in the material definition file to map it to a color the printer expects for void. If the "void" definition is not present in the material file, then it will default to (0,0,0,0). Likewise, the "void" keyword is reserved and should not be used within .VCAD scripts unless the designer intends to create a geometry that is comprised of void space (i.e. to mix in void space to create a porous structure similar to show a stiff material was mixed into the above example).

Creating a custom material config files

When using the OpenVCAD IDE, it will automatically look in OPEN_VCAD_INSTALL_DIR/configs for material configuration files and add them to the drop down list in the code editor panel. You can open this folder by using: File->Open Material Configs Directory in the menubar. After creating or editing a config file, you will need to restart OpenVCAD.

The render preview will always use clear for void space