3 Commits 219d2de17c ... 107de8982b

Autor SHA1 Mensagem Data
  sl@cccfr.de 107de8982b procedual loading 2 anos atrás
  sl@cccfr.de bf98ee771e fix casing 2 anos atrás
  sl@cccfr.de 523de22e73 consolidate tile.gd 2 anos atrás
10 arquivos alterados com 238 adições e 352 exclusões
  1. 49 0
      ChunkSystem.gd
  2. 24 28
      Main.gd
  3. 4 2
      Main.tscn
  4. 10 1
      Player.gd
  5. 1 1
      TextureLoader.gd
  6. 141 158
      Tile.gd
  7. 3 3
      TopoLoader.gd
  8. 1 1
      chunk.tscn
  9. 5 0
      common.gd
  10. 0 158
      flat_tile.gd

+ 49 - 0
ChunkSystem.gd

@@ -0,0 +1,49 @@
+extends Spatial
+
+var Chunk = preload("res://chunk.tscn")
+onready var Player = $"../Player"
+
+var resolution = 512
+var radius = 1737.4
+var renderDistance = 1
+
+var chunkIndex = {}
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+	pass # Replace with function body.
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(delta):
+	var playerSpos = Player.getSpos()
+	var playerRoundSpos = playerSpos.round()
+	var playerChunkPos = Vector2(int(playerRoundSpos.x), int(playerRoundSpos.y))
+	var playerInterChunkPos = Vector2(playerSpos.x - playerChunkPos.x, playerSpos.y - playerChunkPos.y)
+	
+	for i in [Vector2(1,0),Vector2(1,1),Vector2(0,1),Vector2(-1,0),Vector2(0,-1),Vector2(-1,-1),Vector2(1,-1),Vector2(-1,1)]:
+		var dist = Vector2(playerSpos.x, playerSpos.y).distance_to(playerChunkPos+i+Vector2(0.5,0.5))
+		if dist < renderDistance:
+			add_chunk(playerChunkPos+i)
+
+
+func add_chunk(chunkPos = Vector2()):
+	var lat = int(chunkPos.x)
+	var lon = int(chunkPos.y)
+	if chunkIndex.has(lon) and chunkIndex[lon].has(lat):
+		return
+	var chunk = Chunk.instance()
+	chunk.setParams(lat,lat+1,lon,lon+1,resolution,radius)
+	#moontile.scale=Vector3(1000,1000,1000)
+	.add_child(chunk)
+	if not chunkIndex.has(lon):
+		chunkIndex[lon]={}
+	chunkIndex[lon][lat] = chunk
+
+func remove_chunk(chunkPos = Vector2()):
+	var lat = int(chunkPos.x)
+	var lon = int(chunkPos.y)
+	if chunkIndex.has(lon) and chunkIndex[lon].has(lat):
+		chunkIndex[lon][lat].queue_free()
+		chunkIndex[lon].delete(lat)
+

+ 24 - 28
Main.gd

@@ -5,25 +5,25 @@ extends Spatial
 # var a = 2
 # var b = "text"
 #var tileGenScene = preload("res://TileGenerator.tscn")
-var Chunk = preload("res://chunk.tscn")
+#var Chunk = preload("res://chunk.tscn")
 
-var minlat = 24
-var maxlat = 26
-var minlon = 2
-var maxlon = 4
-var steplat = 1
-var steplon = 1
+#var minlat = 20
+#var maxlat = 26
+#var minlon = 308
+#var maxlon = 313
+#var steplat = 1
+#var steplon = 1
 
-var resolution = 512
+#var resolution = 512
 var radius = 1737.4#*1000
+var startPos = Vector3(20,308,radius)
 
-var curlat = 0
-var curlon = 0
+#var curlat = 0
+#var curlon = 0
 
 func _ready():
 	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
-	curlat = minlat*steplat
-	curlon = minlon*steplon
+	get_node("Player").moveTo(startPos)
 	
 func _input(event):
 	if event.is_action_pressed("ui_cancel"):
@@ -34,22 +34,18 @@ func _input(event):
 			get_tree().set_input_as_handled()
 
 func _process(delta):
