sl@cccfr.de 2 年之前
父節點
當前提交
ddf437e4f7
共有 3 個文件被更改,包括 26 次插入10 次删除
  1. 1 1
      Player.gd
  2. 3 1
      TextureLoader.gd
  3. 22 8
      TopoLoader.gd

+ 1 - 1
Player.gd

@@ -37,7 +37,7 @@ onready var forward = global_transform.basis.y
 onready var right = forward.cross(up).normalized()
 
 func _ready():
-	move_and_slide(Common.latLonToGlobal(Vector3(0,0,1737.4)), Vector3.UP)
+	move_and_slide(Common.latLonToGlobal(Vector3(1,1,1737.4)), Vector3.UP)
 	if mouse_captured:
 		Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
 	pass

+ 3 - 1
TextureLoader.gd

@@ -10,7 +10,7 @@ func _ready():
 
 func loadTexture(lat, lon):
 	lat =int(lat)
-	lon = int(lon)
+	lon = int(lon+180)%360
 	var texName = getTexName(lat, lon)
 	print(texName)
 	var image = Image.new()
@@ -25,6 +25,8 @@ func getTexName(lat, lon):
 	return "%s/m-%s-%s.png" % [filePrexif, (lat+90)%180, (lon+180)%360]
 	#return "user://grid.png"
 
+
+
 # Called every frame. 'delta' is the elapsed time since the previous frame.
 #func _process(delta):
 #	pass

+ 22 - 8
TopoLoader.gd

@@ -2,7 +2,10 @@ extends Node
 
 var Downloader = preload("res://downloader.gd")
 
-var datafile = "height/SLDEM2015_512_00N_30N_000_045_FLOAT.IMG"
+var filePrefix = "user://topo"
+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
 var lines = 15360
 var offset = 1737.4#*1000
@@ -20,16 +23,16 @@ var file: File
 # Called when the node enters the scene tree for the first time.
 func open():
 	file = File.new()
-	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)
+	print("opening topo: "+getFilename())
+	file.open(getFilename(), File.READ)
 	
 func close():
 	file.close()
-	queue_free()
+	#queue_free()
+	
+func clear():
+	file.close()
+	cache = {}
 	
 func cacheArea(latMinIN, latMaxIN, lonMinIN, lonMaxIN):
 	if not _validate(latMinIN,lonMinIN) and not _validate(latMaxIN,lonMaxIN) :
@@ -65,6 +68,17 @@ func _validate(lat,lon):
 		return true
 	return false
 
+func getFilename():
+	# example sldem2015_512_00n_30n_000_045_float.img
+	#     "%s/sldem2015_%s_%0*d%s_%0*d%s_%00*d_%00*d_float.img"
+	var orientation: String
+	if latMin >= 0:
+		orientation = "n"
+	else:
+		orientation = "s"
+	var properties = [filePrefix, resolution, latMin, orientation, latMax, orientation, lonMin, lonMax]
+	return formatString % properties
+
 # Called every frame. 'delta' is the elapsed time since the previous frame.
 #func _process(delta):
 #	pass