b3dGetTerrainTriangleCount

Returns the current triangle count for the terrain's active LOD level. Takes entity (terrain entity handle), camera (camera entity handle). Returns triangle count (number of triangles being rendered for the current LOD level).

3D Graphics

Parameters & Returns

Parameters

entity Int
camera Int

Returns

Int

Quick Summary

Returns the current triangle count for the terrain's active LOD level. Takes entity (terrain entity handle), camera (camera entity handle). Returns triangle count (number of triangles being rendered for the current LOD level).

Technical Exegesis...

Returns the current triangle count for the terrain's active LOD level based on camera distance. Takes entity (terrain entity handle), camera (camera entity handle). Returns triangle count (number of triangles being rendered for the current LOD level), or 0 if invalid handles.

Uses the same LOD selection logic as the renderer: calculates distance from camera to terrain corner position, selects appropriate LOD level based on terrain.lodDistances thresholds, and returns indexCount / 3 for that LOD level.

Example

Example.bam
; Create terrain and camera
Local terrain:Int = b3dCreateTerrain("heightmap.bmp", 128)
Local camera:Int = b3dCreateCamera()
b3dPositionEntity(camera, 0, 100, -500)

; Configure LOD thresholds
b3dSetTerrainLOD(terrain, 0, 1000, 2000, 3000)

; Game loop - display triangle count
While running
    sysUpdateEvents()

    ; Get current triangle count (changes with camera distance)
    Local triangles:Int = b3dGetTerrainTriangleCount(terrain, camera)

    ; Move camera
    If inpIsKeyDown(VKEY_W) Then
        b3dMoveEntity(camera, 0, 0, 10)
    EndIf

    ; Render and display
    b3dCls3D()
    b3dRenderWorld()
    b3dFlip3D()

    ; Show triangle count (updates when LOD changes)
    Print "Terrain triangles: " & ToString(triangles)
Wend