Giter VIP home page Giter VIP logo

Comments (3)

Squareys avatar Squareys commented on May 21, 2024

Updated version:

    std::optional<Trade::MeshData3D> meshData = ...;

    if(!meshData || meshData->primitive() != MeshPrimitive::Triangles) {
        Error() << "Cannot load collision mesh, skipping";
        return;
    }

    /* this is a collision mesh, convert to bullet mesh */
    btIndexedMesh bulletMesh;
    bulletMesh.m_numTriangles = meshData->indices().size()/3;
    bulletMesh.m_triangleIndexBase = reinterpret_cast<const unsigned char *>(meshData->indices().data());
    bulletMesh.m_triangleIndexStride = 3 * sizeof(UnsignedInt);
    bulletMesh.m_numVertices = meshData->positions(0).size();
    bulletMesh.m_vertexBase = reinterpret_cast<const unsigned char *>(meshData->positions(0).data());
    bulletMesh.m_vertexStride = sizeof(Vector3);
    bulletMesh.m_indexType = PHY_INTEGER;
    bulletMesh.m_vertexType = PHY_FLOAT;

The btIndexedMesh can then further be used as follows:

    btCollisionShape* shape = nullptr;
    auto tivArray = new btTriangleIndexVertexArray());
    tivArray->addIndexedMesh(bulletMesh, PHY_INTEGER);
    if(shapeType == "TriangleMeshShape") {
        /* exact shape, but worse performance */
        shape = new btBvhTriangleMeshShape(tivArray, true);
    } else {
        /* convex hull, but better performance */
        shape = new btConvexTriangleMeshShape(tivArray, true);
    } /* btConvexHullShape can be even more performant */

PS: also CC0, in case anybody cares.

from magnum-integration.

Squareys avatar Squareys commented on May 21, 2024

Will a free function in BulletIntegration namespace suffice?

from magnum-integration.

mosra avatar mosra commented on May 21, 2024

Yup, why not? :)

from magnum-integration.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.