feat: implement 3D arena support and dynamic environment management in main scene

This commit is contained in:
Yogi Wiguna
2026-03-31 17:42:05 +08:00
parent fd54c16026
commit 5ea41806f1
65 changed files with 1740 additions and 9384 deletions
+22 -45
View File
@@ -1,6 +1,10 @@
extends StaticBody3D
@onready var mesh_instance: MeshInstance3D = $MeshInstance3D
@onready var seat_container: Node3D = $SeatContainer
# Preload the new seat models
var SEAT_1 = load("res://scenes/tekton_stand/tekton_seat.tscn")
var SEAT_2 = load("res://scenes/tekton_stand/tekton_seat_2.tscn")
# Sync the chosen shape so all clients see the same one
@export var shape_index: int = -1:
@@ -19,17 +23,12 @@ func _ready():
if multiplayer.is_server():
# Only randomize if not already set (Main.gd sets it now)
if shape_index == -1:
shape_index = randi() % 4
shape_index = randi() % 2 # Randomize between seat 1 and 2
_update_mesh_from_index()
else:
# Client side:
if shape_index != -1:
_update_mesh_from_index()
else:
# If we spawned but data hasn't arrived (unlikely with spawn=true but possible),
# we wait. The setter will trigger update when data arrives.
# But just in case, we can try to request it or use a default
pass
func _clear_local_gridmap_area():
var main = get_tree().get_root().get_node_or_null("Main")
@@ -55,45 +54,23 @@ func _clear_local_gridmap_area():
gridmap.update_astar_costs()
func _update_mesh_from_index():
if not mesh_instance: return
if not is_inside_tree() or not seat_container: return
var shapes = [
_create_cylinder(),
_create_box()
]
# Clear existing models
for child in seat_container.get_children():
child.queue_free()
var idx = shape_index % shapes.size()
var selected_mesh = shapes[idx]
var seats = [SEAT_1, SEAT_2]
var idx = shape_index % seats.size()
var selected_scene = seats[idx]
# Apply Material
var mat = StandardMaterial3D.new()
mat.albedo_color = Color(0.2, 0.2, 0.25)
mat.metallic = 0.5
mat.roughness = 0.5
selected_mesh.material = mat
if not selected_scene:
push_error("[StaticStand] Failed to load seat model at index %d. Path may be incorrect." % idx)
return
var seat_instance = selected_scene.instantiate()
seat_container.add_child(seat_instance)
mesh_instance.mesh = selected_mesh
# Deprecated: _randomize_shape (Logic moved to server init and sync)
# func _randomize_shape(): ...
func _create_cylinder() -> CylinderMesh:
var mesh = CylinderMesh.new()
mesh.top_radius = 1.4
mesh.bottom_radius = 1.4
mesh.height = 0.6
return mesh
func _create_box() -> BoxMesh:
var mesh = BoxMesh.new()
mesh.size = Vector3(3.2, 0.6, 3.2)
return mesh
func _create_sphere() -> SphereMesh:
# A flattened sphere acting like a dome stand
var mesh = SphereMesh.new()
mesh.radius = 1.4
mesh.height = 1.0 # Flattened
mesh.is_hemisphere = true
return mesh
# Ensure the model is centered
seat_instance.position = Vector3.ZERO
print("[StaticStand] Instantiated Seat Model %d" % idx)
+1 -1
View File
@@ -45,7 +45,7 @@ func update_visual_position():
var offset = 0.2
if is_static_turret:
offset = 0.5
floor_y = 0.6
floor_y = 1.0
position = Vector3(current_position.x + offset, floor_y, current_position.y + offset)