-	if curlat < maxlat*steplat:
-		if curlon < maxlon*steplon:
-			call_deferred("add_chunk", curlon, curlat)
-			curlon += steplon
-		else:
-			curlat +=steplat
-			curlon = 0
-			if curlat >= maxlat:
-				print("loading complete")
-
-func add_chunk(curlon, curlat):
-	var chunk = Chunk.instance()
-	chunk.setParams(curlat,curlat+steplat,curlon,curlon+steplon,resolution,radius)
-	#moontile.scale=Vector3(1000,1000,1000)
-	$Tiles.add_child(chunk)
-	.get_node("UI/3").text="lastLatLon="+str(curlat)+":"+str(curlon)
+	pass
+	#if curlat < maxlat*steplat:
+	#	if curlon < maxlon*steplon:
+	#		.get_node("Chunks").call_deferred("add_chunk", Vector2(curlat,curlon))
+	#		curlon += steplon
+	#	else:
+	#		curlat +=steplat
+	#		curlon = 0
+	#		if curlat >= maxlat:
+	#			print("loading complete")
+
+
 
 # Called every frame. 'delta' is the elapsed time since the previous frame.
 #func _process(delta):

+ 4 - 2
Main.tscn

@@ -1,7 +1,8 @@
-[gd_scene load_steps=9 format=2]
+[gd_scene load_steps=10 format=2]
 
 [ext_resource path="res://Main.gd" type="Script" id=1]
 [ext_resource path="res://Player.gd" type="Script" id=2]
+[ext_resource path="res://ChunkSystem.gd" type="Script" id=3]
 
 [sub_resource type="ProceduralSky" id=4]
 sun_latitude = 135.0
@@ -57,7 +58,8 @@ material/0 = null
 transform = Transform( 1, 0, 0, 0, 0.573905, -0.818922, 0, 0.818922, 0.573905, -0.00356923, 0.433873, 1.27676 )
 light_energy = 7.3
 
-[node name="Tiles" type="Spatial" parent="."]
+[node name="Chunks" type="Spatial" parent="."]
+script = ExtResource( 3 )
 __meta__ = {
 "_edit_lock_": true
 }

+ 10 - 1
Player.gd

@@ -37,10 +37,19 @@ onready var forward = global_transform.basis.y
 onready var right = forward.cross(up).normalized()
 
 func _ready():
-	move_and_slide(Common.latLonToGlobal(Vector3(24,2,1737.4)), Vector3.UP)
 	if mouse_captured:
 		Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
 	pass
+	
+func moveTo(pos = Vector3()):
+	if pos.z == 0:
+		pos.z = 1737.4
+	move_and_slide(Common.latLonToGlobal(Vector3(pos.x,pos.y,pos.z)), Vector3.UP)
+
+func getSpos():
+	var sPos = Common.globalToLatLon(self.global_transform.origin)
+	sPos.y = Common.relativeToAbsolute(sPos.y)
+	return sPos
 
 func _process(delta):
 	var pos = self.global_transform.origin

+ 1 - 1
TextureLoader.gd

@@ -10,7 +10,7 @@ func _ready():
 
 func loadTexture(lat, lon):
 	var texName = getTexName(lat, lon)
-	print(texName)
+	print("opening texture "+texName)
 	var image = Image.new()
 	var err = image.load(texName)
 	if err != OK:

+ 141 - 158
Tile.gd

@@ -1,175 +1,158 @@
 extends MeshInstance
 
-var latMin = 0
-var latMax = 1
-var lonMin = 0
-var lonMax = 1
-var resolution = 512
-var radius = 1737.4 
-var rng = RandomNumberGenerator.new()
+var Point = preload("res://point.tscn")
+var TopoLoader = preload("res://TopoLoader.gd")
+var TextureLoader = preload("res://TextureLoader.gd")
+#var grid = load("res://tex/grid.png")
 
