Exporting lights

Maxwell Render always needs real geometry to emit lights. Spotlights and other abstractions that are not physically correct are not natively supported. However it is possible converting lights such cone lights, spot lights, etc from the host platform into real geometries with emission materials applied. The maxwelllights.cpp file of the SDK provides some convenience functions to translate lights easily. This file is also attached here.

For instance:

byte CreateHemisphereLight ( Cmaxwell* pScene, char* name, Cbase& base, Cmaxwell::Cmaterial& emitMat, real sceneScale,
                             real sizeX, real sizeY, real sizeZ, dword hemisphereSegments,
		             bool hideToCamera, bool hideToRays, Cmaxwell::Cobject& hemisphere )
{
	byte isOk = 1;
	real radiusX = sizeX *sceneScale * 0.5;
	real radiusY = sizeY *sceneScale * 0.5;
	real radiusZ = sizeZ *sceneScale * 0.5;

	dword nVertices = 2 + ( hemisphereSegments - 2 ) * hemisphereSegments;
	dword nTriangulos = 2 * hemisphereSegments + ( hemisphereSegments - 3 ) * 2 * hemisphereSegments;
	dword nNormales = 0;
	hemisphere = pScene->createMesh ( name, nVertices, nNormales, nTriangulos, 1 );

	Cpoint pos;
	pos.assign ( 0.0 , radiusY,  0.0 );//Polo norte
	isOk = hemisphere.setVertex ( 0, 0, pos );

	pos.assign ( 0.0, 0.0, 0.0 );//Polo sur
	isOk = hemisphere.setVertex ( nVertices - 1, 0, pos );

	dword latSegments = hemisphereSegments - 1;
	real deltaLat =  pi / ( ( real ) 2.0*latSegments );

	//Vertices
	dword iVertex = 1;
	for ( dword i = 0; i < latSegments - 1; i++ )
	{
		real lat0 = pi/2 - deltaLat - ( deltaLat * i );

		for ( dword j = 0; j < hemisphereSegments; j++ )
		{
			real lon0 = (2 * pi /(real)hemisphereSegments)* j;

			real x0 = radiusX*cosf( lat0 ) * cosf( lon0 );
			real y0 = radiusY*sinf( lat0 );
			real z0 = radiusZ*cosf( lat0 ) * sinf( lon0 );

			pos.assign ( x0, y0, z0 );
			isOk = hemisphere.setVertex ( iVertex, 0, pos );
			iVertex++;
		}
	}

	//Faces
        //hemisphere above
	for ( dword i = 0; i < hemisphereSegments; i++ )
	{
		dword i2 = i+2;
		if ( i == hemisphereSegments - 1 ) i2 = 1;
		isOk = hemisphere.setTriangle ( i, 0, i+1, i2, 0, 0, 0 );
	}

	dword coronas = latSegments - 2;
	dword iFace = hemisphereSegments;
	for ( dword i = 0; i < coronas; i++ )
	{
		for ( dword j = 0; j < hemisphereSegments; j++ )
		{
			dword vOff = 1 + i*hemisphereSegments;
			dword i1 = vOff + j;
			dword i2 = vOff + hemisphereSegments + j;
			dword i3 = vOff + hemisphereSegments + j + 1;
			if ( j == hemisphereSegments - 1 ) i3 = vOff + hemisphereSegments;
			dword i4 = vOff + j + 1;
			if ( j == hemisphereSegments - 1 ) i4 = vOff;

			isOk = hemisphere.setTriangle ( iFace, i1, i2, i4, 0, 0, 0 );
			iFace++;
			isOk = hemisphere.setTriangle ( iFace, i2, i3, i4, 0, 0, 0 );
			iFace++;
		}
	}

        //Disk below
	dword vO = 1+hemisphereSegments*(hemisphereSegments-3);
	for ( dword i = 0; i < hemisphereSegments; i++ )
	{
		dword i2 = i + vO + 1;
		if ( i == hemisphereSegments - 1 ) i2 = vO;
		isOk = hemisphere.setTriangle ( iFace, i + vO, nVertices-1, i2, 0, 0, 0 );
		iFace++;
	}

	isOk = hemisphere.setBase ( base );
	Cbase pivot;
	pivot.initCanonic ();
	isOk = hemisphere.setPivot( pivot );

	isOk = hemisphere.setHideToCamera( hideToCamera );
	isOk = hemisphere.setHideToReflectionsRefractions( hideToRays );
	isOk = hemisphere.setMaterial( emitMat );

	return isOk;
}