## Capture scenario for the streamed island terrain. The camera stands `lift` metres above ## the ground at `eye` (x, z) and looks at `target`. With `crack_check` the sky is a flat ## magenta that appears nowhere in the terrain, so any crack between chunks shows up as ## magenta pixels for tools/crack_check.gd to count. extends Node3D const CRACK_COLOUR: Color = Color(1.0, 0.0, 1.0) @export var island_seed: int = 2 @export var eye: Vector2 = Vector2(700.0, 760.0) @export var lift: float = 12.0 @export var target: Vector3 = Vector3(520.0, 35.0, 470.0) @export var show_lod: bool = false @export var crack_check: bool = false @export var fov: float = 70.0 ## Off only in terrain_cracks_control, which must show cracks. @export var skirts: bool = true ## When set, draw the island's points of interest and frame the first one of this kind: ## the camera stands `poi_view` (x right, y up, z out of the front) from its origin. @export var poi_kind: String = "" @export var poi_view: Vector3 = Vector3(6.0, 7.0, 22.0) ## Draw the island's props too. @export var show_props: bool = false ## When set, frame the first prop of this kind whose surroundings hold at least ## `prop_crowd` others within 25 m: the camera stands `prop_view` from it (x east, y up, ## z south) and looks at it. @export var prop_kind: String = "" @export var prop_crowd: int = 0 @export var prop_view: Vector3 = Vector3(10.0, 4.0, 14.0) ## Destroy every `knock_out`th prop near the framed one, to show felled props vanish. @export var knock_out: int = 0 func _ready() -> void: var island: Island = Island.generate(island_seed) var environment: Environment = Environment.new() if crack_check: environment.background_mode = Environment.BG_COLOR environment.background_color = CRACK_COLOUR environment.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR environment.ambient_light_color = Color(0.5, 0.5, 0.5) environment.tonemap_mode = Environment.TONE_MAPPER_LINEAR else: var sky_material: ProceduralSkyMaterial = ProceduralSkyMaterial.new() sky_material.sky_top_color = Color(0.32, 0.5, 0.68) sky_material.sky_horizon_color = Color(0.82, 0.78, 0.68) sky_material.ground_bottom_color = Color(0.18, 0.2, 0.2) sky_material.ground_horizon_color = Color(0.82, 0.78, 0.68) var sky: Sky = Sky.new() sky.sky_material = sky_material environment.background_mode = Environment.BG_SKY environment.sky = sky environment.ambient_light_source = Environment.AMBIENT_SOURCE_SKY environment.ambient_light_energy = 0.45 environment.tonemap_mode = Environment.TONE_MAPPER_FILMIC environment.fog_enabled = true environment.fog_light_color = Color(0.78, 0.78, 0.74) environment.fog_density = 0.0005 environment.fog_aerial_perspective = 0.4 var world: WorldEnvironment = WorldEnvironment.new() world.environment = environment add_child(world) var sun: DirectionalLight3D = DirectionalLight3D.new() sun.rotation_degrees = Vector3(-35.0, -130.0, 0.0) sun.light_energy = 0.95 sun.shadow_enabled = not crack_check sun.directional_shadow_max_distance = 600.0 add_child(sun) var camera: Camera3D = Camera3D.new() camera.fov = fov camera.far = 2000.0 camera.position = Vector3(eye.x, island.ground.terrain_height(eye.x, eye.y) + lift, eye.y) var look_at_point: Vector3 = target if not poi_kind.is_empty(): var placed: PoiSet = PoiSet.generate(island) var view: PoiView = PoiView.new() view.setup(placed) add_child(view) for poi: Poi in placed.pois: if poi.kind == poi_kind: camera.position = poi.to_world(poi_view) camera.position.y = maxf(camera.position.y, island.ground.terrain_height(camera.position.x, camera.position.z) + 2.0) look_at_point = poi.origin + Vector3.UP * 2.5 break if show_props or not prop_kind.is_empty(): var sim_props: PropSet = PropSet.generate(island, PoiSet.generate(island)) var prop_view_node: PropView = PropView.new() prop_view_node.setup(sim_props) add_child(prop_view_node) if not prop_kind.is_empty(): for prop: int in sim_props.count(): if sim_props.kind_name(prop) != prop_kind: continue var at: Vector3 = sim_props.boxes[prop].get_center() var crowd: PackedInt32Array = sim_props.near(at, 25.0) if crowd.size() <= prop_crowd: continue var base: Vector3 = Vector3(at.x, island.ground.terrain_height(at.x, at.z), at.z) # Back away along the view offset until no canopy is in the camera's face. var offset: Vector3 = prop_view for _try: int in 12: camera.position = base + offset camera.position.y = maxf(camera.position.y, island.ground.terrain_height(camera.position.x, camera.position.z) + 1.6) if sim_props.near(Vector3(camera.position.x, island.ground.terrain_height(camera.position.x, camera.position.z), camera.position.z), 6.0).is_empty(): break offset *= 1.15 look_at_point = base + Vector3.UP * minf(sim_props.boxes[prop].size.y * 0.5, 3.0) if knock_out > 0: for index: int in crowd.size(): if index % knock_out == 1: sim_props.damage(crowd[index], 100000) prop_view_node.sync() break add_child(camera) camera.look_at(look_at_point) camera.make_current() var terrain: TerrainView = TerrainView.new() terrain.setup(island) terrain.focus = camera.position terrain.show_lod = show_lod terrain.skirts = skirts add_child(terrain) terrain.build_all_now()