-var datafile = "user://sldem2015_512_00n_30n_000_045_float.img"
-var samplesPerLine = 23040
-var lines = 15360
-#var offset = 1737.4
-var scaleFact = 1
+var latMin:float = 0
+var latMax:float = 1
+var lonMin:float = 0.0
+var lonMax:float = 1.0
+var resolution:int = 512
+var radius:float = 10
+
+var origin:Vector3
+
+func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float):	
+	latMin = latMinIN
+	latMax = latMaxIN
+	lonMin = lonMinIN
+	lonMax = lonMaxIN
+	resolution = resolutionIN
+	radius = radiusIN
 
-func init(startLat, startLon):
-	
-	self.latMin = startLat
-	self.latMax = startLat + 1
-	self.lonMin = startLon
-	self.lonMax = startLon + 1
-		
-# Called when the node enters the scene tree for the first time.
 func _ready():
+	pass
+	#genMesh called from chunk
+	#self.genMesh()
 	
-	if ResourceLoader.exists("user://tile_"+str(latMin)+"-"+str(lonMin)+".tres"):
-		print("loading tile from file: ", "user://tile_"+str(latMin)+"-"+str(lonMin)+".tres")
-		mesh = ResourceLoader.load("user://tile_"+str(latMin)+"-"+str(lonMin)+".tres")
-	else:
-		self.genMesh()
-	
-	var texture = ImageTexture.new()
-	var image = Image.new()
-	#image.load("res://m-"+str(latMin+90)+"-"+str(lonMin+180)+".png")
-	image.load("user://colorTiles/m-" + str(latMin+90)+"-"+str(lonMin+180)+".png")
-	texture.create_from_image(image)
-	var material=SpatialMaterial.new()
-	material.albedo_texture = texture
-	.set_material_override(material)
-	#print("creating collition...")
-	#.create_trimesh_collision()
-		
 func genMesh():
-	var file = File.new()
-	file.open(datafile, File.READ)
-	#for lala in range(10):
-	#	file.seek(lala*samplesPerLine*4)
-	#	var blubb = ""
-	#	for bla in range(10):
-	#		blubb += " " + str(file.get_float())
-	#	print(blubb)
-	rng.randomize()
+	#print("generating Mesh:")
+	#print("latMin: " + str(latMin))
+	#print("latMax: " + str(latMax))
+	#print("lonMin: " + str(lonMin))
+	#print("lonMax: " + str(lonMax))
+	#print("resolution: " + str(resolution))
+	
+	var verts = convertToCartesian(genSphereCoords())
 	var arr = []
 	arr.resize(Mesh.ARRAY_MAX)
-	#OS.delay_msec(2000)
-	# PoolVectorXXArrays for mesh construction.
-	var verts = PoolVector3Array()
-	verts.resize((lonMax-lonMin) *resolution*(lonMax-lonMin) *resolution)
-	var uvs = PoolVector2Array()
-	uvs.resize((lonMax-lonMin) *resolution*(lonMax-lonMin) *resolution)
-	var normals = PoolVector3Array()
-	normals.resize((lonMax-lonMin) *resolution*resolution * (lonMax-lonMin))
-	var indices = PoolIntArray()
-	indices.resize(6* (lonMax-lonMin)*resolution*(lonMax-lonMin) * resolution*6)
-	var i_idx = 0
+	arr[Mesh.ARRAY_VERTEX] = verts
+	arr[Mesh.ARRAY_TEX_UV] = genUV()
+	arr[Mesh.ARRAY_NORMAL] = genNormals(verts)
+	arr[Mesh.ARRAY_INDEX] = genIndex()
+	mesh = Mesh.new()
+	mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
+	var mat = SpatialMaterial.new()
+	#mat.albedo_color = Color(0.7,0.7,0.7,1)
+	var texl = TextureLoader.new()
+	mat.albedo_texture = texl.loadTexture(latMin, lonMin)
+	mesh.surface_set_material(0,mat)
+	.create_trimesh_collision()
 	
+	var drawBubbles = false
+	if drawBubbles:
+		var i = 0.0
+		for vert in verts:
+			var point = Point.instance()
+			point.translate(vert)
+			var pointMat = SpatialMaterial.new()#point.mesh.surface_get_material(0)
+			mat.albedo_color = Color(i,0,0,1)
+			i+=0.1
+			point.mesh.surface_set_material(0,pointMat)
+			.get_parent().add_child(point)
 
