LoadTexture("skybox\moonc.png", "Moon", 1)
LoadMesh("skybox\moona.x", "Planetoid", "Moon", "Moon")
TextureMesh("Moon", "Moon")
PositionMesh("Moon", 0, 7500, 24500)
MeshCullOn("Moon")
MeshFogOff("Moon")
MeshLightOn("Moon")
SetMeshEmissive("Moon", rgb(255, 255, 255))

LoadMesh("Terrains\plain.x", "Terrain Base", "Base", "Plain")
PositionMesh("Plain", 0, 0, 0)
ColorMesh("Plain", rgb(150, 50, 40))
MeshCullOn("Plain")
MeshFogOn("Plain")
MeshLightOn("Plain")

LoadTexture("skybox\skye.png", "Sky", 1)
LoadMesh("Skybox\skyspherea.x", "Sky", "Skysphere", "Sky")
PositionMesh("Sky", 0, 0, 0)
TextureMesh("Sky", "Sky")
MeshCullOn("Sky")
MeshFogOff("Sky")
MeshLightOff("Sky")
SetMeshEmissive("Sky", rgb(255, 255, 255))

for a = 1 to 12
LoadMesh("Terrains\mesaa.x", "Terrain", "Base", "Mesa A" + str$(a))
PositionMesh("Mesa A" + str$(a), RandomWithSign(25000), 0, RandomWithSign(25000))
RotateMesh("Mesa A" + str$(a), 0, RandomWithSign(180), 0)
MeshCullOn("Mesa A" + str$(a))
ColorMesh("Mesa A" + str$(a), rgb(150, 50, 40))
next a

for a = 1 to 12
LoadMesh("Terrains\mesab.x", "Terrain", "Base", "Mesa B" + str$(a))
PositionMesh("Mesa B" + str$(a), RandomWithSign(25000), 0, RandomWithSign(25000))
RotateMesh("Mesa B" + str$(a), 0, RandomWithSign(180), 0)
MeshCullOn("Mesa B" + str$(a))
MeshLightOn("Mesa B" + str$(a))
ColorMesh("Mesa B" + str$(a), rgb(150, 50, 40))
next a

for a = 1 to 10
LoadTexture("plants\trees\scrub pines\scrub pine.png", "Scrub Pine", 1)
LoadMesh("plants\trees\scrub pines\scrub pine a1.x", "Foliage", "Tree", "Scrub Pine A" + str$(a))
PositionMesh("Scrub Pine A" + str$(a), RandomWithSign(250), 0, RandomWithSign(250))
RotateMesh("Scrub Pine A" + str$(a), 0, RandomWithSign(180), 0)
MeshCullOn("Scrub Pine A" + str$(a))
MeshLightOn("Scrub Pine A" + str$(a))
TextureMesh("Scrub Pine A" + str$(a), "Scrub Pine")
next a

for a = 1 to 10
LoadTexture("plants\trees\scrub pines\scrub pine.png", "Scrub Pine", 1)
LoadMesh("plants\trees\scrub pines\scrub pine b1.x", "Foliage", "Tree", "Scrub Pine B" + str$(a))
PositionMesh("Scrub Pine B" + str$(a), RandomWithSign(250), 0, RandomWithSign(250))
RotateMesh("Scrub Pine B" + str$(a), 0, RandomWithSign(180), 0)
MeshCullOn("Scrub Pine B" + str$(a))
MeshLightOn("Scrub Pine B" + str$(a))
TextureMesh("Scrub Pine B" + str$(a), "Scrub Pine")
next a

for a = 1 to 56
LoadTexture("plants\trees\scrub pines\scrub pine.png", "Scrub Pine", 1)
LoadMesh("plants\trees\scrub pines\scrub pine c1.x", "Foliage", "Tree", "Scrub Pine C" + str$(a))
PositionMesh("Scrub Pine C" + str$(a), RandomWithSign(250), 0, RandomWithSign(250))
RotateMesh("Scrub Pine C" + str$(a), 0, RandomWithSign(180), 0)
MeshCullOn("Scrub Pine C" + str$(a))
MeshLightOn("Scrub Pine C" + str$(a))
TextureMesh("Scrub Pine C" + str$(a), "Scrub Pine")
next a




function GetTerrainHeight(X#, Y#, Z#)

Name$ = NearestMeshClass("Terrain", X#, Y#, Z#, "", "", "")

if WithinMeshBounds(Name$, X#, Y#, Z#)
rem If we are here it means that a terrain feature is closest to us
YMax# = Y# + 10000
TerrainHeight# = YMax# - IntersectMesh(Name$, X#, YMax#, Z#, X#, -YMax#, Z#)
if WithinBounds(TerrainHeight#, 9999.9, 10000.1) < 0
exitfunction TerrainHeight#
else
rem If we are here it means that we didn't hit the terrain feature's mesh
YMax# = Y# + 10000
TerrainHeight# = YMax# - IntersectMesh("Plain", X#, YMax#, Z#, X#, -YMax#, Z#)
endif
else
rem If we are here it means we aren't near any terrain feature
YMax# = Y# + 10000
TerrainHeight# = YMax# - IntersectMesh("Plain", X#, YMax#, Z#, X#, -YMax#, Z#)
endif

endfunction TerrainHeight#