Creates physics collision mesh for terrain entity.
Takes entity (terrain entity from b3dLoadMesh or terrain creation function).
Returns physics mesh handle.
3D Graphics
Parameters & Returns
Parameters
entityInt
Returns
Int
Quick Summary
Creates physics collision mesh for terrain entity.
Takes entity (terrain entity from b3dLoadMesh or terrain creation function).
Returns physics mesh handle.
Technical Exegesis...
Creates physics collision mesh for terrain entity. Takes entity (terrain entity handle, typically large mesh representing ground/landscape). Returns physics mesh handle for use with Jolt physics system. Generates triangle mesh collision shape from terrain geometry for accurate ground collision.
Creates physics collision mesh for terrain entity. Takes entity (terrain entity handle, typically large mesh representing ground/landscape). Returns physics mesh handle for use with Jolt physics system. Generates triangle mesh collision shape from terrain geometry for accurate ground collision.
Terrain physics: terrain typically large static mesh (hills, valleys, flat ground representing landscape), requires mesh collider for accurate collision (heightfield or triangle mesh, follows terrain geometry precisely), static body (mass = 0, immovable ground), dynamic objects collide and slide on terrain surface. Triangle mesh: generates collision from terrain vertex/index data (each triangle becomes physics collision triangle, accurate to visual mesh, can be expensive for very high-poly terrain).
Use cases: (1) Outdoor landscape (hills, mountains, valleys with physics), (2) Indoor floors (complex non-flat ground surfaces), (3) Racing tracks (curved roads and ramps), (4) Platform levels (varied height platforms and slopes). Typical workflow: load terrain mesh (terrain = b3dLoadMesh("landscape.glb", 1, 0)), create physics mesh (physicsMesh = b3dCreateTerrainPhysicsMesh(terrain)), create static physics body (b3dCreatePhysicsBody(terrain, 0, 0, ...) with mass=0 for static).
Performance: triangle mesh collision expensive for high-poly (thousands of triangles slow collision detection, use simplified collision mesh if possible, or heightfield for regular grid terrain), static mesh optimization (Jolt optimizes static triangle mesh with BVH, reasonable performance for detailed terrain). Memory: stores all terrain triangles in physics (large memory footprint for detailed terrain, consider LOD or simplified collision mesh).
Validation: returns 0 or -1 if entity invalid, returns physics mesh handle if successful (handle used internally, may not need to store for simple terrain setup). Related: b3dLoadMesh loads terrain visual mesh, b3dCreatePhysicsBody attaches physics to terrain entity (use mass=0 for static terrain), b3dSetPhysicsBodyFriction sets terrain surface friction (affects how objects slide on terrain).
Example
Example.bam
; Load and create physics for terrain
terrain = b3dLoadMesh("landscape.glb", 1, 0)
b3dPositionEntity(terrain, 0, 0, 0)
; Create terrain physics mesh
terrainPhysics = b3dCreateTerrainPhysicsMesh(terrain)
; Create static physics body (mass=0 for immovable terrain)
b3dCreatePhysicsBody(terrain, 0, 0.0, 0, 0, 0)
; Set terrain surface friction
b3dSetPhysicsBodyFriction(terrain, 0.8)
; Now dynamic objects will collide with terrain
box = b3dCreateBox()
b3dPositionEntity(box, 0, 50, 0)
b3dCreatePhysicsBody(box, 1, 10.0, 0, 0, 0) ; Falls onto terrain