当前位置: 首页>>代码示例>>C++>>正文


C++ AABBTree::Build方法代码示例

本文整理汇总了C++中AABBTree::Build方法的典型用法代码示例。如果您正苦于以下问题:C++ AABBTree::Build方法的具体用法?C++ AABBTree::Build怎么用?C++ AABBTree::Build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AABBTree的用法示例。


在下文中一共展示了AABBTree::Build方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Build

bool HybridModel::Build(const OPCODECREATE& create)
{
    // 1) Checkings
    if(!create.mIMesh || !create.mIMesh->IsValid())	return false;

    // Look for degenerate faces.
    udword NbDegenerate = create.mIMesh->CheckTopology();
    if(NbDegenerate)	OpcodeLog("OPCODE WARNING: found %d degenerate faces in model! Collision might report wrong results!\n", NbDegenerate);
    // We continue nonetheless....

    Release();	// Make sure previous tree has been discarded

    // 1-1) Setup mesh interface automatically
    SetMeshInterface(create.mIMesh);

    bool Status = false;
    AABBTree* LeafTree = null;
    Internal Data;

    // 2) Build a generic AABB Tree.
    mSource = new AABBTree;
    CHECKALLOC(mSource);

    // 2-1) Setup a builder. Our primitives here are triangles from input mesh,
    // so we use an AABBTreeOfTrianglesBuilder.....
    {
        AABBTreeOfTrianglesBuilder TB;
        TB.mIMesh			= create.mIMesh;
        TB.mNbPrimitives	= create.mIMesh->GetNbTriangles();
        TB.mSettings		= create.mSettings;
        TB.mSettings.mLimit	= 16;	// ### Hardcoded, but maybe we could let the user choose 8 / 16 / 32 ...
        if(!mSource->Build(&TB))	goto FreeAndExit;
    }

    // 2-2) Here's the trick : create *another* AABB tree using the leaves of the first one (which are boxes, this time)
    struct Local
    {
        // A callback to count leaf nodes
        static bool CountLeaves(const AABBTreeNode* current, udword depth, void* user_data)
        {
            if(current->IsLeaf())
            {
                Internal* Data = (Internal*)user_data;
                Data->mNbLeaves++;
            }
            return true;
        }

        // A callback to setup leaf nodes in our internal structures
        static bool SetupLeafData(const AABBTreeNode* current, udword depth, void* user_data)
        {
            if(current->IsLeaf())
            {
                Internal* Data = (Internal*)user_data;

                // Get current leaf's box
                Data->mLeaves[Data->mNbLeaves] = *current->GetAABB();

                // Setup leaf data
                udword Index = (size_t(current->GetPrimitives()) - size_t(Data->mBase)) / sizeof(size_t);
                Data->mTriangles[Data->mNbLeaves].SetData(current->GetNbPrimitives(), Index);

                Data->mNbLeaves++;
            }
            return true;
        }
    };

    // Walk the tree & count number of leaves
    Data.mNbLeaves = 0;
    mSource->Walk(Local::CountLeaves, &Data);
    mNbLeaves = Data.mNbLeaves;	// Keep track of it

    // Special case for 1-leaf meshes
    if(mNbLeaves==1)
    {
        mModelCode |= OPC_SINGLE_NODE;
        Status = true;
        goto FreeAndExit;
    }

    // Allocate our structures
    Data.mLeaves = new IceMaths::AABB[Data.mNbLeaves];
    CHECKALLOC(Data.mLeaves);
    mTriangles = new LeafTriangles[Data.mNbLeaves];
    CHECKALLOC(mTriangles);

    // Walk the tree again & setup leaf data
    Data.mTriangles	= mTriangles;
    Data.mBase		= mSource->GetIndices();
    Data.mNbLeaves	= 0;	// Reset for incoming walk
    mSource->Walk(Local::SetupLeafData, &Data);

    // Handle source indices
    {
        bool MustKeepIndices = true;
        if(create.mCanRemap)
        {
            // We try to get rid of source indices (saving more ram!) by reorganizing triangle arrays...
            // Remap can fail when we use callbacks => keep track of indices in that case (it still
//.........这里部分代码省略.........
开发者ID:ak4hige,项目名称:myway3d,代码行数:101,代码来源:OPC_HybridModel.cpp


注:本文中的AABBTree::Build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。