|
entity - mesh entity level - level of detail, from 1 to CountEntityLODs camera (optional) - camera to work it out for; 0 uses the last camera drawn by RenderWorld (default) |
|
Returns how far from a camera one of a mesh's levels of detail takes over. For a hand-made level this is simply the distance you gave AddEntityLOD. A version made by AutoEntityLODs takes over where its difference from the full mesh would look smaller than its tolerance in pixels, so the answer depends on the entity and the camera: doubling the entity's scale or the camera's CameraZoom doubles it, and halving the camera's viewport halves it. Show it in a debug overlay while you tune AutoEntityLODs' tolerance, or use it to set an EntityCullRange beyond the last version. The distance is in world units, measured as the switch measures it: from the camera to the nearest point of the entity's bounding box. When the camera moves away the level switches a little further out than this, and back a little nearer, so a camera resting on the boundary does not flicker; fading between versions starts a little before it. Gotcha: an orthographic camera (CameraProjMode 2) shows things the same size at any distance, so for automatic versions it returns 0 for a version that camera uses at any distance and -1 for one it never uses at its zoom. Called before any RenderWorld without a camera, it assumes a view 1,920 pixels wide at CameraZoom 1. See also: SetEntityLODDistance, AutoEntityLODs, EntityLODLevel, CountEntityLODs, CameraZoom. |
; EntityLODDistance 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
; Zooming in makes things look bigger, so versions take over further away
zoom#=1
While Not KeyDown(1)
; [ / ] zoom out or in
If KeyHit(26) And zoom>1 Then zoom=zoom/2
If KeyHit(27) And zoom<8 Then zoom=zoom*2
CameraZoom camera,zoom
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 [ / ] : zoom Esc: exit"
Text 0,20,"CameraZoom camera,"+zoom
; Where each simpler version takes over, for this camera
For l=1 To CountEntityLODs(rocks(0))
Text 0,20+l*20,"EntityLODDistance(rock,"+l+",camera) = "+EntityLODDistance(rocks(0),l,camera)
Next
Text 0,140,"Triangles drawn: "+TrisRendered()
Flip
Wend
End