Box3D 0.1.0
A 3D physics engine for games
Loading...
Searching...
No Matches

Triangle mesh collision shape. More...

Collaboration diagram for Triangle Mesh:

Data Structures

struct  b3MeshDef
 This is used to create a re-usable collision mesh. More...
struct  b3MeshTriangle
 A mesh triangle. More...
struct  b3MeshNode
 A mesh BVH node. More...
struct  b3MeshData
 This is a sorted triangle collision bounding volume hierarchy. More...
struct  b3Mesh
 This allows mesh data to be re-used with different scales. More...
union  b3MeshNode.data
 Anonymous union. More...
struct  b3MeshNode.data.asNode
 Internal node. More...
struct  b3MeshNode.data.asLeaf
 Leaf node. More...

Macros

#define B3_MESH_VERSION   0xABD11AB62A6E886Dull
 64-bit mesh version. Useful for validating serialized data.

Enumerations

enum  b3MeshEdgeFlags {
  b3_concaveEdge1 = 0x01 , b3_concaveEdge2 = 0x02 , b3_concaveEdge3 = 0x04 , b3_inverseConcaveEdge1 = 0x10 ,
  b3_inverseConcaveEdge2 = 0x20 , b3_inverseConcaveEdge3 = 0x40 , b3_allConcaveEdges = b3_concaveEdge1 | b3_concaveEdge2 | b3_concaveEdge3 , b3_flatEdge1 = b3_concaveEdge1 | b3_inverseConcaveEdge1 ,
  b3_flatEdge2 = b3_concaveEdge2 | b3_inverseConcaveEdge2 , b3_flatEdge3 = b3_concaveEdge3 | b3_inverseConcaveEdge3 , b3_allFlatEdges = b3_flatEdge1 | b3_flatEdge2 | b3_flatEdge3
}
 Triangle mesh edge flags.

Functions

const b3MeshNodeb3GetMeshNodes (const b3MeshData *mesh)
 Get read only mesh BVH nodes.
const b3Vec3b3GetMeshVertices (const b3MeshData *mesh)
 Get read only mesh vertices.
const b3MeshTriangleb3GetMeshTriangles (const b3MeshData *mesh)
 Get read only mesh triangles.
const uint8_t * b3GetMeshMaterialIndices (const b3MeshData *mesh)
 Get read only mesh materials. The count is equal to the triangle count.
const uint8_t * b3GetMeshFlags (const b3MeshData *mesh)
 Get read only mesh flags. The count is equal to the triangle count.
b3MeshDatab3CreateGridMesh (int xCount, int zCount, float cellWidth, int materialCount, bool identifyEdges)
 Create a grid mesh along the x and z axes.
b3MeshDatab3CreateWaveMesh (int xCount, int zCount, float cellWidth, float amplitude, float rowFrequency, float columnFrequency)
 Create a wave mesh along the x and z axes.
b3MeshDatab3CreateTorusMesh (int radialResolution, int tubularResolution, float radius, float thickness)
 Create a torus mesh.
b3MeshDatab3CreateBoxMesh (b3Vec3 center, b3Vec3 extent, bool identifyEdges)
 Create a box mesh.
b3MeshDatab3CreateHollowBoxMesh (b3Vec3 center, b3Vec3 extent)
 Create a hollow box mesh.
b3MeshDatab3CreatePlatformMesh (b3Vec3 center, float height, float topWidth, float bottomWidth)
 Create a platform mesh. A truncated pyramid.
b3MeshDatab3CreateMesh (const b3MeshDef *def, int *degenerateTriangleIndices, int degenerateCapacity)
 Create a generic mesh.
void b3DestroyMesh (b3MeshData *mesh)
 Destroy a mesh.
int b3GetHeight (const b3MeshData *mesh)
 Get the height of the mesh BVH.

Detailed Description

Triangle mesh collision shape.


Data Structure Documentation

◆ b3MeshDef

struct b3MeshDef

This is used to create a re-usable collision mesh.

Collaboration diagram for b3MeshDef:
Data Fields
bool identifyEdges Compute triangle adjacency information using shared edges.
int32_t * indices Triangle vertex indices. 3 for each triangle.
uint8_t * materialIndices Triangle material index.

1 per triangle. Indexes into b3ShapeDef::materials. This allows different run-time material data to be associated with different instances of this mesh.

int triangleCount The triangle count. Must be 1 or more.
bool useMedianSplit Use the median split instead of SAH to speed up mesh creation.

Good for meshes that are structured like a grid.

int vertexCount The vertex count. Must be 3 or more.
b3Vec3 * vertices Triangle vertices.
float weldTolerance Tolerance for vertex welding in length units.
bool weldVertices Optionally weld nearby vertices.

◆ b3MeshTriangle

struct b3MeshTriangle

A mesh triangle.

Data Fields
int32_t index1 Index of vertex 1.
int32_t index2 Index of vertex 2.
int32_t index3 Index of vertex 3.

◆ b3MeshData

struct b3MeshData

This is a sorted triangle collision bounding volume hierarchy.

Note
This struct has data hanging off the end and cannot be directly copied.
Collaboration diagram for b3MeshData:
Data Fields
b3AABB bounds Local axis-aligned box.
int byteCount The total number of bytes for this mesh.
int degenerateCount The number of degenerate triangles. Diagnostic.
int flagsOffset Offset of the triangle flag array in bytes from the struct address.
uint32_t hash Hash of this mesh (this field is zero when the hash is computed).
int materialCount The number of materials.
int materialOffset Offset of the material array in bytes from the struct address.
int nodeCount The number of BVH nodes.
int nodeOffset Offset of the node array in bytes from the struct address.
float surfaceArea Combined surface area of all triangles. Single-sided.
int treeHeight The height of the bounding volume hierarchy.
int triangleCount The number of triangles.
int triangleOffset Offset of the triangle array in bytes from the struct address.
uint64_t version Version must be first.
int vertexCount The number of vertices.
int vertexOffset Offset of the vertex array in bytes from the struct address.

◆ b3Mesh

struct b3Mesh

This allows mesh data to be re-used with different scales.

Collaboration diagram for b3Mesh:
Data Fields
const b3MeshData * data Immutable pointer to the mesh data.
b3Vec3 scale This scale may be non-uniform and have negative components.

However, no component may be very small in magnitude.

◆ b3MeshNode.data.asNode

struct b3MeshNode.data.asNode

Internal node.

Data Fields
uint32_t axis: 2 Split axis. 0, 1, or 2.
uint32_t childOffset: 30 Offset of the second child node.

◆ b3MeshNode.data.asLeaf

struct b3MeshNode.data.asLeaf

Leaf node.

Data Fields
uint32_t triangleCount: 30 The number of triangles for this leaf node.
uint32_t type: 2 Aligned with axis above and has value of 3 if this is a leaf.

Function Documentation

◆ b3CreateGridMesh()

b3MeshData * b3CreateGridMesh ( int xCount,
int zCount,
float cellWidth,
int materialCount,
bool identifyEdges )

Create a grid mesh along the x and z axes.

Parameters
xCountthe number of rows in the x direction
zCountthe number of rows in the z direction
cellWidththe width of each cell
materialCountthe number of materials to generate
identifyEdgescompute adjacency information