Browse Source

Add support for different materials per block face and added wood log block

pull/1/head
Ryan Reed 1 month ago
parent
commit
aa04fddac1
14 changed files with 174 additions and 7 deletions
  1. +9
    -0
      assets/materials/wood_ends.tres
  2. +9
    -0
      assets/materials/wood_side.tres
  3. BIN
      assets/textures/dirt-grass.png
  4. +34
    -0
      assets/textures/dirt-grass.png.import
  5. BIN
      assets/textures/wood-end.png
  6. +35
    -0
      assets/textures/wood-end.png.import
  7. BIN
      assets/textures/wood-side.png
  8. +35
    -0
      assets/textures/wood-side.png.import
  9. +8
    -1
      data_structure/block.gd
  10. +1
    -0
      data_structure/db_items.gd
  11. +3
    -1
      resources/blocks/001_dirt.tres
  12. +1
    -1
      resources/blocks/002_stone.tres
  13. +18
    -0
      resources/blocks/003_wood.tres
  14. +21
    -4
      scenes/blocks/block.gd

+ 9
- 0
assets/materials/wood_ends.tres View File

@ -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

+ 9
- 0
assets/materials/wood_side.tres View File

@ -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

BIN
assets/textures/dirt-grass.png View File

Before After
Width: 16  |  Height: 16  |  Size: 913 B

+ 34
- 0
assets/textures/dirt-grass.png.import View File

@ -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

BIN
assets/textures/wood-end.png View File

Before After
Width: 16  |  Height: 16  |  Size: 805 B

+ 35
- 0
assets/textures/wood-end.png.import View File

@ -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

BIN
assets/textures/wood-side.png View File

Before After
Width: 16  |  Height: 16  |  Size: 700 B

+ 35
- 0
assets/textures/wood-side.png.import View File

@ -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

+ 8
- 1
data_structure/block.gd View File

@ -3,4 +3,11 @@ extends ItemResource
# TODO: Replace with "missing texture" resource # 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

+ 1
- 0
data_structure/db_items.gd View File

@ -16,4 +16,5 @@ func _init() -> void:
@onready var data: Dictionary = { @onready var data: Dictionary = {
"001": preload("res://resources/blocks/001_dirt.tres"), "001": preload("res://resources/blocks/001_dirt.tres"),
"002": preload("res://resources/blocks/002_stone.tres"), "002": preload("res://resources/blocks/002_stone.tres"),
"003": preload("res://resources/blocks/003_wood.tres"),
} }

+ 3
- 1
resources/blocks/001_dirt.tres View File

@ -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="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] [resource]
script = ExtResource("1_ljghb") script = ExtResource("1_ljghb")
material_east = ExtResource("1_n1cq6")
id = "001" id = "001"
name = "Dirt" name = "Dirt"
description = "Block of dirt" description = "Block of dirt"


+ 1
- 1
resources/blocks/002_stone.tres View File

@ -5,7 +5,7 @@
[resource] [resource]
script = ExtResource("1_63t5s") script = ExtResource("1_63t5s")
material = ExtResource("1_6chm7")
material_east = ExtResource("1_6chm7")
id = "002" id = "002"
name = "Stone" name = "Stone"
description = "Block of stone" description = "Block of stone"


+ 18
- 0
resources/blocks/003_wood.tres View File

@ -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"

+ 21
- 4
scenes/blocks/block.gd View File

@ -2,9 +2,15 @@ class_name Block
extends StaticBody3D extends StaticBody3D
@onready var block_faces: Node3D = $BlockFaces
@onready var highlight_mesh: MeshInstance3D = $HighlightMesh @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 id: String
var resource: BlockResource var resource: BlockResource
@ -29,10 +35,21 @@ func set_id(block_id: String) -> void:
func _apply_materials() -> 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: func _get_resource_data() -> void:
if not id: if not id:


Loading…
Cancel
Save