Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This kind of extensions load geometry just before the render starts. They´re useful to decrease the size of the scene file and even to create loaders for new file formats. This class is defined in mx_geometryextension.h. 

Code Block
class CgeometryLoaderExtension : public CbaseExtension
{
public:
    virtual bool loadMeshinitializeForRendering( Cmaxwell::Cobject& meshToLoad* pMaxwell ) = 0;
    
    virtual bool getBoundingBoxinitializePreview( Cpoint& min, Cpoint& maxCmaxwell* pMaxwell ) 
    {
        return ( true false);
    };
 

      virtual bool getProxyDisplayPointsloadMesh( const dwordCmaxwell::Cobject& percent,meshToLoad const dword& maxPoints, dword& nPoints, float*& points )) = 0;
    
    virtual bool getBoundingBox( Cpoint& min, Cpoint& max ) 
    {
        return false;
    };
    };
    virtual bool getProxyDisplayLinesgetProxyDisplayPoints( const dword& percent, const dword& maxLinesmaxPoints, dword& nPoints, float*& points, dword& nLines, dword*& pointsPerLine )
    {
        return false;    
    };
    virtual bool getProxyDisplayFacesgetProxyDisplayLines( const dword& percent, const dword& maxFacesmaxLines, dword& nPoints, float*& points, dword& nFacesnLines, dword*& facespointsPerLine )
    {
        return false;
    }
};

The most important part of the extension functionality resides in loadMesh, which must be implemented. The rest are optional functions. getBoundingBox, if implemented, returns the maximum and minimum points of the geometry's bounding box, in local coordinates of the object. This function is called at the voxelization stage, just before starting to render.

...

    virtual bool getProxyDisplayFaces( const dword& percent, const dword& maxFaces, dword& nPoints, float*& points, dword& nFaces, dword*& faces )
    {
        return false;
    }
};

The most important part of the extension functionality resides in loadMesh, which must be implemented. The rest are optional functions. getBoundingBox, if implemented, returns the maximum and minimum points of the geometry's bounding box, in local coordinates of the object. This function is called at the voxelization stage, just before starting to render.

One of the other three functions getProxyDisplay* should be implemented if the extension writer wants to draw an approximate proxy of the object in the Studio viewport. For example, the  MaxwellGrass extension uses  getProxyDisplayLines to draw some lines representing grass strands.

The class extension constructor is used mainly to create the extension parameters (look at the example below) and, possibly, allocate data structures needed throughout the life of the extension. These data structures must be freed in the class destructor. initializeForRendering is called just before rendering starts, and the incoming pMaxwell (always check != NULL ) is useful for accessing the scene while executing loadMesh.

 

...

initializeForRendering

virtual

...

bool

...

 initializeForRendering(

...

Cmaxwell* pMaxwell ) = 0;

Main function of the extension. It is where the actual work of filling a geometric object is doneCalled at the initial stage before rendering starts. Useful for pre-allocating everything that will be needed during the render. This is especially important for Procedural Geometry extensions.

Arguments

Cmaxwell::Cobject& meshToLoad : input/output, reference to the object being created* pMaxwell : input, pointer to the scene.

Returns

true on success, false otherwise. false;

 

...

aborts the render.

initializePreview

virtual

...

bool

...

initializePreview( Cmaxwell* pMaxwell );

Returns the bounding box of the newly created object, in local coordinates of the objectReset all the pointers allocated in getProxyDisplay* and make them ready for reuse.

Arguments

Cpoint& min : output, reference to the lower corner of the bounding box.Cpoint& max : output, reference to the upper corner of the bounding boxCmaxwell* pMaxwell : input, pointer to the scene.

Returns

true on success, false otherwise false;

 

...

.

loadMesh

virtual

...

bool

...

Allocates and fills the "points" array with the coordinates of points to be drawn in the Studio viewport. Also sets "nPoints" to the actual number of points filled.

Arguments

const dword& percent : input, goes from 0 to 100, indicating the degree of desired precision to draw the proxy.

