Exporting materials

The creation of Maxwell materials is probably the part of a plug-in that requires more attention; an accurate mapping from any shader to a Maxwell material can be difficult, since the Maxwell material model follows a very physically correct approach that might be very different from the traditional shading standards. In maxwell.h and in maxwellpresets.cpp there are many examples to learn how to create materials.

There are two ways to integrate Maxwell materials within a plug-in:

  • Providing a simple interface that allows the user to import a Maxwell material file (.mxm type) and apply it to the objects. In this way, all the material handling relies on the Maxwell Material Editor (mxed.exe), a standalone editor used to create and edit Maxwell materials. Like this, the plug-in just needs to handle path references to the material files.
  • Fully integrating all the material parameters in the plug-in UI. This requires more development efforts, although this type of integration is usually friendlier for users, due to the editor having the same look and feel as the native platform.

The following function is used to create a material:

Cmaterial::Cmaterial createMaterial ( const char *pMaterialName, addToScene = true );
// "addToScene" is implemented for internal purposes and generally it is not needed to set it to false.
// By default a material is automatically embedded into the scene.

Maxwell materials can be embedded in the scene or they can be separate files (*.mxm). It is possible to read an MXS and include it into the scene. This is done with the function “read material” that returns a material read from a path. Then this material can be embedded in the scene with the function addMaterial.

Cmaxwell::Cmaterial readedMaterial = pScene->readMaterial( const char* materialPath );
Cmaxwell::Cmaterial embedMaterial = pScene->addMaterial( Cmaxwell::Cmaterial readedMaterial );

The function

Cmaxwell::Cmaterial getMaterial( const char* materialName )

returns a material given its name as parameter.