H11: Hide pines between the shoulder camera and the player
PropView.clear_view() hides every pine whose drawn shape crosses the line from the camera to the followed player's chest or head, or holds the camera, and shows it again once the line is clear. Candidates come from the trunks in the ground's solid index around the line. MatchView.follow() applies it; look_from() (framing, overview) shows everything again. Test: a player against the most crowded pine on seed 2, at 16 yaws, hides exactly the blocking pines and brings them all back afterwards. Captures canopy and canopy_before (tools/capture.sh canopy ...). Closes #75 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -105,6 +105,10 @@ func follow(entity_id: int, pitch: float = NAN, look_yaw: float = NAN) -> bool:
|
||||
feet = figure.position
|
||||
camera.transform = rig.solve(feet, yaw, look_pitch, player.crouching, sim.ground)
|
||||
camera.fov = rig.fov()
|
||||
# Pines between the lens and the player are hidden (H11).
|
||||
var height: float = Movement.body_height(player)
|
||||
var lines: Array[Vector3] = [feet + Vector3(0.0, height * 0.6, 0.0), feet + Vector3(0.0, height, 0.0)]
|
||||
props.clear_view(sim.ground, camera.transform.origin, lines)
|
||||
_focus()
|
||||
return true
|
||||
|
||||
@@ -138,6 +142,8 @@ func frame(entity_id: int, distance: float = 6.0, height: float = 2.6, beyond: V
|
||||
func look_from(eye: Vector3, target: Vector3) -> void:
|
||||
camera.transform = Transform3D(Basis.IDENTITY, eye).looking_at(target, Vector3.UP)
|
||||
camera.fov = CameraRig.FOV
|
||||
var none: Array[Vector3] = []
|
||||
props.clear_view(sim.ground, eye, none)
|
||||
_focus()
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
## and coloured per vertex in the weathered palette from docs/ORIGINALITY.md. Each
|
||||
## instance gets a slight colour shift so a stand of pines isn't one flat green.
|
||||
##
|
||||
## A pine's canopy is drawn but doesn't block (only its trunk does), so the shoulder
|
||||
## camera can end up behind or inside one. `clear_view()` hides every pine whose drawn
|
||||
## shape crosses the line from the camera to the followed player's chest or head, and
|
||||
## brings it back once the line is clear (H11).
|
||||
##
|
||||
## Destruction comes from the simulation: `sync()` reads new entries in
|
||||
## PropSet.destroyed and collapses those instances to nothing. Collision never comes from
|
||||
## here; SimGround holds the props' boxes on the server and in client prediction alike.
|
||||
@@ -46,6 +51,11 @@ var _nodes: Array[MultiMeshInstance3D] = []
|
||||
var _hidden: PackedByteArray = PackedByteArray()
|
||||
## How many entries of PropSet.destroyed have been applied.
|
||||
var _cursor: int = 0
|
||||
## Pines hidden by clear_view(), and the pine mesh's bounds in unit space.
|
||||
var _screened: PackedInt32Array = PackedInt32Array()
|
||||
var _pine_bounds: AABB = AABB()
|
||||
## How far a canopy may spread past its trunk's box, in metres, for the search.
|
||||
const CANOPY_REACH: float = 4.0
|
||||
|
||||
|
||||
## Builds every instance for `props`. Call once, before or after adding to the tree.
|
||||
@@ -59,6 +69,8 @@ func setup(props: PropSet) -> void:
|
||||
var meshes: Array[ArrayMesh] = []
|
||||
for kind: String in PropSet.KINDS:
|
||||
meshes.append(build_mesh(kind))
|
||||
_pine_bounds = meshes[PropSet.KINDS.find("pine")].get_aabb()
|
||||
_screened = PackedInt32Array()
|
||||
# (chunk key, kind code) -> prop IDs, in prop order so the layout is deterministic.
|
||||
var groups: Dictionary = {}
|
||||
var keys: Array[Vector3i] = []
|
||||
@@ -126,7 +138,47 @@ func _process(_delta: float) -> void:
|
||||
|
||||
|
||||
func is_drawn(prop: int) -> bool:
|
||||
return _hidden[prop] == 0
|
||||
return _hidden[prop] == 0 and not _screened.has(prop)
|
||||
|
||||
|
||||
## Hides the pines whose drawn shape crosses a line from `eye` to any of `targets`, or
|
||||
## holds `eye`, and shows again those that no longer do. Candidates come from the
|
||||
## trunks in `ground` around the lines. With no targets, shows them all again.
|
||||
func clear_view(ground: SimGround, eye: Vector3, targets: Array[Vector3]) -> void:
|
||||
var wanted: PackedInt32Array = PackedInt32Array()
|
||||
if not targets.is_empty():
|
||||
var low: Vector2 = Vector2(eye.x, eye.z)
|
||||
var high: Vector2 = low
|
||||
for target: Vector3 in targets:
|
||||
low = Vector2(minf(low.x, target.x), minf(low.y, target.z))
|
||||
high = Vector2(maxf(high.x, target.x), maxf(high.y, target.z))
|
||||
for solid_id: int in ground.solids_near(low.x - CANOPY_REACH, low.y - CANOPY_REACH, high.x + CANOPY_REACH, high.y + CANOPY_REACH):
|
||||
var prop: int = _props.prop_of_solid(solid_id)
|
||||
if prop < 0 or _hidden[prop] != 0 or _props.kind_name(prop) != "pine" or wanted.has(prop):
|
||||
continue
|
||||
var shape: AABB = canopy_bounds(prop)
|
||||
var blocks: bool = shape.has_point(eye)
|
||||
for target: Vector3 in targets:
|
||||
blocks = blocks or shape.intersects_segment(eye, target)
|
||||
if blocks:
|
||||
wanted.append(prop)
|
||||
for prop: int in _screened:
|
||||
if not wanted.has(prop) and _hidden[prop] == 0:
|
||||
_nodes[_node_of[prop]].multimesh.set_instance_transform(_index_of[prop], instance_transform(_props, prop))
|
||||
for prop: int in wanted:
|
||||
if not _screened.has(prop):
|
||||
_nodes[_node_of[prop]].multimesh.set_instance_transform(_index_of[prop], Transform3D(Basis.from_scale(Vector3.ZERO), Vector3.ZERO))
|
||||
_screened = wanted
|
||||
|
||||
|
||||
## Pines clear_view() is hiding now.
|
||||
func screened() -> PackedInt32Array:
|
||||
return _screened
|
||||
|
||||
|
||||
## The world-space box around a pine as drawn, canopy and all.
|
||||
func canopy_bounds(prop: int) -> AABB:
|
||||
return instance_transform(_props, prop) * _pine_bounds
|
||||
|
||||
|
||||
func node_count() -> int:
|
||||
|
||||
Reference in New Issue
Block a user