diff --git a/assets/materials/wood_ends.tres b/assets/materials/wood_ends.tres new file mode 100644 index 0000000..7b03538 --- /dev/null +++ b/assets/materials/wood_ends.tres @@ -0,0 +1,9 @@ +[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://bnqiumcb3ixan"] + +[ext_resource type="Texture2D" uid="uid://dxh0tr1jn2sym" path="res://assets/textures/wood-end.png" id="1_vqb8t"] + +[resource] +albedo_texture = ExtResource("1_vqb8t") +metallic_specular = 0.0 +roughness = 0.0 +texture_filter = 0 diff --git a/assets/materials/wood_side.tres b/assets/materials/wood_side.tres new file mode 100644 index 0000000..2466568 --- /dev/null +++ b/assets/materials/wood_side.tres @@ -0,0 +1,9 @@ +[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://h0naiw6swfkl"] + +[ext_resource type="Texture2D" uid="uid://0mw651622h01" path="res://assets/textures/wood-side.png" id="1_voafl"] + +[resource] +albedo_texture = ExtResource("1_voafl") +metallic_specular = 0.0 +roughness = 0.0 +texture_filter = 0 diff --git a/assets/textures/dirt-grass.png b/assets/textures/dirt-grass.png new file mode 100644 index 0000000..ac95653 Binary files /dev/null and b/assets/textures/dirt-grass.png differ diff --git a/assets/textures/dirt-grass.png.import b/assets/textures/dirt-grass.png.import new file mode 100644 index 0000000..2573c14 --- /dev/null +++ b/assets/textures/dirt-grass.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bgo4mb3atmbot" +path="res://.godot/imported/dirt-grass.png-12fb5ebf1f814e95cc24f2d6fd063398.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/textures/dirt-grass.png" +dest_files=["res://.godot/imported/dirt-grass.png-12fb5ebf1f814e95cc24f2d6fd063398.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/assets/textures/wood-end.png b/assets/textures/wood-end.png new file mode 100644 index 0000000..f54b654 Binary files /dev/null and b/assets/textures/wood-end.png differ diff --git a/assets/textures/wood-end.png.import b/assets/textures/wood-end.png.import new file mode 100644 index 0000000..b50aa21 --- /dev/null +++ b/assets/textures/wood-end.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dxh0tr1jn2sym" +path.s3tc="res://.godot/imported/wood-end.png-880ae7062d85d2bd8bfc66b6bcdb95a8.s3tc.ctex" +metadata={ +"imported_formats": ["s3tc_bptc"], +"vram_texture": true +} + +[deps] + +source_file="res://assets/textures/wood-end.png" +dest_files=["res://.godot/imported/wood-end.png-880ae7062d85d2bd8bfc66b6bcdb95a8.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 diff --git a/assets/textures/wood-side.png b/assets/textures/wood-side.png new file mode 100644 index 0000000..3842aa5 Binary files /dev/null and b/assets/textures/wood-side.png differ diff --git a/assets/textures/wood-side.png.import b/assets/textures/wood-side.png.import new file mode 100644 index 0000000..acc49af --- /dev/null +++ b/assets/textures/wood-side.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://0mw651622h01" +path.s3tc="res://.godot/imported/wood-side.png-7d9834bbc960a2c99991aedb7dcfa31e.s3tc.ctex" +metadata={ +"imported_formats": ["s3tc_bptc"], +"vram_texture": true +} + +[deps] + +source_file="res://assets/textures/wood-side.png" +dest_files=["res://.godot/imported/wood-side.png-7d9834bbc960a2c99991aedb7dcfa31e.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 diff --git a/data_structure/block.gd b/data_structure/block.gd index 2f0e612..26ed7bf 100644 --- a/data_structure/block.gd +++ b/data_structure/block.gd @@ -3,4 +3,11 @@ extends ItemResource # TODO: Replace with "missing texture" resource -@export var material: StandardMaterial3D = preload("res://assets/materials/dirt.tres") + +## East material is also the default material if not provided +@export var material_east: StandardMaterial3D = null +@export var material_west: StandardMaterial3D = null +@export var material_north: StandardMaterial3D = null +@export var material_south: StandardMaterial3D = null +@export var material_top: StandardMaterial3D = null +@export var material_bottom: StandardMaterial3D = null diff --git a/data_structure/db_items.gd b/data_structure/db_items.gd index 4f12698..656f7b1 100644 --- a/data_structure/db_items.gd +++ b/data_structure/db_items.gd @@ -16,4 +16,5 @@ func _init() -> void: @onready var data: Dictionary = { "001": preload("res://resources/blocks/001_dirt.tres"), "002": preload("res://resources/blocks/002_stone.tres"), + "003": preload("res://resources/blocks/003_wood.tres"), } diff --git a/resources/blocks/001_dirt.tres b/resources/blocks/001_dirt.tres index d2c8aa6..3adafe2 100644 --- a/resources/blocks/001_dirt.tres +++ b/resources/blocks/001_dirt.tres @@ -1,9 +1,11 @@ -[gd_resource type="Resource" script_class="BlockResource" load_steps=2 format=3 uid="uid://bu0yoee1rs1se"] +[gd_resource type="Resource" script_class="BlockResource" load_steps=3 format=3 uid="uid://bu0yoee1rs1se"] [ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://data_structure/block.gd" id="1_ljghb"] +[ext_resource type="Material" uid="uid://uex0dq00xomt" path="res://assets/materials/dirt.tres" id="1_n1cq6"] [resource] script = ExtResource("1_ljghb") +material_east = ExtResource("1_n1cq6") id = "001" name = "Dirt" description = "Block of dirt" diff --git a/resources/blocks/002_stone.tres b/resources/blocks/002_stone.tres index 3ee0b1c..4244e16 100644 --- a/resources/blocks/002_stone.tres +++ b/resources/blocks/002_stone.tres @@ -5,7 +5,7 @@ [resource] script = ExtResource("1_63t5s") -material = ExtResource("1_6chm7") +material_east = ExtResource("1_6chm7") id = "002" name = "Stone" description = "Block of stone" diff --git a/resources/blocks/003_wood.tres b/resources/blocks/003_wood.tres new file mode 100644 index 0000000..48f02e6 --- /dev/null +++ b/resources/blocks/003_wood.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" script_class="BlockResource" load_steps=4 format=3 uid="uid://bvudydis6w27b"] + +[ext_resource type="Material" uid="uid://bnqiumcb3ixan" path="res://assets/materials/wood_ends.tres" id="1_1n8h6"] +[ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://data_structure/block.gd" id="2_1n8h6"] +[ext_resource type="Material" uid="uid://h0naiw6swfkl" path="res://assets/materials/wood_side.tres" id="2_o823h"] + +[resource] +script = ExtResource("2_1n8h6") +material_east = ExtResource("2_o823h") +material_west = ExtResource("2_o823h") +material_north = ExtResource("2_o823h") +material_south = ExtResource("2_o823h") +material_top = ExtResource("1_1n8h6") +material_bottom = ExtResource("1_1n8h6") +id = "003" +name = "Wood" +description = "Wood log" +metadata/_custom_type_script = "uid://dwrmy4mx0mw18" diff --git a/scenes/blocks/block.gd b/scenes/blocks/block.gd index bedbc4e..cf64ff2 100644 --- a/scenes/blocks/block.gd +++ b/scenes/blocks/block.gd @@ -2,9 +2,15 @@ class_name Block extends StaticBody3D -@onready var block_faces: Node3D = $BlockFaces @onready var highlight_mesh: MeshInstance3D = $HighlightMesh +@onready var east_face: MeshInstance3D = $BlockFaces/EastFace +@onready var west_face: MeshInstance3D = $BlockFaces/WestFace +@onready var north_face: MeshInstance3D = $BlockFaces/NorthFace +@onready var south_face: MeshInstance3D = $BlockFaces/SouthFace +@onready var top_face: MeshInstance3D = $BlockFaces/TopFace +@onready var bottom_face: MeshInstance3D = $BlockFaces/BottomFace + var id: String var resource: BlockResource @@ -29,10 +35,21 @@ func set_id(block_id: String) -> void: func _apply_materials() -> void: - if block_faces == null: return + if east_face == null: return + + # This could probably be improved/simplified + _apply_material(east_face, resource.material_east) + _apply_material(west_face, resource.material_west) + _apply_material(north_face, resource.material_north) + _apply_material(south_face, resource.material_south) + _apply_material(top_face, resource.material_top) + _apply_material(bottom_face, resource.material_bottom) + +func _apply_material(face: MeshInstance3D, material: StandardMaterial3D) -> void: + if material == null: + material = resource.material_east # Default to East face (first) - for face: MeshInstance3D in block_faces.get_children(): - face.set_surface_override_material(0, resource.material) + face.set_surface_override_material(0, material) func _get_resource_data() -> void: if not id: