generated from krampus/template-godot4
	Arcology feature & generation layer
This commit is contained in:
		
							parent
							
								
									16c76aeb72
								
							
						
					
					
						commit
						2c065a2663
					
				
							
								
								
									
										79
									
								
								src/world/generation/feature/arcology/arcology.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								src/world/generation/feature/arcology/arcology.tscn
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,79 @@ | |||||||
|  | [gd_scene load_steps=5 format=3 uid="uid://nllc8ljmn37g"] | ||||||
|  | 
 | ||||||
|  | [ext_resource type="Script" uid="uid://drk82eeqk2mjs" path="res://src/world/generation/feature/generation_feature.gd" id="1_ek7o7"] | ||||||
|  | 
 | ||||||
|  | [sub_resource type="PlaneMesh" id="PlaneMesh_pko82"] | ||||||
|  | size = Vector2(100000, 100000) | ||||||
|  | 
 | ||||||
|  | [sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_ek7o7"] | ||||||
|  | data = PackedVector3Array(50000, 0, 50000, -50000, 0, 50000, 50000, 0, -50000, -50000, 0, 50000, -50000, 0, -50000, 50000, 0, -50000) | ||||||
|  | 
 | ||||||
|  | [sub_resource type="BoxShape3D" id="BoxShape3D_pko82"] | ||||||
|  | size = Vector3(200000, 200000, 200000) | ||||||
|  | 
 | ||||||
|  | [node name="Arcology" type="Node3D"] | ||||||
|  | script = ExtResource("1_ek7o7") | ||||||
|  | metadata/_custom_type_script = "uid://drk82eeqk2mjs" | ||||||
|  | 
 | ||||||
|  | [node name="InnerPyramid" type="CSGCylinder3D" parent="."] | ||||||
|  | transform = Transform3D(0.70710677, 0, 0.70710677, 0, 1, 0, -0.70710677, 0, 0.70710677, 50000, 30000, 50000) | ||||||
|  | use_collision = true | ||||||
|  | radius = 60000.0 | ||||||
|  | height = 60000.0 | ||||||
|  | sides = 4 | ||||||
|  | cone = true | ||||||
|  | smooth_faces = false | ||||||
|  | 
 | ||||||
|  | [node name="OuterPyramid" type="CSGCylinder3D" parent="InnerPyramid"] | ||||||
|  | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5000, 0) | ||||||
|  | radius = 70000.0 | ||||||
|  | height = 70000.0 | ||||||
|  | sides = 4 | ||||||
|  | cone = true | ||||||
|  | smooth_faces = false | ||||||
|  | 
 | ||||||
|  | [node name="TopCutoff" type="CSGBox3D" parent="InnerPyramid/OuterPyramid"] | ||||||
|  | transform = Transform3D(0.70710677, 0, -0.70710677, 0, 1, 0, 0.70710677, 0, 0.70710677, 0, 30000, 0) | ||||||
|  | operation = 2 | ||||||
|  | size = Vector3(100000, 80000, 100000) | ||||||
|  | 
 | ||||||
|  | [node name="Slots" type="CSGCombiner3D" parent="InnerPyramid/OuterPyramid"] | ||||||
|  | transform = Transform3D(0.70710677, 0, -0.70710677, 0, 1, 0, 0.70710677, 0, 0.70710677, 0, 0, 0) | ||||||
|  | operation = 2 | ||||||
|  | 
 | ||||||
|  | [node name="CSGBox3D2" type="CSGBox3D" parent="InnerPyramid/OuterPyramid/Slots"] | ||||||
|  | transform = Transform3D(0.99999994, 0, 0, 0, 1, 0, 0, 0, 0.99999994, 0, 0, 0) | ||||||
|  | size = Vector3(100000, 71000, 10000) | ||||||
|  | 
 | ||||||
|  | [node name="CSGBox3D3" type="CSGBox3D" parent="InnerPyramid/OuterPyramid/Slots"] | ||||||
|  | transform = Transform3D(0.99999994, 0, 0, 0, 1, 0, 0, 0, 0.99999994, 0, 0, 0) | ||||||
|  | size = Vector3(10000, 71000, 100000) | ||||||
|  | 
 | ||||||
|  | [node name="Slots" type="CSGCombiner3D" parent="InnerPyramid"] | ||||||
|  | transform = Transform3D(0.70710677, 0, -0.70710677, 0, 1, 0, 0.70710677, 0, 0.70710677, 0, -18000, 0) | ||||||
|  | operation = 2 | ||||||
|  | 
 | ||||||
|  | [node name="CSGBox3D2" type="CSGBox3D" parent="InnerPyramid/Slots"] | ||||||
|  | transform = Transform3D(0.99999994, 0, 0, 0, 1, 0, 0, 0, 0.99999994, 0, 0, 0) | ||||||
|  | size = Vector3(100000, 30000, 10000) | ||||||
|  | 
 | ||||||
|  | [node name="CSGBox3D3" type="CSGBox3D" parent="InnerPyramid/Slots"] | ||||||
|  | transform = Transform3D(0.99999994, 0, 0, 0, 1, 0, 0, 0, 0.99999994, 0, 0, 0) | ||||||
|  | size = Vector3(10000, 30000, 100000) | ||||||
|  | 
 | ||||||
|  | [node name="WorldFloor" type="MeshInstance3D" parent="."] | ||||||
|  | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 50000, 0, 50000) | ||||||
|  | mesh = SubResource("PlaneMesh_pko82") | ||||||
|  | 
 | ||||||
|  | [node name="StaticBody3D" type="StaticBody3D" parent="WorldFloor"] | ||||||
|  | 
 | ||||||
|  | [node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor/StaticBody3D"] | ||||||
|  | shape = SubResource("ConcavePolygonShape3D_ek7o7") | ||||||
|  | 
 | ||||||
|  | [node name="HighDetailArea" type="Area3D" parent="."] | ||||||
|  | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 50000, 0, 50000) | ||||||
|  | collision_layer = 0 | ||||||
|  | collision_mask = 2 | ||||||
|  | 
 | ||||||
|  | [node name="CollisionShape3D" type="CollisionShape3D" parent="HighDetailArea"] | ||||||
|  | shape = SubResource("BoxShape3D_pko82") | ||||||
							
								
								
									
										22
									
								
								src/world/generation/feature/arcology/empty.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/world/generation/feature/arcology/empty.tscn
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | |||||||
|  | [gd_scene load_steps=4 format=3 uid="uid://dawv6mbpr4d3c"] | ||||||
|  | 
 | ||||||
|  | [ext_resource type="Script" uid="uid://drk82eeqk2mjs" path="res://src/world/generation/feature/generation_feature.gd" id="1_ydt4o"] | ||||||
|  | 
 | ||||||
|  | [sub_resource type="PlaneMesh" id="PlaneMesh_ydt4o"] | ||||||
|  | size = Vector2(100000, 100000) | ||||||
|  | 
 | ||||||
|  | [sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_q70le"] | ||||||
|  | data = PackedVector3Array(50000, 0, 50000, -50000, 0, 50000, 50000, 0, -50000, -50000, 0, 50000, -50000, 0, -50000, 50000, 0, -50000) | ||||||
|  | 
 | ||||||
|  | [node name="Empty" type="Node3D"] | ||||||
|  | script = ExtResource("1_ydt4o") | ||||||
|  | metadata/_custom_type_script = "uid://drk82eeqk2mjs" | ||||||
|  | 
 | ||||||
|  | [node name="WorldFloor" type="MeshInstance3D" parent="."] | ||||||
|  | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 50000, 0, 50000) | ||||||
|  | mesh = SubResource("PlaneMesh_ydt4o") | ||||||
|  | 
 | ||||||
|  | [node name="StaticBody3D" type="StaticBody3D" parent="WorldFloor"] | ||||||
|  | 
 | ||||||