-	# Vertex indices.
-	var thisrow = 0
-	var prevrow = 0
-	var point = 0
+func genNormals(verts:PoolVector3Array):
+	var normals = PoolVector3Array()
+	normals.resize(len(verts))
+	var v_idx = 0
+	for vert in verts:
+		normals[v_idx] = vert.normalized()
+		v_idx+=1
+	#print("normals")
+	#print(len(normals))
+	return normals
 
-	print(
-		"calculating segment "+str(latMin)+"-"+str(lonMin)+":\n",
-		"lat:\n",
-		"  min: ", latMin*resolution, "\n",
-		"  max:", latMax*resolution, "\n",
-		"  count: ", (latMax-latMin) * resolution, "\n",
-		"lon:\n",
-		"  min: ", lonMin*resolution, "\n",
-		"  max:", lonMax*resolution, "\n",
-		"  count: ", (lonMax-lonMin) * resolution, "\n"
-	)
+func genUV():
+	var uvs = PoolVector2Array()
+	uvs.resize((resolution+1) * (resolution+1))
+	var v_idx = 0
+	for _y in range(0,resolution+1):
+		for _x in range(0,resolution+1):
+			var y = float(_y)
+			var x = float(_x)
+			var devider = float(resolution+1)
+			uvs[v_idx] = Vector2(x/devider,1-(y/devider))
+			v_idx+=1
+	
+	#for v_idx in range(0,(resolution+1) * (resolution+1)):
+	#	var y = v_idx / resolution
+	#	var x = v_idx % resolution
+	#	uvs[v_idx]=Vector2(clamp(x, 0, resolution),clamp(y, 0, resolution))
+	#print("uv")
+	#print(len(uvs))
+	return uvs
 	
-	#OS.delay_msec(2000)
-
-	var vert = Vector3()
-	# Loop over rings.
-	for latPos in range(float(latMin)*resolution, float(latMax)*resolution):
-		var latCur = float(latPos)/float(resolution)
-		#jump to    last line in file   -   current local lat    -      local startLat     +  local startLon
-		file.seek(lines*samplesPerLine*4-latPos*samplesPerLine*4 - latMin*samplesPerLine*4 + lonMin*resolution*4)
-		#file.seek(latPos*samplesPerLine*4 + latMin*samplesPerLine*4 + lonMin*resolution*4)
-		#file.seek(latPos*samplesPerLine*4 + lonMin*resolution*4) 
-		#file.seek(((latMax*resolution-1-latPos)*samplesPerLine + lonMin*resolution)*4)
-		#var v = float(latPos-latMin*resolution) / ((latMax-latMin) * resolution)
-		var v = float(latPos-latMin*resolution) / ((latMax-latMin) * resolution)
-		#var lat = float(latPos)*PI/(resolution*180)
-		#var w = cos(lat)
-		#var y = sin(lat)
-		#print(v*100, "%")
-
-		# Loop over segments in ring.
-		for lonPos in range(float(lonMin)*resolution, float(lonMax)*resolution):
-			var lonCur = float(lonPos)/float(resolution)
-			var u = float(lonPos-lonMin*resolution) / ((lonMax - lonMin) * resolution)
-			#var lon = float(lonPos)*PI/(resolution*180)
-			#var x = sin(lon)
-			#var z = cos(lon)
-			#print("Lon: ", lon)
-			#var height = file.get_float()/offset*radius+radius
-			var height = file.get_float()+radius
-			vert = Common.latLonToGlobal(latCur, lonCur, height)
-			#vert = Vector3(scaleFact * x * height * w, scaleFact * y*height, scaleFact * z * height * w)
-			verts[point] = vert
-			normals[point] = vert.normalized()
-			uvs[point] = Vector2(u, 1-v)
-			point += 1
-
-			# Create triangles in ring using indices.
-			if latPos > lonMin*resolution and lonPos > lonMin*resolution:
-				indices[i_idx] = (prevrow + (lonPos-lonMin*resolution) - 1)
-				i_idx+=1
-				indices[i_idx] = (thisrow + (lonPos-lonMin*resolution) - 1)
-				i_idx+=1
-				indices[i_idx] = (prevrow + (lonPos-lonMin*resolution))
-				i_idx+=1
-
-				indices[i_idx] = (prevrow + (lonPos-lonMin*resolution))
-				i_idx+=1
-				indices[i_idx] = (thisrow + (lonPos-lonMin*resolution) - 1)
-				i_idx+=1
-				indices[i_idx] = (thisrow + (lonPos-lonMin*resolution))
-				i_idx+=1
-				
-
-		#if latPos > latMin*resolution:
-		#	indices[i_idx] = (prevrow + ((latMax - latMin) * resolution) - 1)
-		#	i_idx+=1
-		#	indices[i_idx] = (prevrow)
-		#	i_idx+=1
-		#	indices[i_idx] = (thisrow + ((latMax - latMin) * resolution) - 1)
-		#	i_idx+=1
-
-		#	indices[i_idx] = (prevrow)
-		#	i_idx+=1
-		#	indices[i_idx] = (prevrow + ((latMax - latMin) * resolution))
-		#	i_idx+=1
-		#	indices[i_idx] = (thisrow + ((latMax - latMin) * resolution) - 1)
-		#	i_idx+=1
-		#print(vert)
-
-		prevrow = thisrow
-		thisrow = point
 