const dword& maxPoints : input, the maximum number of points allowed.

dword& nPoints : output, the actual number of points allocated. Must be <= maxPoints.

 float*& points : output, array with the points, x0y0z0x1y1z1x2y2z2....

Returns

loadMesh( Cmaxwell::Cobject& meshToLoad ) = 0;

Main function of the extension. It is where the actual work of filling a geometric object is done.

Arguments

Cmaxwell::Cobject& meshToLoad : input/output, reference to the object being created.

Returns

true on success, otherwise false;

 

getBoundingBox

virtual bool getBoundingBox( Cpoint& min, Cpoint& max );

Returns the bounding box of the newly created object, in local coordinates of the object.

Arguments

Cpoint& min : output, reference to the lower corner of the bounding box.

Cpoint& max : output, reference to the upper corner of the bounding box.

Returns

true on success, otherwise false;

 

...

getProxyDisplayPoints

virtual

...

bool

...

getProxyDisplayPoints(

...

const

...

dword&

...

percent,

...

const

...

dword&

...

maxPoints,

...

dword&

...

nPoints,

...


float*& points );

Allocates and fills the "points" array and "pointsPerLine" array with with with the coordinates of points , and number of points per line to be drawn in the Studio viewport. Also sets "nPoints" to the actual number of points created and nLines to the actual number of lines createdfilled.

Arguments

const dword& percent : input, goes from 0 to 100, indicating the degree of desired precision to draw the proxy.

const dword& maxPoints maxPoints : input, the maximum number of points allowed.const dword& maxLines : input, the maximum number of lines allowed.

dword& nPoints : output, the actual number of points allocated. Must be <= maxPoints.

float*& points : output, array with the points, x0y0z0x1y1z1x2y2z2....

dword& nLines : output, the actual number of lines created. Must be <= maxLines.

dword*& pointsPerLine : output, array with the number of points per line, n0n1n2.... If this array is NULL, then the number of points per line is constant, and is nPoints/nLines.

Returns

true on success, otherwise false;

 

getProxyDisplayFaces

virtual bool getProxyDisplayFaces( const dword& percent, const dword& maxFaces, dword& nPoints, 
float*& points, dword& nFaces, dword*& faces );

Allocates and fills the "points" array and "faces" array with with the coordinates of points, and indexes to vertices to be drawn in the Studio viewport. Also sets "nPoints" to the actual number of points created and "nFaces" to the actual number of triangles created.

Arguments

const dword& percent : input, goes from 0 to 100, indicating the degree of desired precision to draw the proxy.

const dword& maxPoints : input, the maximum number of points allowed.

const dword& maxFaces : input, the maximum number of faces allowed.

dword& nPoints : output, the actual number of points allocated. Must be <= maxPoints.

float*& points : output, array with the points, x0y0z0x1y1z1x2y2z2....

dword& nFaces : output, the actual number of faces created. Must be <= maxLines.

dword*&  : output, array with the indices to vertices in the "points" array  v00v01v02v10v11v12v20v21v22....

Returns

true on success, otherwise false;

 

 

...

languagecpp
titleExample of Cube creator
firstline1
linenumberstrue

...

Returns

true on success, otherwise false;

 

getProxyDisplayLines

virtual bool getProxyDisplayLines( const dword& percent, const dword& maxPoints, const dword& maxLines,
dword& nPoints, float*& points, dword& nLines, dword*& pointsPerLine );

Allocates and fills the "points" array and "pointsPerLine" array with with the coordinates of points, and number of points per line to be drawn in the Studio viewport. Also sets "nPoints" to the actual number of points created and nLines to the actual number of lines created.

Arguments

const dword& percent : input, goes from 0 to 100, indicating the degree of desired precision to draw the proxy.

const dword& maxPoints : input, the maximum number of points allowed.

const dword& maxLines : input, the maximum number of lines allowed.

dword& nPoints : output, the actual number of points allocated. Must be <= maxPoints.

