TopoLoader.gd 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. extends Node
  2. var datafile = "user://SLDEM2015_256_60S_60N_000_360_FLOAT.IMG"
  3. var samplesPerLine = 92160
  4. var lines = 30720
  5. var offset = 1737.4
  6. var scaleFact = 1
  7. var resolution = 256
  8. var latMin = -60
  9. var latMax = 60
  10. var lonMin = 0
  11. var lonMax = 360
  12. var cache = {}
  13. var file: File
  14. # Called when the node enters the scene tree for the first time.
  15. func open():
  16. file = File.new()
  17. file.open(datafile, File.READ)
  18. func close():
  19. file.close()
  20. queue_free()
  21. func cacheArea(latMinIN, latMaxIN, lonMinIN, lonMaxIN):
  22. if not _validate(latMinIN,lonMinIN) and not _validate(latMaxIN,lonMaxIN) :
  23. print("out of scope!")
  24. return
  25. var lat = latMinIN
  26. while lat <= latMaxIN:
  27. cache[lat]={}
  28. file.seek(lat*resolution*samplesPerLine*4 + lonMinIN*resolution*4)
  29. var lon = lonMinIN
  30. while lon <= lonMaxIN:
  31. cache[lat][lon] = file.get_float()
  32. lon += 1.0/float(resolution)
  33. lat += 1.0/float(resolution)
  34. return
  35. func read(lat,lon):
  36. if _validate(lat,lon):
  37. return cache[lat][lon]
  38. else:
  39. print("out of scope!")
  40. func _validate(lat,lon):
  41. if lat <= latMax and lat >= latMin and lon <= lonMax and lon >= lonMin:
  42. return true
  43. return false
  44. # Called every frame. 'delta' is the elapsed time since the previous frame.
  45. #func _process(delta):
  46. # pass