SpeedTree
    Show / Hide Table of Contents

    Collision objects

    SpeedTree uses capsules as collision objects, providing a cruder representation of a tree object's shape than its detailed geometry. They have no polygonal resolution associated with them. Rather, they are mathematical representations, free to be passed into the collision-handling system in your application.

    Capsules with the same two position values are treated as spheres.

    The following code shows how to access the collision objects embedded in a CCore object, assuming it has been loaded.

    #include "SpeedTree/Core/Core.h"
    using SpeedTree::st_uint32;
    
    void PrintCollisionObjects(const SpeedTree::CCore& cModel)
    {
        st_uint32 uiNumObjects = cModel.CollisionObjects( ).Count( );
        for (st_uint32 i = 0; i < uiNumObjects; ++i)
        {
            SpeedTree::CCollisionObject cObject = cModel.CollisionObjects( )[i];
    
            printf("collision object [%d of %d]\n", i + 1, uiNumObjects);
    
            // each collision object has two position values; when they're identical,
            // the object is a sphere; when diferent, it's a capsule
            SpeedTree::Vec3 vPos1 = cObject.Position( );
            SpeedTree::Vec3 vPos2 = cObject.Position2( );
    
            if (vPos1 == vPos2)
                printf("  [Sphere]\n");
            else
                printf("  [Capsule]\n");
    
            printf("  position 1: (%g, %g, %g)\n", vPos1.x, vPos1.y, vPos1.z);
            printf("  position 2: (%g, %g, %g)\n", vPos2.x, vPos2.y, vPos2.z);
            printf("  radius: %g\n", cObject.Radius( ));
    
            // note the necessary (const char*) typecast
            printf("  user data: [%s]\n", (const char*)cObject.UserData( ).Data( ));
        }
    }
    

    The CForest object (in the Forest library) has a function, CForest::CollisionAdjust(), that will provide the functionality necessary to avoid running through a series of tree models. It works only within the SpeedTree framework but could serve as a useful start for your own application.

    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.