Mesh packing for static meshes
Customize how vertex data is packed into FBX and USD static mesh exports using a custom Lua script.
Read time 3 minutesLast updated 2 hours ago
Customize data packing for static mesh export to FBX and USD formats, using the Mesh packing feature.
Overall process
To define and apply custom data packing to FBX or USD export:
-
Write a packing script in Lua language and save the file in thefolder.
<app install>/mesh_packing -
In Game export options, under the Format-specific section, select the Mesh packing option that corresponds to your custom packer.
Packing script (in Lua)
This script packs the model input data into the vertices of the exported file. During export, the Modeler runs the script for each vertex.
Script language and capabilities
You have to write the packing script in Lua language. For more information and examples about this language, refer to www.lua.org and Lua Tutorials.
The base purpose of the script is to get data from the model and pack it to the exported mesh, but you can also use any built-in Lua functions to pre-process and transform that data before packing it, if you need to. An additional function is also available to print information for debug.
Vertex data packing
The input data available to use in the script covers all of the data available for a vertex.
To place any of that data into the final vertex attributes in the export file, use the and functions, depending on the type of data you need to pack.
set_colorset_uvYou can use these same functions multiple times with different names to define as many color or uv parameters you need to pack data into the target mesh. After export, if you import the mesh to another 3D modeling software, these names are interpreted as colorset and uvset names.
You might also use the , , and functions if you need to set the corresponding properties in the target mesh.
set_normalset_binormalset_tangentReference
Available input data
List of all vertex data available as input for data packing customization.
Variable | Type/format | Description |
|---|---|---|
| in_anchor | 3 float array | Anchor position for node. |
| in_offset | 3 float array | Offset from anchor. |
| in_lod_offset | 3 float array | LOD offset from anchor. |
| in_texcoord | 2 float array | Main UV. |
| in_lightmap_texcoord | 2 float array | Lightmap UV, if available. |
| in_normal | 3 float array | Vertex normal. |
| in_binormal | 3 float array | Vertex binormal. |
| in_tangent | 3 float array | Vertex tangent. |
| in_vertex_color | 3 float array | Vertex color. |
| in_vertex_alpha | float | Vertex blend value. |
| in_ambient_occlusion | float | Ambient occlusion value. |
| in_wind_branch1_position | 3 float array | Branch tip position for level-1 branch in wind. |
| in_wind_branch1_origin | 3 float array | Pivot point position for level-1 branch in wind. |
| in_wind_branch1_direction | 3 float array | Growth direction for level-1 branch in wind. |
| in_wind_branch1_weight | float | Weight/amount for level-1 branch wind motion. |
| in_wind_branch2_position | 3 float array | Branch tip position for level-2 branch in wind. |
| in_wind_branch2_origin | 3 float array | Pivot point position for level-2 branch in wind. |
| in_wind_branch2_direction | 3 float array | Growth direction for level-2 branch in wind. |
| in_wind_branch2_weight | float | Weight/amount for level-2 branch wind motion. |
| in_wind_ripple | float | Wind ripple scalar. |
| in_bone_id | integer | ID of the bone attached to this vertex. |
| in_two_sided | boolean | Represents the two-sided flag on the material used on this vertex. |
| in_geometry_type | integer | Geometry type: Branch=0, Frond, Leaf, FacingLeaf, Billboard. |
| in_original_geometry_type | integer | Original geometry type before batching: Branch=0, SubDivBranch, Cap, Frond, Leaf, FacingLeaf, Mesh. |
| in_tree_extents | 6 float array | Tree extents: min xyz, max xyz. |
Available functions
List of all SpeedTree specific functions you can call in the script in addition to built-in Lua calls.
Function | Parameters | Description |
|---|---|---|
| set_color | name, r, g, b | Specify a name for a vertex color attribute and save any 3-value data to it. |
| set_uv | name, u, v | Specify a name for a vertex UV attribute and save any 2-value data to it. |
| set_position | x, y, z | Specify the vertex position coordinates. |
| set_normal | x, y, z | Specify the vertex normal vector coordinates. |
| set_binormal | x, y, z | Specify the vertex binormal vector coordinates. |
| set_tangent | x, y, z | Specify the vertex tangent vector coordinates. |
| <string> | Output information to the SpeedTree Modeler Console. Use it for debugging, but carefully, since it prints for every vertex. |