瀏覽代碼

minor improvements

sl@cccfr.de 2 年之前
父節點
當前提交
a15118609a
共有 2 個文件被更改,包括 19 次插入16 次删除
  1. 1 1
      Main.gd
  2. 18 15
      flat_tile.gd

+ 1 - 1
Main.gd

@@ -32,7 +32,7 @@ func _process(delta):
 	if curlat < maxlat*30:
 		if curlon < maxlon*60:
 			var chunk = Chunk.instance()
-			chunk.setParams(curlat,curlat+30,curlon,curlon+60,4)
+			chunk.setParams(curlat,curlat+30,curlon,curlon+60,2)
 			#moontile.scale=Vector3(1000,1000,1000)
 			$Tiles.add_child(chunk)
 			.get_node("UI/3").text="lastLatLon="+str(curlat)+":"+str(curlon)

+ 18 - 15
flat_tile.gd

@@ -39,6 +39,7 @@ func genMesh():
 	mesh = Mesh.new()
 	mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
 	
+	
 	var i = 0.0
 	for vert in verts:
 		var point = Point.instance()
@@ -75,13 +76,11 @@ func genUV():
 
 func genIndex():
 	var indices = PoolIntArray()
-	indices.resize(6* (resolution+1) * (resolution+1)*6)
+	indices.resize(6* ((resolution+1) * (resolution+1)))
 	
 	var i_idx = 0
-	var row = 0
-	while row < resolution:
-		var col = 0
-		while col < resolution:
+	for row in range(0, resolution+1):
+		for col in range(0,resolution+1):
 			var v_idx = row*(resolution+1)+col
 			
 			indices[i_idx] = v_idx
@@ -97,9 +96,6 @@ func genIndex():
 			i_idx+=1
 			indices[i_idx] = v_idx + 1
 			i_idx+=1
-			
-			col += 1
-		row += 1
 		
 	print("indices")
 	print(len(indices))
@@ -110,15 +106,22 @@ func genSphereCoords():
 	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
-	var lat := float(latMin)
-	while lat <= float(latMax):
-		var lon := float(lonMin)
-		while lon <= float(lonMax):
-			verts[v_idx] = Vector3(lat, lon, radius)
+	for y in range(0,resolution+1):
+		for x in range(0,resolution+1):
+			verts[v_idx] = Vector3(latMin+latStep*y, lonMin+lonStep*x, radius)
 			v_idx+=1
-			lon += (lonMax-lonMin)/resolution
-		lat += (latMax-latMin)/resolution
+	#var v_idx = 0
+	#var lat := float(latMin)
+	#while lat <= float(latMax):
+	#	var lon := float(lonMin)
+	#	while lon <= float(lonMax):
+	#		verts[v_idx] = Vector3(lat, lon, radius)
+	#		v_idx+=1
+	#		lon += (lonMax-lonMin)/resolution
+	#	lat += (latMax-latMin)/resolution
 	print("verts")
 	print(len(verts))
 	return verts