Materials

The material data type

The material data type works very similar to the color data type, that was described earlier. It applies a certain surface material to a solid object. The material data type has multiple constructors. The first one is quite simple:

Example

material m( 4 )

The constructor receives an integral number that defines a material code that defines the actual type of the material. The actual assignment of a certain code value to a specific material depends now on the chosen visualization type. See more about this topic in this section.

Since material values can be casted into modifiers, the application of a material onto a solid object is as simple the application of a color:

Example

material m(5)
make m >> torus()

Output of the code example.

Some materials come with their own, typical color, like "yellow" for gold. Other materials, like "plastics", don't have a specific color. They can be equipped with a so-called diffusive color, what means the "actual" color of the material (see https://en.wikipedia.org/wiki/Diffuse_reflection). The diffusive color can be applied as an alternative second parameter of type color:

Example

material( 1, rgb( 255, 0, 255 ) )

Material visualization

The solids resulting from a construction with trCAD can be visualized in different ways. One way is the trCAD online editor, another one the usage of trCAD within the paramate framework. Also other ways of visualization could be thought of.

Fixing material codes to actual visualization materials is finally a task of these respective visualization systems. The trCAD editor has e.g. a set of predefined materials whereas within paramate, it is possible to define a custom material set (including the respective OpenGL shaders). In the future there may be a common default material set but this has not been established to the point.

However, it should be tried to make the setting of a certain material code as much independent from the underlying code table as possible. For this reason, the trCAD standard library contains a module "materials.sps" that defines a number of materials by name. Using these instead of the pure numerical values helps to preserve forward compatibility:

Example

#import ( "std/materials.sps" )
enum mat_codes = materials::materials

make material( mat_codes::GOLD ) >> torus()

The following values are defined within this module:

Identifier Description
BASIC no material was set
DIELECTRIC plastics, ceramics etc.
METALLIC metallic surface with free-to-chose diffusive color
COPPER copper
SILVER silver
GOLD gold
GLASS glass (transparent material)

Please note that this list may be expanded in the future.

See also