Using Scripts on Exported POD Files in PVRGeoPOD

Scripts can be used to export any desired data from POD files

The Export user data option (see User Options in PVRGeoPOD) allows the user to apply a script to export any desired data. The location of this script must be entered or browsed to, in order for this feature to function.

The user-defined script should implement the following functions:

  • DefineNodeUserData

  • DefineMaterialUserData

  • DefineSceneUserData

These functions will be called during the export process:

  • DefineNodeUserData when exporting an object to a POD node

  • DefineMaterialUserData when exporting a material

  • DefineSceneUserData when exporting a full scene.

DefineNodeUserData will be passed a node ID, DefineMaterialUserData will be passed a material ID and DefineSceneUserData will be passed nothing.

The return value of each script will be written into the pUserData field of the SPODNode, SPODMaterial, or SPODScene as appropriate. Once the export process is complete, it is then the responsibility of the user to read the pUserData field and parse the exported data correctly.

Examples of using MAXScript and MEL are shown below.

MEL

/* Note: The return type of the procedures can be changed if desired */
                       
global proc string DefineNodeUserData(string $nodeid)
{
    /* Return the node name and class type as a string to be included in the POD node for nodeid */
    string $type = `nodeType $nodeid`;
    return $nodeid + " is of type " + $type;
}
                       
global proc string DefineMaterialUserData(string $matid)
{
    /* This function is going to return the material colour but as a commaa */
    /* comma seperated string. The first value will be a unique tag to */
    /* identify that the colour value is being exporting. The second value will */
    /* be the material's red colour value, the third will be the green colour value
    /* and the final value will be blue. */
                       
    string $s = "";
    $s += "3002,";
    float $c[] = `getAttr ($matid + ".color")`;
    $s += $c[0] + "," + $c[1] + "," + $c[2];
    return $s;
};                       
                       
global proc string DefineSceneUserData()
{
    /* Anything returned from this function will be included in the SPODScene's user data. */
    /* This is for information that does not belong with a node or a material. */
                       
    return "Extra global data";
}
                   

MAXScript

function DefineNodeUserData nodeid =
(
    /* Return the node name and class type as a string to  */
    /* be included in the POD node for nodeid */
    node = maxOps.getNodeByHandle nodeid
    str = stringstream ""
    format "% is of type " node.name  to:str
    print (superClassOf node) to:str
    str as string
)
                
function DefineMaterialUserData matid subid =
(
    mat = sceneMaterials[matid]
    superClassOf mat
                
    /* Is the material a subobject material? */
    if isKindOf mat multimaterial then
    (
        /* If it is a subobject material then return its name and parent material name */
        str = stringstream ""
        submat = mat.materialList[subid]
        format "%:%" mat.name submat.name to:str
        return str as string
    )
                
    /* The material here is just a material. This function going to return the 
    /* diffuse colour but in a structured way using a MAXScript array. */
    /* The first value will be a unique tag to identify that the diffuse value
    /* is being exported. The second value will be the data size and the third value */
    /* will be the material's diffuse value. */
                
    matdata = #()
    append matdata 3004          /* The POD tag for diffuse */
    append matdata (4 * 3)       /* The size of the diffuse data (3 floats) */
    append matdata mat.diffuse   /* The diffuse data */
                
    /* return our data */
    matdata
)
                
function DefineSceneUserData =
(
    /* Anything returned from this function will be included */
    /* in the SPODScene's user data. */
    /* This is for information that does not belong with a node or a material. */
                
    "Extra global data"
)