diff --git a/Art/Stone_11-128x128.png b/Art/Stone_11-128x128.png new file mode 100644 index 0000000..258c854 --- /dev/null +++ b/Art/Stone_11-128x128.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6fff9a20e60041bd1753607abbea69d6a0cc8448089e4c18ddeae9145eb48e9c +size 29097 diff --git a/Art/Stone_11-128x128.png.import b/Art/Stone_11-128x128.png.import new file mode 100644 index 0000000..6440107 --- /dev/null +++ b/Art/Stone_11-128x128.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://eempmja460l5" +path="res://.godot/imported/Stone_11-128x128.png-74289798a2555c4732a5c0fbe1b7230c.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Art/Stone_11-128x128.png" +dest_files=["res://.godot/imported/Stone_11-128x128.png-74289798a2555c4732a5c0fbe1b7230c.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 diff --git a/Scripts/Space/SpaceRegion.gd b/Scripts/Space/SpaceRegion.gd index 3907326..20e1bab 100644 --- a/Scripts/Space/SpaceRegion.gd +++ b/Scripts/Space/SpaceRegion.gd @@ -17,6 +17,28 @@ func _generate_geometry(space: Space, looked_from_inside: bool) -> Node3D: var geometry := MeshInstance3D.new() geometry.name = name + var mesh := ArrayMesh.new() + mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, _generate_wall_arrays(space, looked_from_inside)) + mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, _generate_floor_arrays(space)) + + var wall_material := StandardMaterial3D.new() + wall_material.albedo_texture = wall_texture + mesh.surface_set_material(0, wall_material) + + var floor_material := StandardMaterial3D.new() + floor_material.albedo_texture = floor_texture + mesh.surface_set_material(1, floor_material) + + geometry.mesh = mesh + + for child in get_children(): + if child is SpaceRegion: + geometry.add_child(child._generate_geometry(space, not looked_from_inside)) + + return geometry + + +func _generate_wall_arrays(space: Space, looked_from_inside: bool) -> Array: var polygon = self.polygon var polygon_pairs = Array() for i in range(-1, polygon.size() - 1): @@ -31,22 +53,8 @@ func _generate_geometry(space: Space, looked_from_inside: bool) -> Node3D: arrays.resize(Mesh.ARRAY_MAX) arrays[Mesh.ARRAY_VERTEX] = vertices arrays[Mesh.ARRAY_TEX_UV] = uvs - - var mesh := ArrayMesh.new() - mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays) - - var new_material := preload("res://Scenes/RegionMaterial.tres") - new_material.albedo_texture = wall_texture - - mesh.surface_set_material(0, new_material) - - geometry.mesh = mesh - - for child in get_children(): - if child is SpaceRegion: - geometry.add_child(child._generate_geometry(space, not looked_from_inside)) - - return geometry + + return arrays func _push_line(space: Space, @@ -79,3 +87,26 @@ func _push_line(space: Space, uvs.append(Vector2(1, 0)) uvs.append(Vector2(0, 1)) uvs.append(Vector2(0, 0)) + + +func _generate_floor_arrays(space: Space) -> Array: + var triangulation := Geometry2D.triangulate_polygon(self.polygon) + var vertices := PackedVector3Array() + var uvs := PackedVector2Array() + vertices.resize(triangulation.size()) + uvs.resize(triangulation.size()) + + for i in range(triangulation.size()): + vertices[i] = Vector3( + self.polygon[triangulation[i]].x * space.unit_scale, + elevation * space.unit_scale, + self.polygon[triangulation[i]].y * space.unit_scale, + ) + uvs[i] = self.polygon[triangulation[i]] * space.unit_scale + + var arrays := Array() + arrays.resize(Mesh.ARRAY_MAX) + arrays[Mesh.ARRAY_VERTEX] = vertices + arrays[Mesh.ARRAY_TEX_UV] = uvs + + return arrays diff --git a/Spaces/Dungeon.tscn b/Spaces/Dungeon.tscn index ebf81b1..74bb6ef 100644 --- a/Spaces/Dungeon.tscn +++ b/Spaces/Dungeon.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=7 format=3 uid="uid://deff7lt34nj0h"] +[gd_scene load_steps=8 format=3 uid="uid://deff7lt34nj0h"] [ext_resource type="Script" path="res://Scripts/Space/Space.gd" id="1_ckp7u"] [ext_resource type="Script" path="res://Scripts/Space/SpaceRegion.gd" id="2_s3h7s"] [ext_resource type="Texture2D" uid="uid://h0skytm8grcu" path="res://icon.svg" id="3_7vff1"] [ext_resource type="Texture2D" uid="uid://icmmuqquxhq3" path="res://Art/Stone_06-128x128.png" id="3_ondo6"] [ext_resource type="Texture2D" uid="uid://buoupwtftxjse" path="res://Art/Stone_05-128x128.png" id="3_r08k8"] +[ext_resource type="Texture2D" uid="uid://eempmja460l5" path="res://Art/Stone_11-128x128.png" id="4_mnswr"] [ext_resource type="Script" path="res://Scripts/Space/SpaceSpawn.gd" id="4_rhl23"] [node name="Dungeon" type="Node2D"] @@ -15,7 +16,7 @@ position = Vector2(-30, -8) polygon = PackedVector2Array(30, 72, 262, 32, 497, 192, 286, 328, 94, 264) script = ExtResource("2_s3h7s") wall_texture = ExtResource("3_ondo6") -floor_texture = ExtResource("3_r08k8") +floor_texture = ExtResource("4_mnswr") [node name="Column" type="Polygon2D" parent="Room"] position = Vector2(78, -8)