; SimplifyMesh Example ; -------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-5 light=CreateLight() RotateEntity light,45,45,0 ; The left ball keeps every triangle full=CreateSphere(32) PositionEntity full,-1.3,0,0 EntityColor full,90,160,230 ; The right ball is a copy, simplified to keep about half its triangles keep#=0.5 simple=CopyMesh(full) SimplifyMesh simple,keep PositionEntity simple,1.3,0,0 EntityColor simple,230,160,90 wire=True While Not KeyDown(1) ; [ / ] keep fewer or more triangles: simplify a fresh copy each time old#=keep If KeyHit(26) And keep>0.15 Then keep=keep-0.1 If KeyHit(27) And keep<0.95 Then keep=keep+0.1 If keep<>old FreeEntity simple simple=CopyMesh(full) SimplifyMesh simple,keep PositionEntity simple,1.3,0,0 EntityColor simple,230,160,90 EndIf ; Space shows or hides the triangles If KeyHit(57) Then wire=Not wire WireFrame wire TurnEntity full,0,0.5,0 TurnEntity simple,0,0.5,0 ; 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 [ / ] : keep Space: wireframe Esc: exit" Text 0,20,"SimplifyMesh copy,"+keep Text 0,40,"Left: "+CountTriangles(GetSurface(full,1))+" triangles Right: "+CountTriangles(GetSurface(simple,1)) Flip Wend End