specification of region wall texture, ability to have nested regions, unshaded region material

This commit is contained in:
veclav talica 2024-08-02 03:11:18 +03:00
parent 88af9b13d6
commit 77892c47e4
10 changed files with 151 additions and 41 deletions

3
.gitattributes vendored Normal file
View File

@ -0,0 +1,3 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
*.png filter=lfs diff=lfs merge=lfs -text

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Godot 4+ specific ignores
.godot/

BIN
Art/Stone_05-128x128.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://buoupwtftxjse"
path.s3tc="res://.godot/imported/Stone_05-128x128.png-6e57d717d543c3c7c2a521569c0b2f7c.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://Art/Stone_05-128x128.png"
dest_files=["res://.godot/imported/Stone_05-128x128.png-6e57d717d543c3c7c2a521569c0b2f7c.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
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=0

BIN
Art/Stone_06-128x128.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://icmmuqquxhq3"
path="res://.godot/imported/Stone_06-128x128.png-1430bdd7db0c859489b2b90bbc7ac88e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Art/Stone_06-128x128.png"
dest_files=["res://.godot/imported/Stone_06-128x128.png-1430bdd7db0c859489b2b90bbc7ac88e.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

View File

@ -1,7 +0,0 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://bb47mhgbxy3cw"]
[ext_resource type="Texture2D" uid="uid://h0skytm8grcu" path="res://icon.svg" id="1_2jq3x"]
[resource]
albedo_texture = ExtResource("1_2jq3x")
texture_filter = 1

View File

@ -0,0 +1,8 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://bb47mhgbxy3cw"]
[ext_resource type="Texture2D" uid="uid://buoupwtftxjse" path="res://Art/Stone_05-128x128.png" id="1_cgxdm"]
[resource]
shading_mode = 0
albedo_texture = ExtResource("1_cgxdm")
texture_filter = 0

View File

@ -5,9 +5,15 @@ class_name SpaceRegion
@export var elevation: float = 0.0 @export var elevation: float = 0.0
@export var height: float = 100.0 @export var height: float = 100.0
@export var wall_texture: Texture2D
@export var floor_texture: Texture2D
func generate_geometry(space: Space) -> Node3D: func generate_geometry(space: Space) -> Node3D:
return _generate_geometry(space, true)
func _generate_geometry(space: Space, looked_from_inside: bool) -> Node3D:
var geometry := MeshInstance3D.new() var geometry := MeshInstance3D.new()
geometry.name = name geometry.name = name
@ -19,46 +25,57 @@ func generate_geometry(space: Space) -> Node3D:
var vertices = PackedVector3Array() var vertices = PackedVector3Array()
var uvs = PackedVector2Array() var uvs = PackedVector2Array()
for line in polygon_pairs: for line in polygon_pairs:
vertices.append(Vector3( _push_line(space, line, vertices, uvs, looked_from_inside)
var arrays := Array()
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
func _push_line(space: Space,
line: Array,
vertices: PackedVector3Array,
uvs: PackedVector2Array,
looked_from_inside: bool
):
var v0 := Vector3(
line[0][0] * space.unit_scale, elevation * space.unit_scale, line[0][0] * space.unit_scale, elevation * space.unit_scale,
line[0][1] * space.unit_scale line[0][1] * space.unit_scale)
)) var v1 := Vector3(
vertices.append(Vector3(
line[1][0] * space.unit_scale, (elevation + height) * space.unit_scale, line[1][0] * space.unit_scale, (elevation + height) * space.unit_scale,
line[1][1] * space.unit_scale, line[1][1] * space.unit_scale)
)) var v2 := Vector3(
vertices.append(Vector3(
line[1][0] * space.unit_scale, elevation * space.unit_scale, line[1][0] * space.unit_scale, elevation * space.unit_scale,
line[1][1] * space.unit_scale, line[1][1] * space.unit_scale)
)) var v3 := Vector3(
vertices.append(Vector3(
line[1][0] * space.unit_scale, (elevation + height) * space.unit_scale,
line[1][1] * space.unit_scale,
))
vertices.append(Vector3(
line[0][0] * space.unit_scale, elevation * space.unit_scale,
line[0][1] * space.unit_scale,
))
vertices.append(Vector3(
line[0][0] * space.unit_scale, (elevation + height) * space.unit_scale, line[0][0] * space.unit_scale, (elevation + height) * space.unit_scale,
line[0][1] * space.unit_scale, line[0][1] * space.unit_scale)
))
if looked_from_inside:
vertices.append_array([v0, v1, v2, v1, v0, v3])
else:
vertices.append_array([v0, v2, v1, v1, v3, v0])
uvs.append(Vector2(0, 1)) uvs.append(Vector2(0, 1))
uvs.append(Vector2(1, 0)) uvs.append(Vector2(1, 0))
uvs.append(Vector2(1, 1)) uvs.append(Vector2(1, 1))
uvs.append(Vector2(1, 0)) uvs.append(Vector2(1, 0))
uvs.append(Vector2(0, 1)) uvs.append(Vector2(0, 1))
uvs.append(Vector2(0, 0)) uvs.append(Vector2(0, 0))
var arrays = Array()
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)
mesh.surface_set_material(0, preload("res://Scenes/Material.tres"))
geometry.mesh = mesh
return geometry

View File

@ -1,8 +1,10 @@
[gd_scene load_steps=5 format=3 uid="uid://deff7lt34nj0h"] [gd_scene load_steps=7 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/Space.gd" id="1_ckp7u"]
[ext_resource type="Script" path="res://Scripts/Space/SpaceRegion.gd" id="2_s3h7s"] [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://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="Script" path="res://Scripts/Space/SpaceSpawn.gd" id="4_rhl23"] [ext_resource type="Script" path="res://Scripts/Space/SpaceSpawn.gd" id="4_rhl23"]
[node name="Dungeon" type="Node2D"] [node name="Dungeon" type="Node2D"]
@ -12,6 +14,16 @@ script = ExtResource("1_ckp7u")
position = Vector2(-30, -8) position = Vector2(-30, -8)
polygon = PackedVector2Array(30, 72, 262, 32, 497, 192, 286, 328, 94, 264) polygon = PackedVector2Array(30, 72, 262, 32, 497, 192, 286, 328, 94, 264)
script = ExtResource("2_s3h7s") script = ExtResource("2_s3h7s")
wall_texture = ExtResource("3_ondo6")
floor_texture = ExtResource("3_r08k8")
[node name="Column" type="Polygon2D" parent="Room"]
position = Vector2(78, -8)
color = Color(0.665891, 0.820479, 1, 1)
polygon = PackedVector2Array(222, 168, 272, 136, 318, 184, 294, 232, 230, 216)
script = ExtResource("2_s3h7s")
wall_texture = ExtResource("3_r08k8")
floor_texture = ExtResource("3_r08k8")
[node name="Spawn" type="Sprite2D" parent="."] [node name="Spawn" type="Sprite2D" parent="."]
position = Vector2(72, 104) position = Vector2(72, 104)