|  | [node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor/StaticBody3D"] | ||||||
|  | shape = SubResource("ConcavePolygonShape3D_q70le") | ||||||
| @ -0,0 +1,53 @@ | |||||||
|  | class_name ArcologyGridLayer extends GenerationLayer | ||||||
|  | ## Grid with each cell possibly generating an arcology | ||||||
|  | 
 | ||||||
|  | const GRID_SIZE := Vector2(100000, 100000) | ||||||
|  | 
 | ||||||
|  | @export var arcology_feature_scene: PackedScene | ||||||
|  | @export var empty_feature_scene: PackedScene | ||||||
|  | 
 | ||||||
|  | @export var arcology_probability := 0.2 | ||||||
|  | 
 | ||||||
|  | var features: Dictionary[Vector2, GenerationFeature] = {} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func probe() -> void: | ||||||
|  | 	var world_pos := WorldGenManager.get_generation_point() | ||||||
|  | 	probe_radius(world_pos, WorldGenManager.low_detail_radius) | ||||||
|  | 	# TODO high-detail & medium-detail probes | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func probe_radius(center: Vector3, radius: float) -> void: | ||||||
|  | 	var rad_diff := Vector3(radius, 0, radius) | ||||||
|  | 	var grid_low := world_to_local(center - rad_diff).floor() | ||||||
|  | 	var grid_high := world_to_local(center + rad_diff).floor() | ||||||
|  | 	for i in range(grid_low.x, grid_high.x + 1): | ||||||
|  | 		for j in range(grid_low.y, grid_high.y + 1): | ||||||
|  | 			probe_grid(Vector2(i, j)) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func probe_grid(grid_pos: Vector2) -> void: | ||||||
|  | 	# Generate if needed | ||||||
|  | 	if grid_pos not in features: | ||||||
|  | 		var feature: GenerationFeature | ||||||
|  | 		var sample := absf(WorldGenManager.noise.get_noise_2dv(grid_pos)) | ||||||
|  | 		print_debug("Sampled ", sample, " at ", grid_pos) | ||||||
|  | 		if sample < arcology_probability: | ||||||
|  | 			print_debug("Generating arcology at ", grid_pos) | ||||||
|  | 			feature = arcology_feature_scene.instantiate() | ||||||
|  | 		else: | ||||||
|  | 			feature = empty_feature_scene.instantiate() | ||||||
|  | 		add_child(feature) | ||||||
|  | 		feature.global_position = local_to_world(grid_pos) | ||||||
|  | 		features[grid_pos] = feature | ||||||
|  | 	# Probe feature | ||||||
|  | 	features[grid_pos].probe() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func local_to_world(local_pos: Vector2) -> Vector3: | ||||||
|  | 	return global_position + Vector3(local_pos.x * GRID_SIZE.x, 0, local_pos.y * GRID_SIZE.y) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | func world_to_local(world_pos: Vector3) -> Vector2: | ||||||
|  | 	var rel_pos := world_pos - global_position | ||||||
|  | 	return Vector2(rel_pos.x / GRID_SIZE.x, rel_pos.z / GRID_SIZE.y) | ||||||
| @ -0,0 +1 @@ | |||||||
|  | uid://kp8r23lsylpk | ||||||
| @ -0,0 +1,11 @@ | |||||||
|  | [gd_scene load_steps=4 format=3 uid="uid://dlhc1te2ip8vg"] | ||||||
|  | 
 | ||||||
|  | [ext_resource type="Script" uid="uid://kp8r23lsylpk" path="res://src/world/generation/layer/arcology_grid_layer/arcology_grid_layer.gd" id="1_85eh3"] | ||||||
|  | [ext_resource type="PackedScene" uid="uid://nllc8ljmn37g" path="res://src/world/generation/feature/arcology/arcology.tscn" id="2_pxyh5"] | ||||||
|  | [ext_resource type="PackedScene" uid="uid://dawv6mbpr4d3c" path="res://src/world/generation/feature/arcology/empty.tscn" id="3_p6bke"] | ||||||
|  | 
 | ||||||
|  | [node name="ArcologyGridLayer" type="Node3D"] | ||||||
|  | script = ExtResource("1_85eh3") | ||||||
|  | arcology_feature_scene = ExtResource("2_pxyh5") | ||||||
|  | empty_feature_scene = ExtResource("3_p6bke") | ||||||
|  | metadata/_custom_type_script = "uid://kp8r23lsylpk" | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user