feat: Show buildings in chunk properly

This commit is contained in:
Dendy 2026-03-05 22:25:54 +01:00
parent 4d1dbe2195
commit 3620a95b8b
4 changed files with 35 additions and 8 deletions

View File

@ -7,17 +7,27 @@ script/source = "extends Node3D
const COLORS = [
Color.DARK_KHAKI,
Color.ANTIQUE_WHITE,
Color.CADET_BLUE,
Color.FOREST_GREEN,
Color.GRAY,
Color.WHITE,
Color.CHOCOLATE
]
func _ready():
var mat = $\"8/Mesh\".get_surface_override_material(0)
var orig_mat = $\"8/Mesh\".get_surface_override_material(0)
var rand_color = COLORS.pick_random()
mat.albedo_color = rand_color
var new_mat = orig_mat.duplicate()
new_mat.albedo_color = rand_color
# Set color
for floor_node: Node3D in get_children():
for mesh: MeshInstance3D in floor_node.get_children():
if orig_mat != mesh.get_surface_override_material(0):
continue
mesh.set_surface_override_material(0, new_mat)
# Set height
var last_floor = str(randi_range(3, 8))
for floor_node: Node3D in get_children():
if floor_node.name == last_floor:

View File

@ -6,6 +6,7 @@ var exits: Array = [false, false, false, false]
const STREET_WIDTH: float = 40
@onready var exit_area = $BuildingAreas/B_area_E/Collision
@onready var building_area = $BuildingAreas/B_area/Collision
var building_scn = preload("res://building.tscn")
func _ready() -> void:
$Mesh.mesh.size.x = Global.chunk_size
@ -56,6 +57,7 @@ func update() -> void:
m.mesh = arr_mesh
add_child(m)
$BuildingAreas/B_area_N/Collision.disabled = true
$BuildingAreas/B_area_N.visible = false
if i == 1: #s
var vertices = PackedVector3Array()
vertices.push_back(Vector3(-STREET_WIDTH/2, 0.5, 0))
@ -76,6 +78,7 @@ func update() -> void:
m.mesh = arr_mesh
add_child(m)
$BuildingAreas/B_area_S/Collision.disabled = true
$BuildingAreas/B_area_S.visible = false
if i == 2: #w
var vertices = PackedVector3Array()
vertices.push_back(Vector3(-Global.chunk_size/2, 0.5, -STREET_WIDTH/2))
@ -96,6 +99,7 @@ func update() -> void:
m.mesh = arr_mesh
add_child(m)
$BuildingAreas/B_area_W/Collision.disabled = true
$BuildingAreas/B_area_W.visible = false
if i == 3: #e
var vertices = PackedVector3Array()
vertices.push_back(Vector3(0, 0.5, -STREET_WIDTH/2))
@ -116,6 +120,7 @@ func update() -> void:
m.mesh = arr_mesh
add_child(m)
$BuildingAreas/B_area_E/Collision.disabled = true
$BuildingAreas/B_area_E.visible = false
var center_mesh = MeshInstance3D.new()
center_mesh.position = Vector3(0,0.6,0)

View File

@ -1,6 +1,7 @@
[gd_scene format=3 uid="uid://cqbu5r5pmnhc"]
[ext_resource type="Script" uid="uid://ndadug5eerju" path="res://chunk.gd" id="1_kdh3y"]
[ext_resource type="PackedScene" uid="uid://da60ofnpg72ua" path="res://building.tscn" id="2_eat54"]
[sub_resource type="PlaneMesh" id="PlaneMesh_kdh3y"]
size = Vector2(150, 150)
@ -74,12 +75,18 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 47.5, 0, 47.5)
shape = SubResource("BoxShape3D_kdh3y")
debug_color = Color(0.7365185, 0.46945518, 0, 0.41960785)
[node name="Building" parent="BuildingAreas/B_area" unique_id=228050854 instance=ExtResource("2_eat54")]
transform = Transform3D(1.0948861, 0, 0, 0, 1.0948861, 0, 0, 0, 1.0948861, 47.70289, 2.3668175, 47.375614)
[node name="B_area_E" type="StaticBody3D" parent="BuildingAreas" unique_id=164651542]
[node name="Collision" type="CollisionShape3D" parent="BuildingAreas/B_area_E" unique_id=2080946797]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 47.5, 0, 0)
shape = SubResource("BoxShape3D_a0kup")
[node name="Building" parent="BuildingAreas/B_area_E" unique_id=496327803 instance=ExtResource("2_eat54")]
transform = Transform3D(1.1296118, 0, 0, 0, 1.0989345, 0, 0, 0, 0.8093087, 47.032215, 2.198969, 0)
[node name="B_area_W" type="StaticBody3D" parent="BuildingAreas" unique_id=1412614477]
transform = Transform3D(-1, 0, 8.742278e-08, 0, 1, 0, -8.742278e-08, 0, -1, 0, 0, 0)
@ -87,6 +94,9 @@ transform = Transform3D(-1, 0, 8.742278e-08, 0, 1, 0, -8.742278e-08, 0, -1, 0, 0
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 47.5, 0, 0)
shape = SubResource("BoxShape3D_a0kup")
[node name="Building" parent="BuildingAreas/B_area_W" unique_id=1691268780 instance=ExtResource("2_eat54")]
transform = Transform3D(1.1296118, 0, 0, 0, 1.0989345, 0, 0, 0, 0.8093087, 47.032215, 2.198969, 0)
[node name="B_area_S" type="StaticBody3D" parent="BuildingAreas" unique_id=1192841263]
transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, 0, 0, 0)
@ -94,9 +104,15 @@ transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, 0, 0
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 47.5, 0, 0)
shape = SubResource("BoxShape3D_a0kup")
[node name="Building" parent="BuildingAreas/B_area_S" unique_id=819634987 instance=ExtResource("2_eat54")]
transform = Transform3D(1.1296118, 0, 0, 0, 1.0989345, 0, 0, 0, 0.8093087, 47.032215, 2.198969, 0)
[node name="B_area_N" type="StaticBody3D" parent="BuildingAreas" unique_id=1360962540]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 0, 0, 0)
[node name="Collision" type="CollisionShape3D" parent="BuildingAreas/B_area_N" unique_id=1952010205]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 47.5, 0, 0)
shape = SubResource("BoxShape3D_a0kup")
[node name="Building" parent="BuildingAreas/B_area_N" unique_id=737365486 instance=ExtResource("2_eat54")]
transform = Transform3D(1.1296118, 0, 0, 0, 1.0989345, 0, 0, 0, 0.8093087, 47.032215, 2.198969, 0)

View File

@ -1,7 +1,6 @@
[gd_scene format=3 uid="uid://m45422rsfnmh"]
[ext_resource type="Script" uid="uid://dixivehd47h0o" path="res://spawn.gd" id="1_3a72r"]
[ext_resource type="PackedScene" uid="uid://da60ofnpg72ua" path="res://building.tscn" id="2_yqulk"]
[sub_resource type="PlaneMesh" id="PlaneMesh_kdh3y"]
size = Vector2(150, 150)
@ -15,6 +14,3 @@ script = ExtResource("1_3a72r")
[node name="Mesh" type="MeshInstance3D" parent="." unique_id=651037282]
mesh = SubResource("PlaneMesh_kdh3y")
surface_material_override/0 = SubResource("StandardMaterial3D_eoxb4")
[node name="Building" parent="." unique_id=228050854 instance=ExtResource("2_yqulk")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -46.942894, 1.6992264, -36.10958)