A2: Player figure and animation

The islander is built in headless Blender (tools/models/figure.py,
`make figure`, `make art`) as twelve rigid parts with their origins at
their joints: an oilskin coat, a sou'wester, sea boots, a bedding roll
and the canvas wing-sail. Debian's Blender can't write glTF, so the
figure is jointed rather than skinned.

FigureRig hangs the parts on pivots, paints them from Palette with the
coat in the player's own oilskin, and plays FigurePoses' hand-written
key poses through one AnimationTree: idle, walk and run by speed,
crouch and creep, air, skydive, glide, swim and aboard; long, short and
carried holds; reload and use layers; fire, boathook swing, keg throw
and building as one-shots; and a flinch when health drops. The chest
takes a third of the pitch and the held item all of it.

Figures animate from replicated state only: positions, look, health,
the held item and the FLAG_ bits (reloading and using now reach
mirrored players), with actions from FX. Every boathook swing is now a
sim "swing" event, sent as a SHOT with no item, so misses are seen and
heard; the new FX kind PLACE shows pieces placed. Protocol version 4.

Tests: test_figure_rig (15), plus swing and PLACE cases in test_harvest
and test_net_fx. make check passes (604 tests); make client-check
passes. Captures: figure_states, figure_actions, figure_close
(make figure-captures), client_glide and client_landed.

