CountEntityLODs ( entity )

Parameters

entity - mesh entity

Description

Returns how many levels of detail a mesh has.

It counts hand-made levels added with AddEntityLOD and the versions AutoEntityLODs made alike. 0 means the mesh is always drawn at full detail, for example because AutoEntityLODs found it had too few triangles to gain anything. The levels are numbered from 1; in EntityLODTriangles and EntityLODLevel, level 0 is the full mesh.

Use it to loop over the levels in a debug overlay, or to check that AutoEntityLODs found something worth doing before you rely on it.

See also: AutoEntityLODs, EntityLODTriangles, EntityLODDistance, AddEntityLOD, ClearEntityLODs.

Example

; CountEntityLODs Example
; -----------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,2,-6

light=CreateLight()
RotateEntity light,45,45,0

; A detailed boulder: 6,240 triangles
rock=CreateSphere(40)
ScaleMesh rock,1.2,0.8,1
EntityColor rock,150,140,120

; A row of boulders running into the distance
Dim rocks(9)
For n=0 To 9
    rocks(n)=CopyEntity(rock)
    PositionEntity rocks(n),(n Mod 2)*4-2,0,4+n*6
    AutoEntityLODs rocks(n)
Next
HideEntity rock

; 0 lets AutoEntityLODs decide how many versions to make
levels=0

While Not KeyDown(1)

    ; [ / ] ask for fewer or more versions
    asked=levels
    If KeyHit(26) And levels>0 Then levels=levels-1
    If KeyHit(27) And levels<4 Then levels=levels+1
    If levels<>asked
        For n=0 To 9
            AutoEntityLODs rocks(n),1,levels
        Next
    EndIf

    For n=0 To 9
        TurnEntity rocks(n),0,0.2,0
    Next

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrow keys: move camera   [ / ] : versions asked for   Esc: exit"
    Text 0,20,"Asked for "+levels+" (0 = let it decide)"
    Text 0,40,"CountEntityLODs(rock) = "+CountEntityLODs(rocks(0))
    Text 0,60,"Triangles drawn: "+TrisRendered()

    Flip

Wend

End

Index