Here's another version which culls unwanted poly's ... if you want to see the original poly count uncomment the flag = 0 command.
Stevie
Stevie
Graphics3D 640,480,16,1 AmbientLight 128,128,128 Global LIGHT = CreateLight() : RotateEntity LIGHT, 30,-45,0 Global CAMERA = CreateCamera() : PositionEntity CAMERA, 0, 20, -25 Global LEVEL ;culling consts Const C_Front = 1 Const C_Rear = 4 Const C_Left = 8 Const C_Right = 2 Const C_Top = 16 Const C_Bottom = 32 Dim PT( 20,20 ) ;create random level points For l = 0 To 20 PT( 0 , l ) = 1 PT( 20 , l ) = 1 PT( l , 0 ) = 1 PT( l , 20 ) = 1 Next For l = 1 To 200 PT( Rand(1,19), Rand(1,19) ) = 1 Next ;create level mesh LEVEL = CreateMesh() : EntityFX LEVEL, 4 For y = 0 To 20 For x = 0 To 20 If PT( x, y ) = 1 Flag = C_Bottom If x > 0 If PT( x-1 , y ) = 1 Flag = Flag + C_Left EndIf If x < 20 If PT( x+1 , y ) = 1 Flag = Flag + C_Right EndIf If y > 0 If PT( x , y-1 ) = 1 Flag = Flag + C_Rear EndIf If y < 20 If PT( x, y+1 ) = 1 Flag = Flag + C_Front EndIf ;flag = 0 Tmp = MESHcull( CreateCube(), Flag ) PositionMesh tmp, (x - 10 ) * 2 , 1 , ( y - 10 ) * 2 AddMesh tmp, LEVEL : FreeEntity tmp EndIf Next Next PointEntity CAMERA, LEVEL While Not KeyHit(1) TurnEntity LEVEL, 0, .25, 0 RenderWorld Text 0,0, CountTriangles( GetSurface( LEVEL, 1 ) ) Flip Wend End ;================================================================================================== ;================================================================================================== ;================================================================================================== Function MESHcull( Mesh , Flags = 0 ) If Flags = 0 Return Mesh s = GetSurface( Mesh , 1 ) Copy = CreateMesh() Cs = CreateSurface( Copy ) For t = 0 To CountTriangles( s )-1 ;calculate triangle normal v0 = TriangleVertex( s, t, 0 ) v1 = TriangleVertex( s, t, 1 ) v2 = TriangleVertex( s, t, 2 ) ax# = VertexX( s, v1 ) - VertexX( s, v0 ) ay# = VertexY( s, v1 ) - VertexY( s, v0 ) az# = VertexZ( s, v1 ) - VertexZ( s, v0 ) bx# = VertexX( s, v2 ) - VertexX( s, v1 ) by# = VertexY( s, v2 ) - VertexY( s, v1 ) bz# = VertexZ( s, v2 ) - VertexZ( s, v1 ) Nx# = ( ay * bz ) - ( az * by ) Ny# = ( az * bx ) - ( ax * bz ) Nz# = ( ax * by ) - ( ay * bx ) Ns# = Sqr( Nx * Nx + Ny*Ny + Nz*Nz ) Nx = Nx / Ns Ny = Ny / Ns Nz = Nz / Ns OK = True For l = 0 To 5 Flag = 2^l If ( Flags And Flag) = Flag ;determine plane normal Select Flag Case C_Front px# = 0 : py# = 0 : pz# = 1 Case C_Rear px# = 0 : py# = 0 : pz# = -1 Case C_Left px# = -1 : py# = 0 : pz# = 0 Case C_Right px# = 1 : py# = 0 : pz# = 0 Case C_Top px# = 0 : py# = 1 : pz# = 0 Case C_Bottom px# = 0 : py# = -1 : pz# = 0 End Select If Nx = Px And Ny = Py And Nz = Pz OK = False EndIf Next If OK nv0 = AddVertex( Cs, VertexX( s , v0 ) , VertexY( s, v0 ) , VertexZ( s, v0 ) ) nv1 = AddVertex( Cs, VertexX( s , v1 ) , VertexY( s, v1 ) , VertexZ( s, v1 ) ) nv2 = AddVertex( Cs, VertexX( s , v2 ) , VertexY( s, v2 ) , VertexZ( s, v2 ) ) VertexNormal Cs , nv0 , Nx, Ny, Nz VertexNormal Cs , nv1 , Nx, Ny, Nz VertexNormal Cs , nv2 , Nx, Ny, Nz AddTriangle( Cs , nv0, nv1, nv2 ) EndIf Next FreeEntity mesh Return copy End Function