Browse Source

fix texture mapping

sl@cccfr.de 2 years ago
parent
commit
219d2de17c
5 changed files with 14 additions and 12 deletions
  1. 4 4
      Main.gd
  2. 1 1
      Player.gd
  3. 2 4
      TextureLoader.gd
  4. 5 1
      TopoLoader.gd
  5. 2 2
      flat_tile.gd

+ 4 - 4
Main.gd

@@ -7,10 +7,10 @@ extends Spatial
 #var tileGenScene = preload("res://TileGenerator.tscn")
 var Chunk = preload("res://chunk.tscn")
 
-var minlat = 0
-var maxlat = 2
-var minlon = 0
-var maxlon = 2
+var minlat = 24
+var maxlat = 26
+var minlon = 2
+var maxlon = 4
 var steplat = 1
 var steplon = 1
 

+ 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(1,1,1737.4)), Vector3.UP)
+	move_and_slide(Common.latLonToGlobal(Vector3(24,2,1737.4)), Vector3.UP)
 	if mouse_captured:
 		Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
 	pass

+ 2 - 4
TextureLoader.gd

@@ -9,8 +9,6 @@ func _ready():
 	pass # Replace with function body.
 
 func loadTexture(lat, lon):
-	lat =int(lat)
-	lon = int(lon+180)%360
 	var texName = getTexName(lat, lon)
 	print(texName)
 	var image = Image.new()
@@ -22,8 +20,8 @@ func loadTexture(lat, lon):
 	return tex
 	
 func getTexName(lat, lon):
-	return "%s/m-%s-%s.png" % [filePrexif, (lat+90)%180, (lon+180)%360]
-	#return "user://grid.png"
+	return "%s/m-%s-%s.png" % [filePrexif, (int(lat)+90)%180, (int(lon)+180)%360]
+	#return "res://tex/grid.png"
 
 
 

+ 5 - 1
TopoLoader.gd

@@ -21,7 +21,11 @@ var cache = {}
 var file: File
 
 # Called when the node enters the scene tree for the first time.
-func open():
+func open(latMinIN, lonMinIn):
+	latMin = (int(latMinIN)/30) * 30
+	latMax = latMin+30
+	lonMin = (int(lonMinIn)/45) * 45
+	lonMax = lonMin+45
 	file = File.new()
 	print("opening topo: "+getFilename())
 	file.open(getFilename(), File.READ)

+ 2 - 2
flat_tile.gd

@@ -83,7 +83,7 @@ func genUV():
 			var y = float(_y)
 			var x = float(_x)
 			var devider = float(resolution+1)
-			uvs[v_idx] = Vector2(x/devider,y/devider)
+			uvs[v_idx] = Vector2(x/devider,1-(y/devider))
 			v_idx+=1
 	
 	#for v_idx in range(0,(resolution+1) * (resolution+1)):
@@ -125,7 +125,7 @@ func genIndex():
 func genSphereCoords():
 	var tl = TopoLoader.new()
 	add_child(tl)
-	tl.open()
+	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