|
@@ -4,6 +4,7 @@ var Point = preload("res://point.tscn")
|
|
var TopoLoader = preload("res://TopoLoader.gd")
|
|
var TopoLoader = preload("res://TopoLoader.gd")
|
|
var tl
|
|
var tl
|
|
var TextureLoader = preload("res://TextureLoader.gd")
|
|
var TextureLoader = preload("res://TextureLoader.gd")
|
|
|
|
+var texl
|
|
|
|
|
|
var groundShader = preload("res://shader/ground_shader.tres") as ShaderMaterial
|
|
var groundShader = preload("res://shader/ground_shader.tres") as ShaderMaterial
|
|
|
|
|
|
@@ -18,6 +19,10 @@ var scaleFact:int = 1
|
|
var origin:Vector3
|
|
var origin:Vector3
|
|
var center:Vector3
|
|
var center:Vector3
|
|
|
|
|
|
|
|
+var heightmap:Image
|
|
|
|
+var overlay_heightmap = false
|
|
|
|
+var mat:ShaderMaterial
|
|
|
|
+
|
|
var initialized = false
|
|
var initialized = false
|
|
|
|
|
|
func initialize(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float, scaleIN):
|
|
func initialize(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float, scaleIN):
|
|
@@ -42,6 +47,16 @@ func _ready():
|
|
#genMesh called from chunk
|
|
#genMesh called from chunk
|
|
#self.genMesh()
|
|
#self.genMesh()
|
|
|
|
|
|
|
|
+func initTexture():
|
|
|
|
+ texl = TextureLoader.new()
|
|
|
|
+ var exists = texl.open(latMin, lonMin)
|
|
|
|
+ return exists
|
|
|
|
+
|
|
|
|
+func _process(delta):
|
|
|
|
+ if Input.is_action_just_pressed("overlay"):
|
|
|
|
+ overlay_heightmap = not overlay_heightmap
|
|
|
|
+ mat.set_shader_param("overlay_heightmap", overlay_heightmap)
|
|
|
|
+
|
|
func genMesh():
|
|
func genMesh():
|
|
#print("generating Mesh:")
|
|
#print("generating Mesh:")
|
|
#print("latMin: " + str(latMin))
|
|
#print("latMin: " + str(latMin))
|
|
@@ -59,10 +74,13 @@ func genMesh():
|
|
arr[Mesh.ARRAY_INDEX] = genIndex()
|
|
arr[Mesh.ARRAY_INDEX] = genIndex()
|
|
mesh = Mesh.new()
|
|
mesh = Mesh.new()
|
|
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
|
|
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
|
|
- var mat = groundShader.duplicate()
|
|
|
|
|
|
+ mat = groundShader.duplicate()
|
|
#mat.albedo_color = Color(0.7,0.7,0.7,1)
|
|
#mat.albedo_color = Color(0.7,0.7,0.7,1)
|
|
- var texl = TextureLoader.new()
|
|
|
|
- mat.set_shader_param("texture_albedo_big", texl.loadTexture(latMin, lonMin))
|
|
|
|
|
|
+ mat.set_shader_param("texture_albedo_big", texl.loadTexture())
|
|
|
|
+ heightmap = tl.createHeightmap()
|
|
|
|
+ var heighttex = ImageTexture.new()
|
|
|
|
+ heighttex.create_from_image(heightmap, 0)
|
|
|
|
+ mat.set_shader_param("texture_heightmap", heighttex)
|
|
mesh.surface_set_material(0,mat)
|
|
mesh.surface_set_material(0,mat)
|
|
.create_trimesh_collision()
|
|
.create_trimesh_collision()
|
|
|
|
|
|
@@ -150,7 +168,11 @@ func genSphereCoords():
|
|
for x in range(0,resolution+1):
|
|
for x in range(0,resolution+1):
|
|
var lat = latMin+latStep*y
|
|
var lat = latMin+latStep*y
|
|
var lon = lonMin+lonStep*x
|
|
var lon = lonMin+lonStep*x
|
|
- verts[v_idx] = Vector3(lat, lon, radius+tl.read(lat,lon)*scaleFact)
|
|
|
|
|
|
+ var height = tl.read(lat,lon)
|
|
|
|
+ if not height and height != 0:
|
|
|
|
+ push_error("could not get height")
|
|
|
|
+ return
|
|
|
|
+ verts[v_idx] = Vector3(lat, lon, radius+height*scaleFact)
|
|
v_idx+=1
|
|
v_idx+=1
|
|
tl.close()
|
|
tl.close()
|
|
return verts
|
|
return verts
|