The Export Script

The x42 exporter uses an export script to guide the export process. The script does its work by calling the x42config command (which is only valid during an x42 export). It is first run at the start of the export process, when the exporter sources the script file. The exporter will then call various functions in the script during the export.

The export script must be named the same as the maya file being exported, with .x42.mel appended to the filename.

Script Execution

The script is executed in several phases.

Source

The script is sourced before the export begins the gather phase. This is the preferred spot to set global options like export sections, various file limits, and the root transform.

x42configCB_afterGetGeometry

This function is called after the gather phase has finished. This is a good spot to rename and reparent bones, as well as to clean out unwanted weights as no data has been optimized yet.

x42configCB_afterPruneBones

This function is called after the first round of optimization, when any unused bones and influences have been trimmed away.

x42configCB_afterRecordAnims

This is called after the animation data has been pulled in and simplified, and after constant bones have been collapsed away.

x42configCB_beforeWrite

This is called immediately before the x42 file is written to disk. All optimizations have been applied at this point.

x42config Options

x42config may only be run during the export process (it will throw an error at any other time). It accepts zero or more general flags, and exactly one command flag.

Bone Names

All commands that take a bone name can take it in one of two forms:

Model Bone Names

A regular string is interpreted as a model bone name. This is the name of the bone as it will be exported. It defaults to the name of the transform node that it was created from, but if it has been subsequently renamed that name is used.

Qualified Maya Name

If the string starts with a '~', then the remainder of the string is taken to be the name of the Maya node that the bone was created from. This string must be such that selecting with it would yield the selection of exactly one node.

General Flags

General flags apply for the duration of the command. Their effects are tangential to the way commands operate (except -q and -e).

succeed, s

This forces the command to return a success value, whether it actually succeeded or not.

verbose, v

This causes the command to print extra diagnostic info.

q, e

Commands that deal with global export values can be queried with the standard query-mode flag (-q). Some of these require the standard edit mode flag (-e) to be set. This will be noted on each relevant command.

mayaName, mn

This is valid on any command that returns the name of a scene object. It forces the exporter to return an unambiguous Maya object name (the sort you could select with) instead of the name the exporter will save to the file (these are not always the same).

Command Flags

kill, k

Args: message:string

This command prints message and terminates the export process.

enableAdditionalErrors, eae

Queryable, Args: enable:bool

This command sets the default verbosity value for future commands.

pinFrame, pf

Args: frame:time

This command marks a frame as being critical, subjecting it to much stricter tolerances when cleaning animation values.

setSaveSections, sss

Queryable, Args: normals:bool tangents:bool texcoords:bool colors:bool

This command tells the exporter which of the optional data sections should be saved in the x42 file.

outputTriStrips, ots

Queryable, Args: enable:bool

This command causes the exporter to prefer triangle strips to triangle lists when exporting geometry.

forceUniformScale, fus

Queryable, Args: enable:bool

This command sets whether all animation scale values should be forced to be uniform or not.

maxBonesPerGroup, mbg

Queryable, Args: maxbones:uint

This command sets the maximum number of bones to export per group. The minimum value is 12, the maximum is 60. The default is 30.

transformModelTranslate, tmt

Edit, Args: x:float y:float z:float

Sets the root transform translate value.

transformModelRotate, tmr

Edit, Args: x:float y:float z:float theta:float

Sets the root transform rotation value (axis-angle input format).

transformModelScale, tms

Edit, Args: x:float y:float z:float

Sets the root transform scale value.

cleanWeightsByCount, cwc

Edit, Args: maxweights:uint

Limits the maximum number of weights per vertex across all gathered data. Additional weights are discarded (starting with the weakest), and the remaining weight values are renormalized. maxweights must be between one and four, inclusive.

cleanWeightsByValue, cwv

Edit, Args: minweight:float

Limits the minimum weight of each influence on all vertices across all gathered data. Any weight weaker than minweight is discarded and remaining weight values are renormalized. This function will never discard the strongest weight on a vertex, guaranteeing that at least one per vertex will remain.

swapShader, sws

Args: oldname:string newname:string

This command replaces all shader references equal to oldname with newname.

setDefaultTolerances, sdt

Queryable, Args: scale:float rotation:float translation:float

This command sets the default tolerances used to decide whether animation track elements may be removed.

setBoneTolerances, sbt

Edit, Args: bone:string scale:float rotation:float translation:float

This command overrides the animation simplification tolerances for a particular bone.

renameBone, rnb

Edit, Args: oldname:string newname:string

This command renames a bone. This should only be called in the x42configCB_afterGetGeometry function.

reparentBone, rpb

Edit, Args: bone:string newparent:string

This command reparents a given bone. This should only be called in the x42configCB_afterGetGeometry function.

setAnimGroup, sag

Edit, Args: bone:string newgroup:uint

This command sets the animation of a bone and all of its children. The animation group value must be greater than or equal to the bone's parent's animation group value.

printStats, ps

Prints miscellaneous information about the model.

printBoneTree, pbt

Prints the bone hierarchy.