Creating your own extension

Extensions in Maxwell are dynamic link libraries, that are loaded on demand. Their filename end with the suffix ".<platform>.mxx", where platform can be one of win32, win64, osx or linux64, and are typically stored in the "extensions" folder inside Maxwell installation folder. They must be compiled and linked with the maxwell SDK.

All the extensions currently distributed with Maxwell have been created with this same API, without tricks or shortcuts, so it is a good showcase of what can be achieved with it.

There are several extension types that group extensions with the same functionality, and that need to implement some specific methods depending on type. All extensions types inherit from class CbaseExtension that handle the general interface with Maxwell, and the methods that every extension must implement in order to work correctly. There are currently 3 geometry extension types that can be created, and there are plans in the future for more extension types for other different needs and not only geometry, but they are in the works and not fully supported yet.

An extension must inherit from one of the types, implement 3 methods for the interface, and implement the specific methods of the extension type (it depends in every type). Also, it has to implement a couple of methods to properly register and start the extension in maxwell.

Example of a basic extension implementing generic methods.

class CubeExampleExtension : public CgeometryLoaderExtension
{
  
 // Macro for bureaucracy. Parameters: extension name, main class in the extension, and the version number
 DECLARE_EXTENSION_METHODS( "CubeExample", CubeExampleExtension, 1 )
public:
//declare internal variables for calculation, they can be public or private, and should include at least 
//variables for storing extensionData values 
 double cubeSize;
 
 CubeExampleExtension()
 {
   // create here the editable values of the extensions, they can be modified when used, 
   // getExtensionData returns the internal MxParamList to create new fields
   // check MxParamList for all possibilities of types creation

    //create parameter with name, default value, minimum value and maximum value
    getExtensionData()->createDouble( "Cube size", 1.0, 0, 1000 );
 }
 
 ~CubeExampleExtension() 
 {
  //not needed to implement since we don't reserve memory. 
 }
 
 bool initializeForRendering( Cmaxwell* pMaxwell )
{
   //We must at least copy the extensionData values to internal variables, this will be called usually just one time,
   //before maxwell needs it, and never during render time. All the heavy work must be done here.
   getExtensionData()->getDouble( "Cube size", cubeSize );//Get the parameter value and store it before using it
   return true;
 }
 
 bool loadMesh( Cmaxwell::Cobject &cube )
 {
   ...
   // CgeometryLoaderExtension method, will be explained in the corresponding chapter 
  ...
 } 
 
 bool getBoundingBox( Cvector &bmin, Cvector& bmax)
 { 
   ...
   // CgeometryLoaderExtension method, will be explained in the corresponding chapter 
   ... 
 }
}

extern "C" ALWAYSEXPORT int getSdkVersion()
{
    return MAXWELL_SDK_VERSION;
}

extern "C" ALWAYSEXPORT int StartExtension( CextensionManager& extensionManager )
{
    int i = 0;
    if( extensionManager.registerGeometryLoaderExtension( new CubeExampleExtension ) ) i++;
    return i;
}