AddEntityLOD entity,lod_mesh,distance#
Parameters
|
entity - static mesh entity that gains a level of detail lod_mesh - lower-detail mesh drawn instead, once the camera is far enough away distance# - distance at which this level takes over, in world units. Must be greater than 0, and greater than the distance of every level already added |
Description
EntityLODTransition optionally blends between these actual mesh levels over a distance band. It submits both meshes inside the band and divides their pixel coverage between them. Width zero retains ordinary hard switching.
|
Adds a lower-detail mesh that replaces an entity when the camera is far away. This is the classic way to fill a landscape with trees, rocks or buildings without melting the frame rate. You keep your detailed mesh for close-ups, register one or two cheaper versions, and the renderer swaps them in as the camera pulls back. Call it once per level, in increasing distance order: AddEntityLOD tree,tree_medium,35 AddEntityLOD tree,tree_low,80 The base mesh is used up to the first distance, then each level takes over in turn. Distance is measured from the camera to the nearest point on the entity's transformed bounding box, so a big building switches later than a small rock at the same position. Switching has 10% hysteresis so a camera hovering on a boundary does not flicker between levels, and each camera keeps its own choice - mirrors and shadow passes follow the source camera so their detail stays stable. The level keeps a reference to the replacement mesh's data (and to its brush and shader as they were when you registered it), so you can hide or free the template entity straight afterwards. CopyEntity copies the whole table, so set up the LOD levels once on a template and then stamp out copies - that is also the arrangement automatic instancing likes best, because all the copies at the same level share one mesh and group into a single draw. Gotcha: LOD affects rendering only. Collision, picking and EntityDistance keep using the base mesh, so a distant tree still blocks the player exactly as before. Levels must be added in strictly increasing distance order and a distance of 0 or less is an error. Animated, skinned and morphed meshes are rejected with a runtime error - LOD is for static geometry only. Requires Extended mode. See also: ClearEntityLODs, EntityCullRange, RenderLODSelections, RenderCulledEntities, CopyEntity. |
Example
; AddEntityLOD Example ; -------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,4,-15 CameraClsColor camera,20,30,50 light=CreateLight() RotateEntity light,45,45,0 ground=CreatePlane() EntityColor ground,60,80,55 ; Each detail level is painted its own colour so switches are easy to spot green_brush=CreateBrush(60,200,80) amber_brush=CreateBrush(230,180,50) red_brush=CreateBrush(220,70,60) ; Detailed base tree, plus two cruder stand-in meshes tree=CreateSphere(16) ScaleMesh tree,1,2,1 PositionMesh tree,0,2,0 PaintMesh tree,green_brush tree_mid=CreateSphere(6) ScaleMesh tree_mid,1,2,1 PositionMesh tree_mid,0,2,0 PaintMesh tree_mid,amber_brush tree_far=CreateCube() ScaleMesh tree_far,0.9,1.8,0.9 PositionMesh tree_far,0,1.8,0 PaintMesh tree_far,red_brush ; Register the LOD levels: amber takes over at 12 units, red at 24 AddEntityLOD tree,tree_mid,12 AddEntityLOD tree,tree_far,24 ; A forest of copies - CopyEntity copies the complete LOD table For n=0 To 59 copy=CopyEntity(tree) PositionEntity copy,(n Mod 6)*4-10,0,(n/6)*5 Next HideEntity tree HideEntity tree_mid HideEntity tree_far While Not KeyDown(1) ; 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 Esc: exit" Text 0,20,"Green=base mesh Amber=LOD from 12 Red=LOD from 24" Text 0,40,"Trees drawn with a LOD mesh: "+RenderLODSelections() Flip Wend End
Index