SpeedTree
    Show / Hide Table of Contents

    Mesh packing for static meshes

    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
    • Get the list of all input data and SpeedTree specific functions available to write the script.
    • Look at the Default.lua script provided by default in the <app install>/mesh_packing folder.

    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_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.
    print <string> Output information to the SpeedTree Modeler Console. Use it for debugging, but carefully, since it prints for every vertex.

    Additional resources

    • Games export options
    • Lua scripting reference manuals
    Copyright © 2023 Unity Technologies
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX.