SpeedTree
    Show / Hide Table of Contents

    Games exporting

    Once a model is loaded using StpLoadSpeedTreeFile(), it can be exported to any mesh format supported by the SpeedTree Modeler with a single function call. The supported games formats are:

    • SpeedTree Runtime SDK format (.stsdk)
    • SpeedTree 8 format (.st)
    • SpeedTree 9 format (.st9)
    • Crytek geometry format (.cgf)
    • FBX/Filmbox (.fbx)
    • Wavefront (.obj)
    • All-data XML (.xml)
    • Universal Scene Description (.usd)

    The structure StpGamesExportOptions encapsulates all available export options and is closely related to the .ini export files supported by the Modeler CLI (command-line interface) export system.

    Because the SpeedTree Pipeline SDK API is in C instead of C++, developers should call StpInitGamesExportOptions() to initialize their StpGamesExportOptions objects. The default values it sets are documented here.

    The following example shows how to load an .spm file and export it as a .usd file.

    C++ example

    ///////////////////////////////////////////////////////////////////////
    //  SpeedTree Pipeline SDK error callback
    
    static void MyErrorCallback(const char* error)
    {
        fprintf(stderr, "    **[Error Report from SpeedTree Pipeline SDK]**: %s\n", error);
    }
    
    
    ///////////////////////////////////////////////////////////////////////
    //  SpeedTree Pipeline SDK message callback
    
    static void MyMessageCallback(const char* message)
    {
        fprintf(stderr, "    [Message from SpeedTree Pipeline SDK]: %s\n", message);
    }
    
    ///////////////////////////////////////////////////////////////////////
    //  Example_GamesExport
    //
    //    Parameters:
    //
    //      - modelFilename: should be an SpeedTree .spm file.
    //
    //        - exportFilename: the extension will dictate which format will be
    //          exported (e.g. .usd for USD files, .obj for Wavefront OBJ). The
    //        exporter will not create any new folders in the output path, so
    //          please make sure the path already exists prior to calling.
    
    bool Example_GamesExport(const char* modelFilename, const char* exportFilename)
    {
        bool success = false;
    
        // register callback message functions; when api calls fail, messages will be
        // sent here
        StpSetErrorFunction(MyErrorCallback);
        StpSetMessageFunction(MyMessageCallback);
    
        // the exporting process can be lengthy, taking a minute or more, so the
        // progress callback system will help keep the caller updated
        StpSetProgressFunction(MyProgressCallback);
    
        // create a speedtree engine context
        StpContext* context = StpNew( );
        if (context)
        {
            // load the compact speedtree procedural file from disk
            if (StpLoadSpeedTreeFile(context, modelFilename, NULL))
            {
                // the vfx export system has specific options
                StpGamesExportOptions exportOptions;
    
                // let the export system set defaults for lengthy options list
                StpInitGamesExportOptions(&exportOptions);
    
                // express specific, non-default output preferences
                exportOptions.textureBillboardResolution = 2048; // good-sized billboard
                exportOptions.textureMaxResolution = 1024; // cap texture size
    
                // if exporting a .stsdk file, we need to set the packers; note
                // that packer names do not have paths or extensions here
                strcpy(exportOptions.sdkVertexPacking, "Standard");
                strcpy(exportOptions.sdkBillboardVertexPacking, "Standard_Billboard");
                strcpy(exportOptions.texturePacking, "_Standard");
    
                // make sure the export folder exists
                SpeedTree::CreateFolder(SpeedTree::FilenamePathOnly(exportFilename).c_str( ));
    
                // this is the call that causes the system to execute and it can be
                // lengthy; it's the equivalent of pressing "Export" on the Modeler's
                // export dialog.
                //
                // note that this system will not create output paths in pOutputFilename,
                // so be sure those paths already exist
                success = StpExportForGames(context, exportFilename, &exportOptions);
            }
    
            // operation complete, clean up
            StpDelete(context);
        }
    
        return success;
    }
    

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • C++ example
    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.