[SESI logo]

Prisms Development Toolkit Documentation

Side Effects Software Inc. 1997

Custom SOP Reference

sopDefaults

This sets up the default values the SOP's input fields will have when it is first put into an object's SOP list. In our example, the circle should default to being centered at (0, 0, 0). It will have an initial radius of 1.0, and be divided into 10 segments. The circle will be drawn in the XY plane.

The result looks like this:


/* define SOP-specific constants and menus */

#define PLANE_XY	0
#define PLANE_YZ	1
#define PLANE_ZX	2

static MENU 	planeTypes[] = {
	{ NULLMFUNC, "XY", (char *)PLANE_XY, },
	{ NULLMFUNC, "YZ", (char *)PLANE_YZ, },
	{ NULLMFUNC, "ZX", (char *)PLANE_ZX, },
	{ NULL },
};

static void
sopDefaults(SOP *sop)
{
    SOP_DATA	*sb;

    if (sop->special) 
	free(sop->special);
    sb = (SOP_DATA *)Calloc(sizeof(SOP_DATA), "SOPCircleDefaults");
    sop->special = (char *)sb;

    /* if there were inputs, they would be defined here as
    if (sop->sopin[0].type == SOURCE_NULL)      	// new sop
        sop->sopin[0].type = SOURCE_PREV;
    */
    sop->nsources = NSOURCES;
    SopClearSources(sop, sop->nsources);

    InitSopExpr(&sb->center[0], "0");
    InitSopExpr(&sb->center[1], "0");
    InitSopExpr(&sb->center[2], "0");
    InitSopExpr(&sb->radius, "1");
    InitSopExpr(&sb->ndivs, "10");

    InitSopMenu(&sb->orient, planeTypes, PLANE_XY, "Orientations");
}
The user changes here involve the choice of Init routines, and the values passed. The routine InitSopExpr() initializes an expression value, and needs to see the address of a sop value location, and a string containing the default value. The preceeding example should be self-explanatory.

For menus, there is InitSopMenu(), which is defined thus:


void
InitSopMenu(SOP_EXPR *sep, MENU *mp, int entry, char *title)

where
sep is the entry in the SOP structure containing the menu mp is a pointer to a structure containing a list of menu entries
The first field is a pointer to a menu function - this will be NULL. The second is a menu string, and the third is the keyboard equivalent of that string. Usually, these are just ordered integers which distinguish one choice from the next.
entry is the number of the default entry. Number in this case means the integer just assigned to that entry.
title is the name which appears on the SOP to the left of the menu.

Other Initialization Routines

The following are also available to the programmer:
void InitSopFile(SOP_EXPR *sep, char *str)
sets intial file name to a file chooser, eg
InitSopFile(&sb->filename, "$JOB/Poly/$N.bpoly");

void InitSopFunc(SOP_EXPR *sep, char *str, void (*func)(SOP *))
sets an initial function to be called by the SOP. Usually, this is some kind of initialization or reinitialization that the animator may want to perform, eg
InitSopFunc(&sb->init, "Initialize bevel nicely", sopBevelInit);

void InitSopObject(SOP_EXPR *sep, char *str)
sets an initial object to be referenced by the SOP, eg
InitSopObject(&sb->magobj, "magnet");

void InitSopString(SOP_EXPR *sep, char *str)
sets an initial string referenced by a SOP, eg
InitSopString(&sb->polylist, "");

void InitSopToggle(SOP_EXPR *sep, char *label)
sets the passed params value to 0 (toggle off) and sets up a label to describe the toggle, eg
InitSopToggle(&sb->quads, "Connect with quads");

void InitSopUserMenu(SOP_EXPR *sep, char *str)
int (*func)(SOP *, UI_STRING *, SOP_EXPR *))
sets up a string containing a default value, and the location of a user-defined function which itself builds a menu that the user can access. Usually this menu is created dynamically, depending on data coming into the SOP.
For example, the Sage SOP defaults to converting a SOP in Sage called "convert1"; however, the user really wants to see a menu of possible SOPs to bring in from the Sage file, but this information is not available until after the SOP has been cooked.
In the Sage SOP, this is used as
InitSopUserMenu(&sb->sop, "convert1", getAvailableSops);
where 'getAvailableSops' is defined as

static int
getAvailableSops(SOP *sop, UI_STRING *sp, SOP_EXPR *sep)
{
    SOP_DATA	 *sb;
    UI_MENU	 *mp;
    MENU	 *entry;
    FILE	 *ifp;
    int		  i;
    char	**sops;
    char	 *file;

    sb = (SOP_DATA *)sop->special;

    file = SopExpandString(sop, sb->file.value.sval);
    if (sb->saging && sb->oldFile && strcmp(file, sb->oldFile) != 0)
    {
	ACTsageStop(sb->saging);
	sb->saging = 0;
    }
    if (!sb->saging)
    {
	if (sb->oldFile) free(sb->oldFile);
	sb->saging = ACTsageStart(file);
	sb->oldFile = strdup(file);
    }

    sops = ACTsageGetSops(sb->saging);
    i = 0;
    if( sops )
    {
	for (; sops[i]; i++)
	{
	    GeneralBigMenu[i].func = NULLMFUNC;
	    GeneralBigMenu[i].menu = sops[i];
	    GeneralBigMenu[i].keyboard = (char *)0;
	}
	free(sops);
    }
    GeneralBigMenu[i].func = NOFUNC;
    GeneralBigMenu[i].menu = NOSTRING;

    mp = UI_InitMenu("Sage SOPs", GeneralBigMenu);
    UI_SelectMenu(mp);
    entry = UI_RenderMenu();
    UI_CleanMenu(mp);

    if (entry)
    {
	strreplace(&sep->value.sval, entry->menu);
	UI_SETSTRING(sp, entry->menu);
    }

    for (i = 0; GeneralBigMenu[i].func != NOFUNC; i++)
	free(GeneralBigMenu[i].menu);

    return (entry) ? 1 : 0;
}


Tookit Overview
Expression Functions | User Functions | Custom SOPs
Prisms Internal Format | Programmer's Reference
Compiling SOPs | Using sopbuild | SOP Routine Reference
Dynamic SOPs | Prisms Types | Macros
Math Routines | Data Routines | Polygon Routines | Winged-edge Routines

Copyright © 1997 Side Effects Software Inc.
477 Richmond Street West, Toronto, Ontario, Canada M5V 3E7