Documentation

SpeedTree Modeler

SpeedTree Modeler

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:
  1. Write a packing script in Lua language and save the file in the
    <app install>/mesh_packing
    folder.
  2. 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.
Note
To be able to select your custom mesh packer from the Modeler at export, you must place the script file in the
<app install>/mesh_packing
folder.

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.
Tip

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
set_color
and
set_uv
functions, depending on the type of data you need to pack.
You 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.
Important
In addition to any color or uv property you set up, you always have to pass the vertex position through the script, using the
set_position
function with
in_anchor
and
in_offset
input data­. If you skip this configuration, the Modeler sets all vertices to the origin (0,0,0).
You might also use the
set_normal
,
set_binormal
, and
set_tangent
functions if you need to set the corresponding properties in the target mesh.

Reference

Available input data

List of all vertex data available as input for data packing customization.

Variable

Type/format

Description

in_anchor3 float arrayAnchor position for node.
in_offset3 float arrayOffset from anchor.
in_lod_offset3 float arrayLOD offset from anchor.
in_texcoord2 float arrayMain UV.
in_lightmap_texcoord2 float arrayLightmap UV, if available.
in_normal3 float arrayVertex normal.
in_binormal3 float arrayVertex binormal.
in_tangent3 float arrayVertex tangent.
in_vertex_color3 float arrayVertex color.
in_vertex_alphafloatVertex blend value.
in_ambient_occlusionfloatAmbient occlusion value.
in_wind_branch1_position3 float arrayBranch tip position for level-1 branch in wind.
in_wind_branch1_origin3 float arrayPivot point position for level-1 branch in wind.
in_wind_branch1_direction3 float arrayGrowth direction for level-1 branch in wind.
in_wind_branch1_weightfloatWeight/amount for level-1 branch wind motion.
in_wind_branch2_position3 float arrayBranch tip position for level-2 branch in wind.
in_wind_branch2_origin3 float arrayPivot point position for level-2 branch in wind.
in_wind_branch2_direction3 float arrayGrowth direction for level-2 branch in wind.
in_wind_branch2_weightfloatWeight/amount for level-2 branch wind motion.
in_wind_ripplefloatWind ripple scalar.
in_bone_idintegerID of the bone attached to this vertex.
in_two_sidedbooleanRepresents the two-sided flag on the material used on this vertex.
in_geometry_typeintegerGeometry type: Branch=0, Frond, Leaf, FacingLeaf, Billboard.
in_original_geometry_typeintegerOriginal geometry type before batching: Branch=0, SubDivBranch, Cap, Frond, Leaf, FacingLeaf, Mesh.
in_tree_extents6 float arrayTree 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_colorname, r, g, bSpecify a name for a vertex color attribute and save any 3-value data to it.
set_uvname, u, vSpecify a name for a vertex UV attribute and save any 2-value data to it.
set_positionx, y, zSpecify the vertex position coordinates.
set_normalx, y, zSpecify the vertex normal vector coordinates.
set_binormalx, y, zSpecify the vertex binormal vector coordinates.
set_tangentx, y, zSpecify the vertex tangent vector coordinates.
print<string>Output information to the SpeedTree Modeler Console. Use it for debugging, but carefully, since it prints for every vertex.

Additional resources