Introduction
The Exchange Mapper is defined in the exchange.framework however maxon::nodes::NodeMaterialExportInterface and maxon::nodes::NodeMaterialImportInterface are declared in the nodespace.framework due to some API compatibility requirements to be reworked in the future.
The main purpose of the framework is to provide a reusable and extendable way to transport a material definition across different formats without an explicit dependency on the chosen format.
Once a material definition is implemented, it's possible to use it to:
- Read properties during the import phase: generate a custom material from the properties found in the imported file.
- Write properties during the export phase: generate properties from a custom material to store in the exported file.
Then it's possible to provide a mapping from a material definition to another one.
FBX Example
- Some maxon::MAXON_ATTRIBUTE are defined within a namespace: this is called a material description bundle. These maxon::MAXON_ATTRIBUTE describe all the possible entries of a material definition.
Such attributes are stored in: a maxon::material::MaterialExchangeData to represents the features (the material definition) of an FBX material.
Default values for each attribute are defined using the Resource Editor.
- A maxon::material::MaterialImportInterface is defined for each Cinema API material (MaterialData).
maxon::material::MaterialImportInterface::CreateMaterial() is called to return a BaseMaterial pointer from a given maxon::material::MaterialExchangeData.
This is the place where to check if the provided maxon::material::MaterialExchangeData is an FBX material definition via maxon::material::MaterialExchangeData::_materialTypeId and eventually perform further operations on the provided data to better accommodate with the custom MaterialData needs (e.g. apply a hue shift, or link the roughness to the specular parameter).
- A maxon::nodes::NodeMaterialImportInterface is defined for each node space.
Similarly to the maxon::material::MaterialImportInterface, this interface is designed to manage node-based materials. Since there is only one MaterialData type for all the possible node-based materials in Cinema 4D, it relies on the node space.
A maxon::material::MaterialExportInterface is defined for each Cinema API material (MaterialData).
The maxon::material::MaterialExportInterface::Export() is called to return a maxon::material::MaterialExchangeData feed with an FBX material definition from a given BaseMaterial and a maxon::DataDictionary containing setting (e.g. the target type, the baking size, etc).
In case no exporter is found from the custom MaterialData to an FBX output, the maxon::NODESPACE::EXCHANGE::BUNDLE::VIEWPORTMATERIAL is used as fall-back. The steps are:
- The maxon::material::MaterialExchangeData is, first, exported to a VIEWPORTMATERIAL.
- The VIEWPORTMATERIAL, is then mapped via a MaterialMappingInterface to the FBX material definition.
In the end if no suitable mapping is found to export a custom material, the default values of the FBX material definition will be set.
- A maxon::nodes::NodeMaterialExportInterface is defined for each node space.
Similarly to the maxon::material::MaterialExportInterface, this interface is designed to manage node-based materials. Since there is only one MaterialData type for all the possible node-based materials in Cinema 4D, it relies on the node space.
- A maxon::material::MaterialMappingInterface can be defined to convert a material definition to another.
The process takes two passes:: first to transfer the POD type (stored in maxon::material::MaterialExchangeData._parameters), then to transfer the texture (stored in maxon::material::MaterialExchangeData._textures).
Further Reading