A4: Item models and icons

tools/models/items.py builds every item in headless Blender from
primitives: the boathook, the eight weapons and powder keg, four
consumables and five kinds of ammo, each with its own outline. It
writes an OBJ per item (the Debian Blender's glTF exporter needs numpy),
a JSON with the grip and the left hand's support point, and a 128 px
Cycles icon rendered on the CPU. Materials are named after Palette
colours, and TRIM2_/TRIM3_ surfaces are the tier treatment: rope
whipping from tier 2, brass bands from tier 3; tier 0 is faded.

ItemModels paints the models from Palette by tier. EntityView puts the
held item's grip in each figure's right hand, turned with the player's
pitch and put away aboard, falling, gliding or swimming, and draws
items lying in the world with their models, one MultiMesh per model
and tier. The hotbar shows each slot's icon.

make models rebuilds them; make item-captures renders the items held,
over the shoulder, on the ground and by tier.

Closes #44

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 14:46:41 -05:00
co-authored by Claude Opus 5.5
parent 2545337204
commit 0991f27700
127 changed files with 22903 additions and 28 deletions
+118 -12
View File
@@ -1,8 +1,10 @@
## Draws what moves in a match: players, the sky barge while it crosses, items lying
## in the world and sea chests. `sync()` matches everything to the simulation as it is
## 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. Nothing here is ever used for collision.
## 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.
class_name EntityView
extends Node3D
@@ -22,6 +24,10 @@ 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
## The entity drawn in the brightest oilskin, or 0.
var local_id: int = 0
@@ -33,7 +39,9 @@ var _sim: Simulation
## Entity ID -> the figure's root node.
var _figures: Dictionary = {}
var _barge: Node3D
var _pickups: MultiMeshInstance3D
## Items lying in the world: one MultiMeshInstance3D per item model and tier.
var _pickups: Node3D
var _pickup_fields: Dictionary = {}
var _chests: MultiMeshInstance3D
@@ -42,7 +50,8 @@ func setup(sim: Simulation) -> void:
_barge = _build_barge()
_barge.visible = false
add_child(_barge)
_pickups = _box_field("Pickups", Vector3(0.34, 0.34, 0.34), true)
_pickups = Node3D.new()
_pickups.name = "Pickups"
add_child(_pickups)
_chests = _box_field("Chests", Vector3(0.9, 0.55, 0.6), false)
add_child(_chests)
@@ -62,6 +71,31 @@ func barge() -> Node3D:
return _barge
## Items drawn lying in the world.
func pickup_count() -> int:
var total: int = 0
for field: MultiMeshInstance3D in _pickup_fields.values():
total += field.multimesh.instance_count
return total
## The catalog code of the item a player holds: -1 for the boathook. A full copy of
## the player (the server's, or the client's own) knows its slots; others carry the
## held code the snapshot gave them.
static func held_code(entity: SimEntity) -> int:
if entity.slot_items.size() > 0:
var slot: int = entity.selected - 1
return entity.slot_items[slot] if slot >= 0 and slot < entity.slot_items.size() else -1
return entity.item
static func held_tier(entity: SimEntity) -> int:
var slot: int = entity.selected - 1
if slot >= 0 and slot < entity.slot_tiers.size():
return entity.slot_tiers[slot]
return 1
func sync() -> void:
if _sim == null:
return
@@ -99,18 +133,13 @@ func sync() -> void:
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):
_figures[entity_id].queue_free()
_figures.erase(entity_id)
var items: MultiMesh = _pickups.multimesh
items.instance_count = _sim.pickups.size()
for index: int in _sim.pickups.size():
var pickup: SimEntity = _sim.entities.find(_sim.pickups[index])
var at: Vector3 = pickup.position + Vector3(0.0, 0.3, 0.0) if pickup != null else Vector3(0.0, -1000.0, 0.0)
items.set_instance_transform(index, Transform3D(Basis(Vector3.UP, 0.6 * index), at))
items.set_instance_color(index, ITEM)
_sync_pickups()
var chests: MultiMesh = _chests.multimesh
chests.instance_count = _sim.loot.chest_positions.size()
for index: int in _sim.loot.chest_positions.size():
@@ -122,6 +151,76 @@ func _process(_delta: float) -> void:
sync()
## 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")
var busy: bool = entity.drop_state != Drop.NONE or entity.swimming or entity.eliminated
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)
func _sync_pickups() -> void:
var groups: Dictionary = {}
for index: int in _sim.pickups.size():
var pickup: SimEntity = _sim.entities.find(_sim.pickups[index])
if pickup == null:
continue
var id: String = ItemModels.id_of(pickup.item)
var key: String = "%s@%d" % [id, ItemModels.shown_tier(id, pickup.item_tier)]
if not groups.has(key):
groups[key] = []
groups[key].append(pickup)
for key: String in _pickup_fields.keys():
if not groups.has(key):
_pickup_fields[key].multimesh.instance_count = 0
for key: String in groups:
var field: MultiMeshInstance3D = _pickup_fields.get(key)
if field == null:
field = _item_field(key)
_pickup_fields[key] = field
_pickups.add_child(field)
var lying: Array = groups[key]
var lift: float = pickup_lift(field.multimesh.mesh)
field.multimesh.instance_count = lying.size()
for index: int in lying.size():
var pickup: SimEntity = lying[index]
# Laid on their side, turned by ID so a pile doesn't line up.
var basis: Basis = Basis(Vector3.UP, 0.9 * pickup.id).scaled(Vector3.ONE * PICKUP_SCALE)
field.multimesh.set_instance_transform(index, Transform3D(basis, pickup.position + Vector3(0.0, lift, 0.0)))
## How far above the spot an item lying there is placed, so the model's lowest point,
## not its grip, rests on the ground.
static func pickup_lift(mesh: Mesh) -> float:
return 0.02 - mesh.get_aabb().position.y * PICKUP_SCALE
func _item_field(key: String) -> MultiMeshInstance3D:
var multimesh: MultiMesh = MultiMesh.new()
multimesh.transform_format = MultiMesh.TRANSFORM_3D
var mesh: ArrayMesh = ItemModels.model(key.get_slice("@", 0), key.get_slice("@", 1).to_int())
if mesh == null:
var stand_in: BoxMesh = BoxMesh.new()
stand_in.size = Vector3(0.25, 0.25, 0.25)
multimesh.mesh = stand_in
else:
multimesh.mesh = mesh
var field: MultiMeshInstance3D = MultiMeshInstance3D.new()
field.name = key.replace("@", "_")
field.multimesh = multimesh
field.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
return field
func _build_figure(entity_id: int) -> Node3D:
var coat: Color = OILSKINS[0] if entity_id == local_id else OILSKINS[1 + entity_id % (OILSKINS.size() - 1)]
var figure: Node3D = Node3D.new()
@@ -150,6 +249,13 @@ func _build_figure(entity_id: int) -> Node3D:
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