コード例 #1
0
void ConvexData::BuildHull(const PODVector<Vector3>& vertices)
{
    if (vertices.Size())
    {
        // Build the convex hull from the raw geometry
        StanHull::HullDesc desc;
        desc.SetHullFlag(StanHull::QF_TRIANGLES);
        desc.mVcount = vertices.Size();
        desc.mVertices = vertices[0].Data();
        desc.mVertexStride = 3 * sizeof(float);
        desc.mSkinWidth = 0.0f;

        StanHull::HullLibrary lib;
        StanHull::HullResult result;
        lib.CreateConvexHull(desc, result);

        vertexCount_ = result.mNumOutputVertices;
        vertexData_ = new Vector3[vertexCount_];

        indexCount_ = result.mNumIndices;
        indexData_ = new unsigned[indexCount_];

        // Copy vertex data & index data
        memcpy(vertexData_.Get(), result.mOutputVertices, vertexCount_ * sizeof(Vector3));
        memcpy(indexData_.Get(), result.mIndices, indexCount_ * sizeof(unsigned));

        lib.ReleaseResult(result);
    }
    else
    {
        vertexCount_ = 0;
        indexCount_ = 0;
    }
}
コード例 #2
0
ファイル: CollisionShapeUtils.cpp プロジェクト: Pouique/naali
void GenerateConvexHullSet(Ogre::Mesh* mesh, ConvexHullSet* ptr)
{
    std::vector<float3> vertices;
    GetTrianglesFromMesh(mesh, vertices);
    if (!vertices.size())
    {
        LogError("Mesh had no triangles; aborting convex hull generation");
        return;
    }
    
    StanHull::HullDesc desc;
    desc.SetHullFlag(StanHull::QF_TRIANGLES);
    desc.mVcount = (uint)vertices.size();
    desc.mVertices = &vertices[0].x;
    desc.mVertexStride = sizeof(float3);
    desc.mSkinWidth = 0.01f; // Hardcoded skin width
    
    StanHull::HullLibrary lib;
    StanHull::HullResult result;
    lib.CreateConvexHull(desc, result);

    if (!result.mNumOutputVertices)
    {
        LogError("No vertices were generated; aborting convex hull generation");
        return;
    }
    
    ConvexHull hull;
    hull.position_ = float3(0,0,0);
    /// \todo StanHull always produces only 1 hull. Therefore using a hull set is unnecessary and could be optimized away
#include "DisableMemoryLeakCheck.h"
    hull.hull_ = shared_ptr<btConvexHullShape>(new btConvexHullShape((const btScalar*)&result.mOutputVertices[0], result.mNumOutputVertices, 3 * sizeof(float)));
#include "EnableMemoryLeakCheck.h"
    ptr->hulls_.push_back(hull);
    
    lib.ReleaseResult(result);
}