From: MarStr Date: Sun, 10 Nov 2024 12:50:09 +0000 (+0100) Subject: Initial commit with correct working GD script X-Git-Url: https://marstr.online/code/gitweb.cgi?a=commitdiff_plain;h=cd5fe6096348b6084c853e9ae6c6147f6b03bd70;p=lidar Initial commit with correct working GD script --- cd5fe6096348b6084c853e9ae6c6147f6b03bd70 diff --git a/N51E007.hgt b/N51E007.hgt new file mode 100644 index 0000000..5344159 Binary files /dev/null and b/N51E007.hgt differ diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..9d8b7fa --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..7f086b3 --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://516p06wj654n" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/lidar.gd b/lidar.gd new file mode 100644 index 0000000..af0cd74 --- /dev/null +++ b/lidar.gd @@ -0,0 +1,106 @@ +@tool +extends MeshInstance3D +@export var update=false + +var height = Array() +var grid +var lng_w +var lat_l = 111.321 +var v_step +var h_step + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + _getHeights() + _widthOfLongitude(51) + v_step = grid / lat_l + h_step = ((lng_w/1000) / lat_l) * v_step + _generateTerrain() + + +func _getHeights(): + if FileAccess.file_exists("res://N51E007.hgt"): + var file = FileAccess.open("res://N51E007.hgt", FileAccess.READ) + file.big_endian = true + var size = file.get_length() + grid = int(sqrt(size/2)) + #uv_step = 1 / grid + for x in range(0, grid): + var row = Array() + for y in range(0, grid): + row.append(file.get_16()) + height.append(row) + height.reverse() + + +func _widthOfLongitude(lng): + var dm = cos(deg_to_rad(lng)) * lat_l + lng_w = round(dm * 1000) + + +func _generateTerrain(): + var a_mesh = ArrayMesh.new() + var verts := PackedVector3Array() + var indices := PackedInt32Array() + var normals := PackedVector3Array() + var curind = 0 + + for x in range(0, grid-2): + for y in range(0, grid-2): + var xp = x*h_step + var yp = y*v_step + var v1 = Vector3(xp, _getHeight(x, y), -yp) + var v2 = Vector3(xp, _getHeight(x, y+1), -yp-v_step) + var v3 = Vector3(xp+h_step, _getHeight(x+1, y), -yp) + + var side1 = v2-v1 + var side2 = v2-v3 + var normal1 = side1.cross(side2) + + var v4 = Vector3(xp, _getHeight(x, y+1), -yp-v_step) + var v5 = Vector3(xp+h_step, _getHeight(x+1, y+1), -yp-v_step) + var v6 = Vector3(xp+h_step, _getHeight(x+1, y), -yp) + + var side3 = v5-v4 + var side4 = v5-v6 + var normal2 = side3.cross(side4) + + verts.append(v1) + verts.append(v2) + verts.append(v3) + verts.append(v4) + verts.append(v5) + verts.append(v6) + + normals.append(normal1) + normals.append(normal1) + normals.append(normal1) + normals.append(normal2) + normals.append(normal2) + normals.append(normal2) + + indices.append(curind+0) + indices.append(curind+1) + indices.append(curind+2) + indices.append(curind+3) + indices.append(curind+4) + indices.append(curind+5) + curind = curind+6 + + var array = [] + array.resize(Mesh.ARRAY_MAX) + array[Mesh.ARRAY_VERTEX] = verts + array[Mesh.ARRAY_INDEX] = indices + array[Mesh.ARRAY_NORMAL] = normals + a_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, array) + mesh = a_mesh + + + +func _getHeight(x, y): + return height[y][x] + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/lidar.tres b/lidar.tres new file mode 100644 index 0000000..c19ebbd --- /dev/null +++ b/lidar.tres @@ -0,0 +1,4 @@ +[gd_resource type="StandardMaterial3D" format=3 uid="uid://csub3tefbxyos"] + +[resource] +emission = Color(1, 1, 1, 1) diff --git a/lidar.tscn b/lidar.tscn new file mode 100644 index 0000000..11caba6 --- /dev/null +++ b/lidar.tscn @@ -0,0 +1,28 @@ +[gd_scene load_steps=4 format=3 uid="uid://bycv6uqx3ruk8"] + +[ext_resource type="Script" path="res://lidar.gd" id="1_54dbw"] + +[sub_resource type="Environment" id="Environment_ngpq5"] +background_mode = 1 +background_color = Color(0.58581, 0.673741, 0.868176, 1) + +[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_c0u6f"] + +[node name="Node3D" type="Node3D"] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +script = ExtResource("1_54dbw") + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(-1, -8.74228e-08, 2.5411e-21, -3.82137e-15, 4.37114e-08, 1, -8.74228e-08, 1, -4.37114e-08, 0, 99.8156, 0) +current = true +far = 60000.0 + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_ngpq5") +camera_attributes = SubResource("CameraAttributesPractical_c0u6f") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 0.72118, 0.692748, 0, -0.692748, 0.72118, 16.4428, 103.755, 12.2305) +light_energy = 0.405 +shadow_enabled = true diff --git a/lidar.tscn-0igfeB b/lidar.tscn-0igfeB new file mode 100644 index 0000000..e69de29 diff --git a/lidar.tscn-1SXUtf b/lidar.tscn-1SXUtf new file mode 100644 index 0000000..e69de29 diff --git a/lidar.tscn-TLMdhn b/lidar.tscn-TLMdhn new file mode 100644 index 0000000..e69de29 diff --git a/lidar.tscn-ZmJlrG b/lidar.tscn-ZmJlrG new file mode 100644 index 0000000..e69de29 diff --git a/lidar.tscn-gy9kfh b/lidar.tscn-gy9kfh new file mode 100644 index 0000000..e69de29 diff --git a/lidar.tscn-hPkEpt b/lidar.tscn-hPkEpt new file mode 100644 index 0000000..e69de29 diff --git a/lidar.tscn-lW8qDe b/lidar.tscn-lW8qDe new file mode 100644 index 0000000..e69de29 diff --git a/lidar.tscn-pHKR72 b/lidar.tscn-pHKR72 new file mode 100644 index 0000000..e69de29 diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..bb1409c --- /dev/null +++ b/project.godot @@ -0,0 +1,16 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="lidar" +run/main_scene="res://lidar.tscn" +config/features=PackedStringArray("4.3", "Forward Plus") +config/icon="res://icon.svg"