-	file.close()
-	print(vert)
-	# Assign arrays to mesh array.
-	arr[Mesh.ARRAY_VERTEX] = verts
-	arr[Mesh.ARRAY_TEX_UV] = uvs
-	arr[Mesh.ARRAY_NORMAL] = normals
-	arr[Mesh.ARRAY_INDEX] = indices
+func genIndex():
+	var indices = PoolIntArray()
+	indices.resize(6* ((resolution) * (resolution)))
+	
+	var i_idx = 0
+	for row in range(0, resolution):
+		for col in range(0,resolution):
+			var v_idx = row*(resolution+1)+col
+			
+			indices[i_idx] = v_idx
+			i_idx+=1
+			indices[i_idx] = v_idx + resolution +1
+			i_idx+=1
+			indices[i_idx] = v_idx + 1
+			i_idx+=1
 
-	mesh = Mesh.new()
-	# Create mesh surface from mesh array.
-	mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
-	print(mesh)
-	ResourceSaver.save("user://tile_"+str(latMin)+"-"+str(lonMin)+".tres", mesh, 32)
-	print("saved tile_"+str(latMin)+"-"+str(lonMin))
+			indices[i_idx] = v_idx + resolution+1
+			i_idx+=1
+			indices[i_idx] = v_idx + resolution + 2
+			i_idx+=1
+			indices[i_idx] = v_idx + 1
+			i_idx+=1
+		
+	#print("indices")
+	#print(len(indices))
+	return indices
+		
+func genSphereCoords():
+	var tl = TopoLoader.new()
+	add_child(tl)
+	tl.open(latMin, lonMin)
+	tl.cacheArea(latMin, latMax, lonMin, lonMax)
+	var verts = PoolVector3Array()
+	var size = (resolution+1) * (resolution+1)#(lonMax-lonMin)*resolution * (latMax-latMin)*resolution
+	verts.resize(size)
 	
+	var lonStep = (lonMax - lonMin)/resolution
+	var latStep = (latMax - latMin)/resolution
+	var v_idx = 0
+	for y in range(0,resolution+1):
+		for x in range(0,resolution+1):
+			var lat = latMin+latStep*y
+			var lon = lonMin+lonStep*x
+			verts[v_idx] = Vector3(lat, lon, radius+tl.read(lat,lon))
+			v_idx+=1
+	tl.close()
+	return verts
+
 
