2000/utils/render/samples/allmats/allmats.cpp
////////////////////////////////////////////////////////////////////////////////
// allmats()
//
// Draw all of the materials in a given materials library file (.mli).
// The name of the library is passed in the resbuf (the only argument
// it processes).   The resbuf is NULL or not of type RTSTR, the displayed
// library will be "Support/render.mli".
//
// Returns AvRetNorm on success, otherwise, AvRetError.
//

allmats()
Draw all of the materials in a given materials library file (.mli).
The name of the library is passed in the resbuf (the only argument
it processes).   The resbuf is NULL or not of type RTSTR, the displayed
library will be "Support/render.mli".


allmats () Draw all of the materials in a given materials library file ( . mli ) . The name of the library is passed in the resbuf ( the only argument it processes ) . The resbuf is NULL or not of type RTSTR the displayed library will be " Support / render . mli " .
static AvErrorCode
allmats(struct resbuf *rb)
{
	union ads_u_val *resval;
    char            *sLibPath,
                    *sLibName;
    AvMatlibParam   libParam;
    ads_point       corner,
                    offset;
	double			dCubeSize,
					dCubeSpacing,
					dLibNameHeight;
    struct resbuf   *pMaterial;
    int             numMaterials,
                    numRows,
				    i;
	resval = getArg(rb, RTSTR, 0);
	if (resval == NULL)
		sLibPath = DEFAULT_LIBRARY_PATH;
	else
		sLibPath = resval->rstring;
	resval = getArg(rb, RT3DPOINT, 1);
	if (resval == NULL)
	{
		offset[X] = offset[Y] = offset[Z] = DEFAULT_OFFSET;
	}
	else
	{
		offset[X] = resval->rpoint[X];
        offset[Y] = resval->rpoint[Y];
        offset[Z] = resval->rpoint[Z];
	}
	resval = getArg(rb, RTREAL, 2);
	if (resval == NULL || resval->rreal <= 0.0)
		dCubeSize = DEFAULT_CUBE_SIZE;
	else
		dCubeSize = resval->rreal;
	resval = getArg(rb, RTREAL, 3);
	if (resval == NULL || resval->rreal <= 0.0)
		dLibNameHeight = DEFAULT_TITLE_HEIGHT;
	else
		dLibNameHeight = resval->rreal;
    sLibName = sLibPath + strlen(sLibPath);
    while (sLibName > sLibPath) 
	{
        if (*sLibName == '/') 
		{
            sLibName++;
            break;
        }
        sLibName--;
    }
    acutPrintf("Displaying materials library %s (%s)\n", 
		sLibName, sLibPath);
    libParam.mode = AvMatlibList;
    libParam.libraryName = sLibPath;
    libParam.flags = AvMatlibLibrary;
	if (av_matlib(&libParam) != AvRetNorm)
		return AvRetError;
    pMaterial = libParam.stringList;
	numMaterials = resbufListCount(pMaterial);
	drawText(offset, dLibNameHeight, sLibName);
    offset[Y] += dLibNameHeight * 1.5;
    numRows = (int)(sqrt((double)numMaterials)); 
	dCubeSpacing = dCubeSize * 1.5;
    for (i = 0; i < numMaterials; i++) 
	{
        corner[X] = offset[X] + (i % numRows) * dCubeSpacing;
        corner[Y] = offset[Y] + (int)(i / numRows) * dCubeSpacing;
        corner[Z] = offset[Z];
		if (drawMaterial(corner, dCubeSize, 
			pMaterial->resval.rstring, sLibPath) != AvRetNorm)
			return AvRetError;
        pMaterial = pMaterial->rbnext;
    }
    acutRelRb(libParam.stringList);  
    acutPrintf("Got %d materials\n", numMaterials);
    return AvRetNorm;
}
static AvErrorCode allmats ( struct resbuf * rb ) { union ads_u_val * resval ; char * sLibPath , * sLibName ; AvMatlibParam libParam ; ads_point corner , offset ; double dCubeSize , dCubeSpacing , dLibNameHeight ; struct resbuf * pMaterial ; int numMaterials , numRows , i ; resval = getArg ( rb , RTSTR , 0 ) ; if ( resval == NULL ) sLibPath = DEFAULT_LIBRARY_PATH ; else sLibPath = resval -> rstring ; resval = getArg ( rb , RT3DPOINT , 1 ) ; if ( resval == NULL ) { offset [ X ] = offset [ Y ] = offset [ Z ] = DEFAULT_OFFSET ; } else { offset [ X ] = resval -> rpoint [ X ] ; offset [ Y ] = resval -> rpoint [ Y ] ; offset [ Z ] = resval -> rpoint [ Z ] ; } resval = getArg ( rb , RTREAL , 2 ) ; if ( resval == NULL || resval -> rreal <= 0.0 ) dCubeSize = DEFAULT_CUBE_SIZE ; else dCubeSize = resval -> rreal ; resval = getArg ( rb , RTREAL , 3 ) ; if ( resval == NULL || resval -> rreal <= 0.0 ) dLibNameHeight = DEFAULT_TITLE_HEIGHT ; else dLibNameHeight = resval -> rreal ; sLibName = sLibPath + strlen ( sLibPath ) ; while ( sLibName > sLibPath ) { if ( * sLibName == ' ' ) { sLibName ++ ; break ; } sLibName -- ; } acutPrintf ( " \n " , sLibName , sLibPath ) ; libParam . mode = AvMatlibList ; libParam . libraryName = sLibPath ; libParam . flags = AvMatlibLibrary ; if ( av_matlib ( & libParam ) != AvRetNorm ) return AvRetError ; pMaterial = libParam . stringList ; numMaterials = resbufListCount ( pMaterial ) ; drawText ( offset , dLibNameHeight , sLibName ) ; offset [ Y ] += dLibNameHeight * 1.5 ; numRows = ( int ) ( sqrt ( ( double ) numMaterials ) ) ; dCubeSpacing = dCubeSize * 1.5 ; for ( i = 0 ; i < numMaterials ; i ++ ) { corner [ X ] = offset [ X ] + ( i % numRows ) * dCubeSpacing ; corner [ Y ] = offset [ Y ] + ( int ) ( i / numRows ) * dCubeSpacing ; corner [ Z ] = offset [ Z ] ; if ( drawMaterial ( corner , dCubeSize , pMaterial -> resval . rstring , sLibPath ) != AvRetNorm ) return AvRetError ; pMaterial = pMaterial -> rbnext ; } acutRelRb ( libParam . stringList ) ; acutPrintf ( " \n " , numMaterials ) ; return AvRetNorm ; }
allmats()
Draw all of the materials in a given materials library file (.mli).
allmats () Draw all of the materials in a given materials library file ( . mli ) .
// Get path of materials library to display
 //
 // Get offset position for drawing 
 //
 // Get cube size
 //
 // Get title text height
 //
 // Make sLibName point to the library file name only
 //
 // Get list of materials in library
 //
 // Display library name, height = 0.8
 //
 // Set Y offset for first material block
 //
 // layout is square
 // Draw each material in the library
 //
 // Find position
 //
 // Draw it
 //
 // the start of pMaterial
