; ClearEntityLODs 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 AddEntityLOD tree,tree_mid,10 AddEntityLOD tree,tree_far,20 ; A forest of copies - CopyEntity copies the complete LOD table Dim trees(59) For n=0 To 59 trees(n)=CopyEntity(tree) PositionEntity trees(n),(n Mod 6)*4-10,0,(n/6)*5 Next HideEntity tree HideEntity tree_mid HideEntity tree_far lods_on=True While Not KeyDown(1) ; Space strips or re-registers the LOD table on every tree If KeyHit(57) lods_on=Not lods_on For n=0 To 59 If lods_on AddEntityLOD trees(n),tree_mid,10 AddEntityLOD trees(n),tree_far,20 Else ClearEntityLODs trees(n) EndIf Next EndIf ; 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 Space: toggle LODs Esc: exit" If lods_on Text 0,20,"LODs registered: amber from 10 units, red from 20" Else Text 0,20,"ClearEntityLODs called - every tree uses its base mesh" EndIf Text 0,40,"Trees drawn with a LOD mesh: "+RenderLODSelections() Flip Wend End