Closes #42

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 17:35:53 -05:00
co-authored by Claude Opus 5.5
parent da0c65f3ce
commit 07738330b5
66 changed files with 6230 additions and 88 deletions
+48 -57
View File
@@ -1,10 +1,13 @@
## Draws what moves in a match: players with what they hold, the sky barge while it
## crosses, items lying in the world and sea chests. `sync()` matches everything to the simulation as it is
## now. These are stand-in shapes built in code, in the weathered seafaring palette of
## docs/STYLE.md: an oilskin coat, a sou'wester and a canvas wing-sail. The art
## pass replaces them. Held and lying items are the models of A4 (ItemModels): a held
## one sits with its grip in the figure's right hand and points where its player looks.
## Nothing here is ever used for collision.
## crosses, items lying in the world and sea chests. `sync()` matches everything to the
## simulation as it is now, and `animate()` steps the players' figures.
##
## Players are FigureRigs (A2): jointed islanders in oilskins, animated from what the
## simulation replicates about them, with shots, swings and building played from FX
## records through hear(). Held and lying items are the models of A4 (ItemModels): a
## held one sits with its grip in the figure's right hand and points where its player
## looks. The barge and chests are still stand-in shapes. Nothing here is ever used
## for collision.
class_name EntityView
extends Node3D
@@ -24,8 +27,6 @@ const ITEM: Color = Palette.GILT
## carries them all at one point; this only spreads them out to be seen.
const DECK_SPACING: float = 1.3
const DECK_ROWS: int = 4
## Where a figure's right hand holds an item, from its feet, facing +Z; its right is -X.
const HAND: Vector3 = Vector3(-0.24, 1.2, 0.32)
## Items lying in the world are drawn this much larger than life, to be seen.
const PICKUP_SCALE: float = 1.4
@@ -36,8 +37,10 @@ var local_id: int = 0
var barge_at: Vector3 = Vector3.INF
var _sim: Simulation
## Entity ID -> the figure's root node.
## Entity ID -> its FigureRig.
var _figures: Dictionary = {}
## Whether _process steps the figures. Captures that pose figures exactly turn it off.
var animate_live: bool = true
var _barge: Node3D
## Items lying in the world: one MultiMeshInstance3D per item model and tier.
var _pickups: Node3D
@@ -63,7 +66,7 @@ func figure_count() -> int:
## The figure drawn for a player, or null.
func figure_of(entity_id: int) -> Node3D:
func figure_of(entity_id: int) -> FigureRig:
return _figures.get(entity_id)
@@ -116,11 +119,12 @@ func sync() -> void:
if entity.archetype != SimEntity.ARCHETYPE_PLAYER:
continue
seen[entity.id] = true
var figure: Node3D = _figures.get(entity.id)
var figure: FigureRig = _figures.get(entity.id)
if figure == null:
figure = _build_figure(entity.id)
_figures[entity.id] = figure
add_child(figure)
figure.drive(entity, 0.0)
figure.visible = not entity.eliminated
figure.position = entity.position
figure.rotation.y = float(entity.yaw) / PlayerCommand.YAW_STEPS * TAU
@@ -131,8 +135,6 @@ func sync() -> void:
figure.position += offset.rotated(Vector3.UP, heading)
figure.rotation.y = heading
aboard += 1
figure.scale.y = Tuning.CROUCH_HEIGHT / Tuning.PLAYER_HEIGHT if entity.crouching else 1.0
(figure.get_node("Sail") as Node3D).visible = entity.drop_state == Drop.GLIDING
_hold(figure, entity)
for entity_id: int in _figures.keys():
if not seen.has(entity_id):
@@ -147,25 +149,45 @@ func sync() -> void:
chests.set_instance_color(index, CHEST_OPEN if _sim.loot.chest_opened[index] != 0 else CHEST_SHUT)
func _process(_delta: float) -> void:
func _process(delta: float) -> void:
sync()
if animate_live:
animate(delta)
## Puts the held item's model in the figure's hand, pointing where the player looks.
## Nothing is held aboard the barge, falling, gliding or swimming.
func _hold(figure: Node3D, entity: SimEntity) -> void:
var hand: Node3D = figure.get_node("Hand")
var held: MeshInstance3D = hand.get_node("Held")
## Drives every figure from its player's state and steps its animation by `delta`.
func animate(delta: float) -> void:
if _sim == null:
return
for entity_id: int in _figures:
var entity: SimEntity = _sim.entities.find(entity_id)
var figure: FigureRig = _figures[entity_id]
if entity == null or not figure.visible:
continue
figure.drive(entity, delta)
figure.advance(delta)
## Plays the actions FX records show (shots, swings, pieces placed) on the figures of
## the players who made them.
func hear(records: Array[Dictionary]) -> void:
for record: Dictionary in records:
var figure: FigureRig = _figures.get(int(record.get("player", 0)))
if figure != null and figure.visible:
figure.hear(record)
## Puts the held item's model in the figure's hand; the figure points it where the
## player looks. Nothing is held aboard the barge, falling, gliding or swimming.
func _hold(figure: FigureRig, entity: SimEntity) -> void:
var busy: bool = entity.drop_state != Drop.NONE or entity.swimming or entity.eliminated
hand.visible = not busy
figure.hand().visible = not busy
if busy:
return
var id: String = ItemModels.id_of(held_code(entity))
var mesh: ArrayMesh = ItemModels.model(id, held_tier(entity))
if held.mesh != mesh:
held.mesh = mesh
var pitch: float = float(entity.pitch) / PlayerCommand.PITCH_MAX * (PI * 0.5)
hand.rotation = Vector3(-pitch, 0.0, 0.0)
if figure.held().mesh != mesh:
figure.held().mesh = mesh
func _sync_pickups() -> void:
@@ -221,41 +243,10 @@ func _item_field(key: String) -> MultiMeshInstance3D:
return field
func _build_figure(entity_id: int) -> Node3D:
func _build_figure(entity_id: int) -> FigureRig:
var coat: Color = OILSKINS[0] if entity_id == local_id else OILSKINS[1 + entity_id % (OILSKINS.size() - 1)]
var figure: Node3D = Node3D.new()
var figure: FigureRig = FigureRig.new(coat)
figure.name = "player_%d" % entity_id
var legs: BoxMesh = BoxMesh.new()
legs.size = Vector3(0.42, 0.8, 0.26)
figure.add_child(_part(legs, TAR, Vector3(0.0, 0.4, 0.0)))
var body: CapsuleMesh = CapsuleMesh.new()
body.radius = 0.3
body.height = 0.95
figure.add_child(_part(body, coat, Vector3(0.0, 1.05, 0.0)))
var head: SphereMesh = SphereMesh.new()
head.radius = 0.16
head.height = 0.32
figure.add_child(_part(head, SKIN, Vector3(0.0, 1.6, 0.0)))
var brim: CylinderMesh = CylinderMesh.new()
brim.top_radius = 0.17
brim.bottom_radius = 0.33
brim.height = 0.16
# The sou'wester's brim runs long at the back.
figure.add_child(_part(brim, coat.darkened(0.25), Vector3(0.0, 1.76, -0.05)))
var sail_mesh: BoxMesh = BoxMesh.new()
sail_mesh.size = Vector3(2.6, 0.04, 0.9)
var sail: MeshInstance3D = _part(sail_mesh, CANVAS, Vector3(0.0, 2.15, -0.1))
sail.name = "Sail"
sail.rotation.x = deg_to_rad(-8.0)
sail.visible = false
figure.add_child(sail)
var hand: Node3D = Node3D.new()
hand.name = "Hand"
hand.position = HAND
figure.add_child(hand)
var held: MeshInstance3D = MeshInstance3D.new()
held.name = "Held"
hand.add_child(held)
return figure