Browse Source

switch origin

sl@cccfr.de 2 years ago
parent
commit
7282b6dd31
4 changed files with 51 additions and 34 deletions
  1. 15 10
      Main.gd
  2. 5 2
      chunk.gd
  3. 1 0
      chunk.tscn
  4. 30 22
      flat_tile.gd

+ 15 - 10
Main.gd

@@ -7,18 +7,23 @@ extends Spatial
 #var tileGenScene = preload("res://TileGenerator.tscn")
 var Chunk = preload("res://chunk.tscn")
 
-var minlat = 0
-var maxlat = 8
+var minlat = -90
+var maxlat = 90
 var minlon = 0
-var maxlon = 36
+var maxlon = 360
+var steplat = 1
+var steplon = 1
+
+var resolution = 10
+var radius = 20
 
 var curlat = 0
 var curlon = 0
 
 func _ready():
 	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
-	curlat = minlat*10
-	curlon = minlon*10
+	curlat = minlat*steplat
+	curlon = minlon*steplon
 	
 func _input(event):
 	if event.is_action_pressed("ui_cancel"):
@@ -29,16 +34,16 @@ func _input(event):
 			get_tree().set_input_as_handled()
 
 func _process(delta):
-	if curlat < maxlat*10:
-		if curlon < maxlon*10:
+	if curlat < maxlat*steplat:
+		if curlon < maxlon*steplon:
 			var chunk = Chunk.instance()
-			chunk.setParams(curlat,curlat+10,curlon,curlon+10,2)
+			chunk.setParams(curlat,curlat+steplat,curlon,curlon+steplon,resolution,radius)
 			#moontile.scale=Vector3(1000,1000,1000)
 			$Tiles.add_child(chunk)
 			.get_node("UI/3").text="lastLatLon="+str(curlat)+":"+str(curlon)
-			curlon += 10
+			curlon += steplon
 		else:
-			curlat +=10
+			curlat +=steplat
 			curlon = 0
 			if curlat >= maxlat:
 				print("loading complete")

+ 5 - 2
chunk.gd

@@ -9,18 +9,21 @@ var latMax:float = 1
 var lonMin:float = 0.0
 var lonMax:float = 1.0
 var resolution:int = 512
+var radius:float = 10
 
-func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN):
+func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float):
 	latMin = latMinIN
 	latMax = latMaxIN
 	lonMin = lonMinIN
 	lonMax = lonMaxIN
 	resolution = resolutionIN
+	radius = radiusIN
 	
 # Called when the node enters the scene tree for the first time.
 func _ready():
-	.get_node("Mesh").setParams(latMin, latMax, lonMin, lonMax, resolution)
+	.get_node("Mesh").setParams(latMin, latMax, lonMin, lonMax, resolution, radius)
 	.get_node("Mesh").genMesh()
+	.translate(.get_node("Mesh").origin)
 
 # Called every frame. 'delta' is the elapsed time since the previous frame.
 #func _process(delta):

+ 1 - 0
chunk.tscn

@@ -7,4 +7,5 @@
 script = ExtResource( 1 )
 
 [node name="Mesh" type="MeshInstance" parent="."]
+use_in_baked_light = true
 script = ExtResource( 2 )

+ 30 - 22
flat_tile.gd

@@ -9,12 +9,15 @@ var lonMax:float = 1.0
 var resolution:int = 512
 var radius:float = 10
 
-func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN):	
+var origin:Vector3
+
+func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float):	
 	latMin = latMinIN
 	latMax = latMaxIN
 	lonMin = lonMinIN
 	lonMax = lonMaxIN
 	resolution = resolutionIN
+	radius = radiusIN
 
 func _ready():
 	pass
@@ -22,33 +25,36 @@ func _ready():
 	#self.genMesh()
 	
 func genMesh():
-	print("generating Mesh:")
-	print("latMin: " + str(latMin))
-	print("latMax: " + str(latMax))
-	print("lonMin: " + str(lonMin))
-	print("lonMax: " + str(lonMax))
-	print("resolution: " + str(resolution))
+	#print("generating Mesh:")
+	#print("latMin: " + str(latMin))
+	#print("latMax: " + str(latMax))
+	#print("lonMin: " + str(lonMin))
+	#print("lonMax: " + str(lonMax))
+	#print("resolution: " + str(resolution))
 	
 	var verts = convertToCartesian(genSphereCoords())
 	var arr = []
 	arr.resize(Mesh.ARRAY_MAX)
 	arr[Mesh.ARRAY_VERTEX] = verts
-	#arr[Mesh.ARRAY_TEX_UV] = genUV()
+	arr[Mesh.ARRAY_TEX_UV] = genUV()
 	arr[Mesh.ARRAY_NORMAL] = genNormals(verts)
 	arr[Mesh.ARRAY_INDEX] = genIndex()
 	mesh = Mesh.new()
 	mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
+	var mat = SpatialMaterial.new()
+	mat.albedo_color = Color(0.7,0.7,0.7,1)
+	mesh.surface_set_material(0,mat)
 	
-	var drawBubbles = true
+	var drawBubbles = false
 	if drawBubbles:
 		var i = 0.0
 		for vert in verts:
 			var point = Point.instance()
 			point.translate(vert)
-			var mat = SpatialMaterial.new()#point.mesh.surface_get_material(0)
+			var pointMat = SpatialMaterial.new()#point.mesh.surface_get_material(0)
 			mat.albedo_color = Color(i,0,0,1)
 			i+=0.1
-			point.mesh.surface_set_material(0,mat)
+			point.mesh.surface_set_material(0,pointMat)
 			.get_parent().add_child(point)
 
 func genNormals(verts:PoolVector3Array):
@@ -58,8 +64,8 @@ func genNormals(verts:PoolVector3Array):
 	for vert in verts:
 		normals[v_idx] = vert.normalized()
 		v_idx+=1
-	print("normals")
-	print(len(normals))
+	#print("normals")
+	#print(len(normals))
 	return normals
 
 func genUV():
@@ -70,8 +76,8 @@ func genUV():
 		var y = v_idx / resolution
 		var x = v_idx % resolution
 		uvs[v_idx]=Vector2(clamp(x, 0, resolution),clamp(y, 0, resolution))
-	print("uv")
-	print(len(uvs))
+	#print("uv")
+	#print(len(uvs))
 	return uvs
 	
 
@@ -98,8 +104,8 @@ func genIndex():
 			indices[i_idx] = v_idx + 1
 			i_idx+=1
 		
-	print("indices")
-	print(len(indices))
+	#print("indices")
+	#print(len(indices))
 	return indices
 		
 func genSphereCoords():
@@ -123,8 +129,8 @@ func genSphereCoords():
 	#		v_idx+=1
 	#		lon += (lonMax-lonMin)/resolution
 	#	lat += (latMax-latMin)/resolution
-	print("verts")
-	print(len(verts))
+	#print("verts")
+	#print(len(verts))
 	return verts
 
 
@@ -133,8 +139,10 @@ func convertToCartesian(verts:PoolVector3Array):
 	carVerts.resize(len(verts))
 	var v_idx = 0
 	for vert in verts:
-		carVerts[v_idx] = Common.latLonToGlobal(vert.x, vert.y, vert.z, Vector3(), Vector3())
+		if not origin:
+			origin = vert			
+		carVerts[v_idx] = Common.latLonToGlobal(vert.x, vert.y, vert.z, Vector3(), origin)
 		v_idx+=1
-	print("Cartesian")
-	print(len(carVerts))
+	#print("Cartesian")
+	#print(len(carVerts))
 	return carVerts