-# Called every frame. 'delta' is the elapsed time since the previous frame.
-#func _process(delta):
-#	pass
+func convertToCartesian(verts:PoolVector3Array):
+	var carVerts = PoolVector3Array()
+	carVerts.resize(len(verts))
+	var v_idx = 0
+	for vert in verts:
+		if not origin:
+			origin = vert			
+		carVerts[v_idx] = Common.latLonToGlobal(vert, Vector3())#, origin)
+		v_idx+=1
+	#print("Cartesian")
+	#print(len(carVerts))
+	return carVerts

+ 3 - 3
TopoLoader.gd

@@ -3,7 +3,7 @@ extends Node
 var Downloader = preload("res://downloader.gd")
 
 var filePrefix = "user://topo"
-var formatString = "%s/sldem2015_%s_%02d%s_%02d%s_%03d_%03d_float.img"
+var formatString = "%s/SLDEM2015_%s_%02d%s_%02d%s_%03d_%03d_FLOAT.IMG"
 #              example sldem2015_512_00n_30n_000_045_float.img
 var datafile = "user://topo/sldem2015_512_00n_30n_000_045_float.img"
 var samplesPerLine = 23040
@@ -77,9 +77,9 @@ func getFilename():
 	#     "%s/sldem2015_%s_%0*d%s_%0*d%s_%00*d_%00*d_float.img"
 	var orientation: String
 	if latMin >= 0:
-		orientation = "n"
+		orientation = "N"
 	else:
-		orientation = "s"
+		orientation = "S"
 	var properties = [filePrefix, resolution, latMin, orientation, latMax, orientation, lonMin, lonMax]
 	return formatString % properties
 

+ 1 - 1
chunk.tscn

@@ -1,7 +1,7 @@
 [gd_scene load_steps=3 format=2]
 
 [ext_resource path="res://chunk.gd" type="Script" id=1]
-[ext_resource path="res://flat_tile.gd" type="Script" id=2]
+[ext_resource path="res://Tile.gd" type="Script" id=2]
 
 [node name="Chunk" type="Spatial"]
 script = ExtResource( 1 )

+ 5 - 0
common.gd

@@ -25,6 +25,11 @@ func globalToLatLon(pos: Vector3, offset=Vector3()):
 	#print("x:"+str(x)+" y:"+str(y)+" z:"+str(z)))
 	#print("lat:"+str(lat)+" lon:"+str(lon))
 	return Vector3(lat, lon, height)
+	
+func relativeToAbsolute(rel = float()):
+	var absolute = float()
+	absolute = rel+180-(sign(rel)*180)
+	return absolute
 
 #func globalToRad(pos: Vector3):
 #	var floor_normal = pos - Vector3()

+ 0 - 158
flat_tile.gd

