Blender homepage link
header graphic
 

Multiple Materials

This page describes how to express an object having several materials, in Verse.

This is something that is often needed, but can be very hard to figure out how to do in a way that fits the data model and also works well with loaders/savers.

Involved Nodes

In this example, we will consider a general case of an object that is to have a different material on each of its surfaces. To keep things general, there will be N unique materials needed. Of course, the object could have less or more than N faces, but the "palette" of materials will be limited to N. Here, N is assumed to fit in a 32-bit unsigned integer. Thus, we need:

The object node, representing the object itself.
A geometry node, holding the base mesh (vertex and polygon layers), plus a FACE_UINT (8- or 32-bit, as needed) layer that uses integers in the range [0,N) to select the material for each face of the mesh. The name of this layer is arbitrary, but important. Here, we will call it "matsel" (for "material selector").
The N materal nodes, holding the different materials.

Linking

Once the node data is there, we need to link it together properly. Here is how:

One link with label="geometry" from the object node to the geometry node. This establishes what geometry to use for the object.
N links with label="matsel" from the object node, to each of the N material nodes. These should have target_id field values that enumerate the interval [0,N).

It is important to realize that the link label text ("matsel") on all the material links is the same as the name of the geometry layer that stores the selection data. The target_id values give each material an integer ID that is independent of the node IDs of the material nodes.

Putting it All Together

Here is a concrete example showing a cube with its faces colored one of three nice primary colors: red, green or blue.



The desired output, as interpreted by a programmer. The numerals on the faces are the index values we wish to use for the three materials shown.

The second image shows a schematic view of the nodes involved. The labels on the links show either just the value of the label field, or the value of the label and target_id fields, separated by a comma.

The "matsel" layer is not shown explicitly, although the values from it are the numbers on the cube's faces in the top image.

Example

The VML test case collection contains a sample of multiple materials. The VML is commented and should be easily readable.