Setting up Scenes
The x42maya exporter follows a few simple rules when gathering scene data for export. The first stage of the export is called the gather, during which the exporter gathers the scene data in an unoptimized form. This stage creates many extra bones and geometry groups which are later removed.
Material Names
The x42 format supports both a surface name and an associated default material name. These names are taken from the materials assigned to the scene geometry and the shading groups those materials link to.
The exporter pulls the surface name in from the shading group. It uses the name of the shadingEngine node directly. You can get to this node either through the "Shading Groups" tab in Hypershade, or by selecting the material and clicking the Go to Output Connections button on the Attributes editor (if the shader is collected to multiple outputs you may need to right-click the button and select the link to the shading group from the list).
The default shader name is taken from the material assigned to the geometry. This is the name of the Lambert or Phong (or whatever) material node. You can override this name by adding a custom attribute called shaderName to the material node. To add this attribute, select the material through Hypershade and bring up the attributes editor. Select Add Attribute under the attribute editor's Attributes menu. Set the name to shaderName, the type to String, and uncheck Make attribute keyable. The new attribute will show up under Extra Attributes in the attribute editor. Set it to the name of the game shader you want to use (like textures/my_texture_name.tga). Note that the material node must be selected directly, selecting geometry that uses the material and switching to the material attributes tab won't work - the attribute will be created on the geometry object.
There is also one special case to keep in mind. Geometry with lambert1 assigned will not be exported by the plugin. You can use this to your advantage since it allows you to exclude entire objects or even individual faces from the exported file. Just remember to assign a different material to anything you do want exported.
Exported material names may also be overridden in an export script.
LODs
LOD numbers are assigned to any imported geometry based on the name of the source mesh (as opposed to the transforms it is bound to). If a mesh's name ends in an underscore followed by a number, that number is taken to the the LOD number. If this suffix is not present the LOD number is assumed to be zero.
Root Transform
The exporter supports the notion of a root transformation, which is essentially a constant-valued bone that gets inserted at the root of the skeletal hierarchy. Root transform values are specified by the export script.
Skinned Geometry
Whenever the exporter encounters a renderable mesh, it searches upstream in the DAG for a skinCluster node. If it finds one directly connected to the render mesh's inMesh attribute, it considers the mesh to be skinned geometry. The base pose is pulled from the skinCluster's inputGeometry plug - it does not search further up through the DAG history (and thus ignores any Maya animation that occurs upstream of the skinCluster).
Influence information is pulled in from the skinCluster and stored on the vertices. The x42 format supports a maximum of four influences per vertex, so the exporter keeps only the four strongest influences. Note that the export script may further restrict the maximum number of influences, and it may also instruct the exporter to discard influences smaller than a given weight value.
Normally the exporter will stop searching for a skinCluster node if it doesn't find one directly attached to the rendered mesh node. This behavior can be overridden by the export script, which can instruct the exporter to follow the links through a given set of DG nodes. Enabling this behavior is dangerous, however, as the exporter will crash if the mesh has been edited significantly between the skinCluster and the renderable mesh node.
Rigid Geometry
Any unskinned geometry is consisered rigidly skinned. Its transform is turned into a bone and the geometry's vertices are weighted entirely to this bone.
Tags
Any transform-type node can be made a tag by use of a custom attribute. To turn a transform into a bone, add a string-type custom attribute to it called treat_as_tag and set its value to the name of the tag. The transform node will be converted into a bone, and a tag with an identity matrix will be attached to it.
Since it can be difficult to figure out the orientation of a Maya transform, a sample tag object is included in the test-scenes folder of the maya2q3 repository (right under trunk). To quickly create a new tag, simply import x42_tag.ma into your scene. You can parent or animate the tag object as you please. The axis you see rendered in Maya will line up with the axis you'll see in x42view.
Camera Tags
This isn't a requirement of the x42 format, but a convention does exist for treating tags as camera mounting points (and x42view knows about this convention). By default the -z axis is considered forward, the +y axis is up, and the +x axis is right. This is chosen to correspond to the way Maya aligns cameras on its transforms, and it makes exporting a Maya camera's mounting info as a tag as easy as adding the treat_as_tag attribute to the camera's transform.
Optimizations
After gathering the input data, the exporter performs a number of optimizations. Some are at the direction of an export script, others are built in.
Extra Influences
The export script may cause the exporter to limit the maximum number of influences on a geometry patch, or to discard influences who's weight is below a given threshold. These actions can easily create orphaned influences that don't actually attach to anything. Any such influences are deleted from the model.
Duplicate Influences
Influences are often duplicated (usually when binding multiple objects with the same model space transform to the same bone, as happens when binding multiple LODs to the same skeleton). Any influences that are equal to within a given threshold are collapsed into a single influence and deleted.
Unused Bones
If deleting influences in the prior steps leaves a bone with no children, no bound tags, and no bound geometry that bone is deleted. If deleting these bones leaves more childless bones with no attached influences or tags those two are deleted. This is repeated until all remaining bones have a child, an attached influence, or an attached tag.
Constant Bone Collapse
Any bones that don't actually have animation info on them are collapsed into their children and removed. This includes leaf bones, which are collapsed into the tags and influences that are bound to them. It is possible for a entire sub-heirarchies to vanish this way, leaving tags and influences bound directly to the overall model transform.
Animation Track Cleanup
Animation tracks that lack high frequency informations are always simplified. Constant tracks usually bake into a single constant value.
Group Splits
Geometry groups are split by the number of influences on each triangle, leaving low-cost geometry separate from high-cost geometry. If this creates any unreasonably small groups, they are merged into the next most expensive group.
Mesh Optimization
Triangle indices, and the mesh's vertex order are fixed up to make better use of GPU vertex caches. The optimization values are tuned to older GPUs, but they're fine for more modern hardware as well (certainly much better than the random order that comes out of Maya).
