melonJS
    Preparing search index...

    Class TriangleMesh3d

    A collision shape made of a mesh's own triangles, exact to the surface: the shape for static level geometry, such as terrain, a ramp or a room loaded from glTF, that a character walks on and objects land on.

    It is hollow, a skin of triangles with no inside, so it suits bodies that do not move. A moving body is better given a ConvexHull3d, or a few Box3d, Sphere and Capsule3d shapes.

    Its vertices are in the body's space, relative to the renderable's pos, in the engine's 3D convention (Y-down, +Z forward). TriangleMesh3d.fromMesh builds one from a Mesh as it is drawn, a glTF part included.

    A 3D physics adapter (@melonjs/rapier3d-adapter) builds it exactly. The built-in physics approximates it by its bounding Box3d, and the 2D adapters refuse it.

    // a loaded level's ground, which the player walks on
    const ground = app.world.getChildByName("ground")[0];
    ground.bodyDef = { type: "static", shapes: [TriangleMesh3d.fromMesh(ground)] };
    Index
    • Parameters

      • vertices: ArrayLike<number>

        the vertices, [x, y, z, ...]

      • Optionalindices: ArrayLike<number>

        three vertex indices per triangle; consecutive triples of vertices when omitted

      Returns TriangleMesh3d

      when there is not a whole number of vertices, or an index names a vertex that is not there

    collisionMask?: number
    collisionType?: number

    Optional per-shape collision settings (see Body#addShape).

    indices: Uint32Array

    three vertex indices per triangle

    isActive?: boolean

    false takes this shape out of collision without removing it

    isTrigger?: boolean

    true reports contacts but skips the position correction

    an offset from the owning body's position, added to every vertex

    type: string = "TriangleMesh3d"

    the shape type (used internally)

    "TriangleMesh3d"
    
    vertices: Float32Array

    the vertices, [x, y, z, ...], relative to pos