@@ -1,158 +0,0 @@
-extends MeshInstance
-
-var Point = preload("res://point.tscn")
-var TopoLoader = preload("res://TopoLoader.gd")
-var TextureLoader = preload("res://TextureLoader.gd")
-#var grid = load("res://tex/grid.png")
-
-var latMin:float = 0
-var latMax:float = 1
-var lonMin:float = 0.0
-var lonMax:float = 1.0
-var resolution:int = 512
-var radius:float = 10
-
-var origin:Vector3
-
-func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float):	
-	latMin = latMinIN
-	latMax = latMaxIN
-	lonMin = lonMinIN
-	lonMax = lonMaxIN
-	resolution = resolutionIN
-	radius = radiusIN
-
-func _ready():
-	pass
-	#genMesh called from chunk
-	#self.genMesh()
-	
-func genMesh():
-	#print("generating Mesh:")
-	#print("latMin: " + str(latMin))
-	#print("latMax: " + str(latMax))
-	#print("lonMin: " + str(lonMin))
-	#print("lonMax: " + str(lonMax))
-	#print("resolution: " + str(resolution))
-	
-	var verts = convertToCartesian(genSphereCoords())
-	var arr = []
-	arr.resize(Mesh.ARRAY_MAX)
-	arr[Mesh.ARRAY_VERTEX] = verts
-	arr[Mesh.ARRAY_TEX_UV] = genUV()
-	arr[Mesh.ARRAY_NORMAL] = genNormals(verts)
-	arr[Mesh.ARRAY_INDEX] = genIndex()
-	mesh = Mesh.new()
-	mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
-	var mat = SpatialMaterial.new()
-	#mat.albedo_color = Color(0.7,0.7,0.7,1)
-	var texl = TextureLoader.new()
-	mat.albedo_texture = texl.loadTexture(latMin, lonMin)
-	mesh.surface_set_material(0,mat)
-	.create_trimesh_collision()
-	
-	var drawBubbles = false
-	if drawBubbles:
-		var i = 0.0
-		for vert in verts:
-			var point = Point.instance()
-			point.translate(vert)
-			var pointMat = SpatialMaterial.new()#point.mesh.surface_get_material(0)
-			mat.albedo_color = Color(i,0,0,1)
-			i+=0.1
-			point.mesh.surface_set_material(0,pointMat)
-			.get_parent().add_child(point)
-
-func genNormals(verts:PoolVector3Array):
-	var normals = PoolVector3Array()
-	normals.resize(len(verts))
-	var v_idx = 0
-	for vert in verts:
-		normals[v_idx] = vert.normalized()
-		v_idx+=1
-	#print("normals")
-	#print(len(normals))
-	return normals
-
-func genUV():
-	var uvs = PoolVector2Array()
-	uvs.resize((resolution+1) * (resolution+1))
-	var v_idx = 0
-	for _y in range(0,resolution+1):
-		for _x in range(0,resolution+1):
-			var y = float(_y)
-			var x = float(_x)
-			var devider = float(resolution+1)
-			uvs[v_idx] = Vector2(x/devider,1-(y/devider))
-			v_idx+=1
-	
-	#for v_idx in range(0,(resolution+1) * (resolution+1)):
-	#	var y = v_idx / resolution
-	#	var x = v_idx % resolution
-	#	uvs[v_idx]=Vector2(clamp(x, 0, resolution),clamp(y, 0, resolution))
-	#print("uv")
-	#print(len(uvs))
-	return uvs
-	
-
-func genIndex():
-	var indices = PoolIntArray()
-	indices.resize(6* ((resolution) * (resolution)))
-	
-	var i_idx = 0
-	for row in range(0, resolution):
-		for col in range(0,resolution):
-			var v_idx = row*(resolution+1)+col
-			
-			indices[i_idx] = v_idx
-			i_idx+=1
-			indices[i_idx] = v_idx + resolution +1
-			i_idx+=1
-			indices[i_idx] = v_idx + 1
-			i_idx+=1
-
-			indices[i_idx] = v_idx + resolution+1
-			i_idx+=1
-			indices[i_idx] = v_idx + resolution + 2
-			i_idx+=1
-			indices[i_idx] = v_idx + 1
-			i_idx+=1
-		
-	#print("indices")
-	#print(len(indices))
-	return indices
-		
-func genSphereCoords():
-	var tl = TopoLoader.new()
-	add_child(tl)
-	tl.open(latMin, lonMin)
-	tl.cacheArea(latMin, latMax, lonMin, lonMax)
-	var verts = PoolVector3Array()
-	var size = (resolution+1) * (resolution+1)#(lonMax-lonMin)*resolution * (latMax-latMin)*resolution
-	verts.resize(size)
-	
-	var lonStep = (lonMax - lonMin)/resolution
-	var latStep = (latMax - latMin)/resolution
-	var v_idx = 0
-	for y in range(0,resolution+1):
-		for x in range(0,resolution+1):
-			var lat = latMin+latStep*y
-			var lon = lonMin+lonStep*x
-			verts[v_idx] = Vector3(lat, lon, radius+tl.read(lat,lon))
-			v_idx+=1
-	tl.close()
-	return verts
-
-
-func convertToCartesian(verts:PoolVector3Array):
-	var carVerts = PoolVector3Array()
-	carVerts.resize(len(verts))
-	var v_idx = 0
-	for vert in verts:
-		if not origin:
-			origin = vert			
-		carVerts[v_idx] = Common.latLonToGlobal(vert, Vector3())#, origin)
-		v_idx+=1
-	#print("Cartesian")
-	#print(len(carVerts))
-	return carVerts