瀏覽代碼

add downloader stump

Malf 2 年之前
父節點
當前提交
570e0a472d
共有 3 個文件被更改,包括 34 次插入2 次删除
  1. 8 2
      TopoLoader.gd
  2. 25 0
      downloader.gd
  3. 1 0
      flat_tile.gd

+ 8 - 2
TopoLoader.gd

@@ -1,7 +1,8 @@
 extends Node
 
+var Downloader = preload("res://downloader.gd")
 
-var datafile = "user://sldem2015_512_00n_30n_000_045_float.img"
+var datafile = "height/SLDEM2015_512_30N_60N_000_045_FLOAT.IMG"
 var samplesPerLine = 23040
 var lines = 15360
 var offset = 1737.4
@@ -19,7 +20,12 @@ var file: File
 # Called when the node enters the scene tree for the first time.
 func open():
 	file = File.new()
-	file.open(datafile, File.READ)
+	if not file.file_exists("user://"+datafile):
+		var downloader = Downloader.new()
+		add_child(downloader)
+		downloader.load(datafile, "height")
+		yield(downloader, "request_completed")
+	file.open("user://"+datafile, File.READ)
 	
 func close():
 	file.close()

+ 25 - 0
downloader.gd

@@ -0,0 +1,25 @@
+extends HTTPRequest
+
+var kinds = {
+	"height": "http://imbrium.mit.edu/DATA/SLDEM2015/TILES/FLOAT_IMG/%s",
+	"color": "" 
+}
+
+func ensureFolder(kind):
+	var dir = Directory.new()
+	dir.open("user://")
+	if not dir.dir_exists(kind):
+		dir.make_dir(kind)
+
+func load(file, kind):
+	if not kinds.has(kind):
+		print("don't know kind %s"%kind)
+		return
+	
+	ensureFolder(kind)
+	var url = kinds[kind]%file
+	download_file = "user://%s/%s".format([kind, file])
+	# Perform a GET request.
+	var error = request(url)
+	if error != OK:
+		push_error("An error occurred in the HTTP request.")

+ 1 - 0
flat_tile.gd

@@ -124,6 +124,7 @@ func genIndex():
 		
 func genSphereCoords():
 	var tl = TopoLoader.new()
+	add_child(tl)
 	tl.open()
 	tl.cacheArea(latMin, latMax, lonMin, lonMax)
 	var verts = PoolVector3Array()