float*& points : output, array with the points, x0y0z0x1y1z1x2y2z2....

dword& nLines : output, the actual number of lines created. Must be <= maxLines.

dword*& pointsPerLine : output, array with the number of points per line, n0n1n2.... If this array is NULL, then the number of points per line is constant, and is nPoints/nLines.

Returns

true on success, otherwise false;

 

getProxyDisplayFaces

virtual bool getProxyDisplayFaces( const dword& percent, const dword& maxFaces, dword& nPoints,
float*& points, dword& nFaces, dword*& faces );

Allocates and fills the "points" array and "faces" array with with the coordinates of points, and indexes to vertices to be drawn in the Studio viewport. Also sets "nPoints" to the actual number of points created and "nFaces" to the actual number of triangles created.

Arguments

const dword& percent : input, goes from 0 to 100, indicating the degree of desired precision to draw the proxy.

const dword& maxPoints : input, the maximum number of points allowed.

const dword& maxFaces : input, the maximum number of faces allowed.

dword& nPoints : output, the actual number of points allocated. Must be <= maxPoints.

float*& points : output, array with the points, x0y0z0x1y1z1x2y2z2....

dword& nFaces : output, the actual number of faces created. Must be <= maxLines.

dword*& faces : output, array with the indices to vertices in the "points" array  v00v01v02v10v11v12v20v21v22....

Returns

true on success, otherwise false.

 

Code Block
languagecpp
titleExample of Cube creator
firstline1
linenumberstrue
#include <math.h>
#include "extensionmanager.h"
#include "geometryextension.h"
#include "maxwell.h"

using namespace mx;

class CubeExampleExtension : public CgeometryLoaderExtension
{
	DECLARE_EXTENSION_METHODS( "CubeExample", CubeExampleExtension, 1 )
    Cmaxwell* pMaxwellLocal; //Handy to access the scene.

    //Helper function to spit messages to maxwell.
    void printMessage( const char* text, const int code )
    {
        if( pMaxwellLocal != NULL ) 
        {
            char pMessage[ 1024 ];
            sprintf ( pMessage, "[Extension %s] %s", getName(), text );
            pMaxwellLocal->printMessage( pMessage, code );
        }
    }

public:
	CubeExampleExtension()
	{
		getExtensionData()->createDouble( "Cube size", 1.0, 0, 1000 );//Create parameter with Default value
	}
 
	~CubeExampleExtension() 
	{
	}

	bool initializeForRendering ( Cmaxwell* pMaxwell )
	{
	    pMaxwellLocal = pMaxwell;
	    return true;
	}

