Implements procedural ground tile generation
Adds procedural ground tile generation with chunking for improved performance. Includes: - Ground tile entity with debug text and cell information - Grass and tree placement based on cell data - Ground shader for visual representation - Chunk loading and unloading system based on player position
This commit is contained in:
parent
95665f54eb
commit
b5bf7619e6
21 changed files with 532 additions and 149 deletions
66
Entities/GroundTile/scripts/grass_multimesh.gd
Normal file
66
Entities/GroundTile/scripts/grass_multimesh.gd
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# GrassMultiMesh.gd (assuming this is your MultiMeshInstance3D script)
|
||||
extends MultiMeshInstance3D
|
||||
|
||||
var mm: MultiMesh
|
||||
@onready var parent_node: GrassController
|
||||
|
||||
func _ready() -> void:
|
||||
# Use call_deferred to ensure proper initialization order
|
||||
call_deferred("_setup_connections")
|
||||
|
||||
func _setup_connections() -> void:
|
||||
parent_node = get_parent() as GrassController
|
||||
if parent_node == null:
|
||||
Log.pr("Error: Parent node is not a GrassController!")
|
||||
return
|
||||
|
||||
parent_node.grass_data_ready.connect(_on_grass_data_ready)
|
||||
Log.pr("Connected to grass_data_ready signal")
|
||||
|
||||
func _on_grass_data_ready():
|
||||
Log.pr("Received grass_data_ready signal, setting up multimesh")
|
||||
setup_multimesh()
|
||||
|
||||
func setup_multimesh() -> void:
|
||||
if parent_node == null:
|
||||
Log.pr("Error: Parent node not available in setup_multimesh")
|
||||
return
|
||||
|
||||
# Load the mesh resource directly
|
||||
var mesh = load("res://Stages/Test3D/assets/stylizedGrassMeshes/grass2_mesh.res")
|
||||
if mesh == null:
|
||||
Log.pr("Error: Could not load grass mesh")
|
||||
return
|
||||
|
||||
# Create new MultiMesh instance
|
||||
mm = MultiMesh.new()
|
||||
|
||||
# Configure the MultiMesh
|
||||
mm.transform_format = MultiMesh.TRANSFORM_3D
|
||||
mm.instance_count = parent_node.grass_instance_range
|
||||
mm.mesh = mesh
|
||||
|
||||
Log.pr("Setting up MultiMesh with " + str(mm.instance_count) + " instances")
|
||||
|
||||
# Generate random positions for grass
|
||||
for i in range(mm.instance_count):
|
||||
var random_pos = Vector3(
|
||||
randf_range(-1.0, 1.0),
|
||||
0.0,
|
||||
randf_range(-1.0, 1.0)
|
||||
)
|
||||
|
||||
var random_rotation = randf_range(0.0, TAU)
|
||||
var basis = Basis(Vector3.UP, random_rotation)
|
||||
|
||||
var random_scale = randf_range(0.05, 0.3)
|
||||
basis = basis.scaled(Vector3(random_scale, random_scale, random_scale))
|
||||
|
||||
var tx = Transform3D(basis, random_pos)
|
||||
mm.set_instance_transform(i, tx)
|
||||
|
||||
# Assign the MultiMesh to this node
|
||||
multimesh = mm
|
||||
cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
|
||||
Log.pr("MultiMesh setup complete with " + str(multimesh.instance_count) + " instances")
|
||||
Loading…
Add table
Add a link
Reference in a new issue