	bool loadMesh( Cmaxwell::Cobject &cube )
	{
	//Get the extension parameter
		getExtensionData()->getDouble( "Cube size", cubeSize );

	//Create the mesh
		cube.initializeMesh( 8, 6, 12, 1 );

	//Add the vertices
		Cpoint point;
		point.assign( 0.0, 0.0, 0.0 );					cube.setVertex ( 0, 0, point );
		point.assign( 0.0, 0.0, cubeSize );				cube.setVertex ( 1, 0, point );
		point.assign( cubeSize, 0.0, cubeSize );		cube.setVertex ( 2, 0, point );
		point.assign( cubeSize, 0.0, 0.0 );					cube.setVertex ( 03, 0, point );
		point.assign( 0.0, cubeSize, 0.0, cubeSize );				cube.setVertex ( 14, 0, point );
		point.assign( cubeSize, 0.0, cubeSize, cubeSize );		cube.setVertex ( 25, 0, point );
		point.assign( cubeSize, 0.0cubeSize, 0.0cubeSize );				cube.setVertex ( 36, 0, point );
		point.assign( 0.0cubeSize, cubeSize, 0.0 );				cube.setVertex ( 47, 0, point );

		point//Set some normals
		Cvector normal;
		normal.assign( 01.0, cubeSize0.0, cubeSize0.0 );		cube.setVertex setNormal( 50, 0, pointnormal );
		pointnormal.assign( cubeSize-1.0, cubeSize0.0, cubeSize0.0 );	cube.setVertex setNormal( 61, 0, pointnormal );
		pointnormal.assign( cubeSize0.0, cubeSize1.0, 0.0 );		cube.setVertex setNormal( 72, 0, pointnormal );

	//Set some normals
		Cvector normal;
		normal.assign( 10.0, 0-1.0, 0.0 );		cube.setNormal( 03, 0, normal );
		normal.assign( -10.0, 0.0, 01.0 );		cube.setNormal( 14, 0, normal );
		normal.assign( 0.0, 10.0, 0-1.0 );		cube.setNormal( 25, 0, normal );

		normal.assign//Add triangles
		cube.setTriangle ( 0.0, -1.0, 0.0 );	cube.setNormal(2, 1, 3, 03, normal3 );
		normalcube.assignsetTriangle ( 0.0, 0.0, 1.01, 0, 3, 2, 3, 3, 3 );
		cube.setNormalsetTriangle ( 2, 4, 5, 6, 02, 2, normal2 );
		normalcube.assignsetTriangle ( 0.03, 0.04, -1.0 );	cube.setNormal( 5, 0, normal6, 7, 2, 2, 2 );

	//Add triangles
		cube.setTriangle ( 04, 02, 23, 17, 30, 30, 30 );
		cube.setTriangle ( 15, 02, 37, 26, 30, 30, 30 );
		cube.setTriangle ( 26, 40, 51, 65, 21, 21, 21 );
		cube.setTriangle ( 37, 40, 65, 74, 21, 21, 21 );
		cube.setTriangle ( 48, 21, 32, 76, 04, 04, 04 );
		cube.setTriangle ( 59, 21, 76, 65, 04, 04, 04 );
		cube.setTriangle ( 610, 0, 14, 57, 15, 15, 15 );
		cube.setTriangle ( 711, 0, 57, 43, 15, 15, 15 );

		cube.setTriangle ( 8, 1, 2, 6, 4, 4, 4 );
		cube.setTriangle ( 9, 1, 6, 5, 4, 4, 4//Generate some uvs
		dword cchanIdx = 0;
		dword daChan;
		cube.addChannelUVW( daChan, cchanIdx );
		Cbase projBase;
		projBase.origin.assign( 0.5, 0.5, 0.5 );
		cube.setTriangle projBase.xAxis.assign( 101.0, 0.0, 4, 7, 5, 5, 50.0 );
		cube.setTriangle projBase.yAxis.assign( 110.0, 1.0, 7, 3, 5, 5, 50.0 );

	//Generate some uvs
		dword cchanIdx = 0;
		dword daChan;
		cube.addChannelUVW( daChan, cchanIdx	projBase.zAxis.assign( 0.0, 0.0, 1.0 );
		CbaseCvector projBasescale; 		projBasescale.origin.assign( 0.5, 0.5, 1.0.5 ) );
		byte sux = cube.generateCubicUVW( cchanIdx, projBase );
		return true;
		projBase.xAxis.assign( 1.0, 0.0, 0.0 );
		projBase.yAxis.assign( 0.0, 1.0, 0.0}
 
	bool getBoundingBox( Cvector &bmin, Cvector& bmax)
	{ 
		bmin.assign( -cubeSize, -cubeSize, -cubeSize );
		projBase.zAxisbmax.assign( 0.0cubeSize, 0.0cubeSize, 1.0cubeSize );
		Cvector scale; scale.assign( 0.5, 0.5, 1.0 );
		byte sux = cube.generateCubicUVW( cchanIdx, projBase );
		return true;
	}
 
	bool getBoundingBox( Cvector &bmin, Cvector& bmax)
	{ 
		bmin.assign( -cubeSize, -cubeSize, -cubeSize );
		bmax.assign( cubeSize, cubeSize, cubeSize );
		return true;
	}
};
EXPORT_GEOMETRY_LOADER_EXTENSION( CubeExampleExtension )return true;
	}
};

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;
}