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
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/items_scene.gd" id="1"]
[node name="CaptureItems" type="Node3D"]
script = ExtResource("1")
stage = "ground"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/items_scene.gd" id="1"]
[node name="CaptureItems" type="Node3D"]
script = ExtResource("1")
stage = "held"
+113
View File
@@ -0,0 +1,113 @@
## Capture scenario for item models (A4), on seed 2's island in the real MatchView:
##
## - held: a row of players, each holding a different weapon or consumable, seen from
## their right side, so the grips can be checked against the hands.
## - shoulder: the over-the-shoulder view of a player holding the whaler's longgun, as
## the game's camera has it, aiming down the sight line.
## - ground: every item lying on the ground, at a mix of tiers, from above.
## - tiers: the dock carbine at tiers 0 to 3, side by side, held.
extends Node3D
@export var stage: String = "held"
@export var match_seed: int = 2
const HELD: Array[String] = [
"boathook", "fowling_piece", "dock_carbine", "signal_revolver", "rivet_repeater",
"whalers_longgun", "line_thrower", "harpoon_gun", "powder_keg", "brine_tonic",
]
var sim: Simulation
var view: MatchView
func _ready() -> void:
sim = Simulation.new(match_seed)
var spot: Vector3 = _open_ground()
match stage:
"held":
_row(spot, HELD, [])
"tiers":
_row(spot, ["dock_carbine", "dock_carbine", "dock_carbine", "dock_carbine"], [0, 1, 2, 3])
"shoulder":
_row(spot, ["whalers_longgun"], [])
"ground":
_lay_out(spot)
view = MatchView.new()
view.setup(sim, 0)
add_child(view)
view.sync()
match stage:
"held", "tiers":
var count: int = HELD.size() if stage == "held" else 4
var middle: Vector3 = _at(spot, (count - 1) * 0.5)
# From the players' right (-X of a figure facing +Z), a little ahead.
var back: float = 5.5 + count * 0.25 if stage == "held" else 2.6
var eye: Vector3 = middle + Vector3(-back, 1.6, 0.8)
view.look_from(eye, middle + Vector3(0.0, 1.0, 0.0))
"shoulder":
var id: int = sim.entities.entities()[0].id
view.rig.aim_blend = 1.0
view.follow(id, deg_to_rad(4.0))
"ground":
view.look_from(spot + Vector3(0.0, 5.0, -3.6), spot + Vector3(0.0, 0.0, 1.8))
view.settle()
func _at(spot: Vector3, index: float) -> Vector3:
var at: Vector3 = spot + Vector3(0.0, 0.0, index * 1.7 - 6.0)
at.y = sim.ground.terrain_height(at.x, at.z)
return at
func _row(spot: Vector3, items: Array, tiers: Array) -> void:
for index: int in items.size():
var player: SimEntity = sim.entities.find(sim.add_player())
player.position = _at(spot, index)
player.drop_state = Drop.NONE
player.on_ground = true
player.health = 100
player.yaw = 0
var id: String = items[index]
if id == ItemCatalog.BOATHOOK:
player.selected = 0
continue
player.slot_items[0] = ItemCatalog.code_of(id)
player.slot_counts[0] = 1
player.slot_tiers[0] = int(tiers[index]) if index < tiers.size() else 1
player.selected = 1
func _lay_out(spot: Vector3) -> void:
var ids: Array[String] = ItemModels.ids()
for index: int in ids.size():
var code: int = ItemCatalog.code_of(ids[index])
var x: float = (index % 6 - 2.5) * 2.2
var z: float = (index / 6) * 1.6
var at: Vector3 = spot + Vector3(x, 0.0, z)
at.y = sim.ground.terrain_height(at.x, at.z)
if code < 0:
continue
Inventory.spawn_pickup(sim, at, code, 1, -1, index % 4)
## Fairly flat, open ground above the sea near the middle of the island.
func _open_ground() -> Vector3:
var size: float = Tuning.WORLD_SIZE_METRES
var best: Vector3 = Vector3(size * 0.5, 0.0, size * 0.5)
for ring: int in 60:
for step: int in 24:
var angle: float = TAU * step / 24.0
var x: float = size * 0.5 + cos(angle) * ring * 12.0
var z: float = size * 0.5 + sin(angle) * ring * 12.0
var feet: Vector3 = Vector3(x, sim.ground.terrain_height(x, z), z)
if feet.y < sim.sea_level + 3.0 or sim.ground.terrain_normal(x, z).y < 0.985:
continue
if not sim.props.near(feet, 12.0).is_empty():
continue
var level: bool = true
for dz: float in [-7.0, 0.0, 9.0]:
if absf(sim.ground.terrain_height(x - 2.0, z + dz) - feet.y) > 0.8:
level = false
if level:
return feet
return best
+1
View File
@@ -0,0 +1 @@
uid://b0gws66qbu53s
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/items_scene.gd" id="1"]
[node name="CaptureItems" type="Node3D"]
script = ExtResource("1")
stage = "shoulder"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/items_scene.gd" id="1"]
[node name="CaptureItems" type="Node3D"]
script = ExtResource("1")
stage = "tiers"
+153
View File
@@ -0,0 +1,153 @@
extends TestCase
## A4: every item has a model, an icon and attachment data; models are painted from the
## Palette with their tier's treatment; figures hold what their players hold, and items
## lying in the world are drawn with their models.
const SIDE: Vector3 = Vector3(1.0, 0.0, 0.0)
func after_each() -> void:
ItemModels.clear()
super.after_each()
func test_every_item_has_a_model_an_icon_and_a_grip() -> void:
var ids: Array[String] = ItemModels.ids()
assert_eq(ids.size(), ItemCatalog.count() + 1, "the boathook and every catalog item")
for id: String in ids:
var mesh: ArrayMesh = ItemModels.model(id)
assert_not_null(mesh, "%s has a model" % id)
var picture: Texture2D = ItemModels.icon(id)
assert_not_null(picture, "%s has an icon" % id)
if picture != null:
assert_eq(picture.get_size(), Vector2(128, 128), "%s's icon size" % id)
var info: Dictionary = ItemModels.info(id)
assert_eq(info.get("generator", ""), "tools/models/items.py", "%s says what made it" % id)
if mesh == null:
continue
var bounds: AABB = mesh.get_aabb()
assert_true(bounds.has_point(Vector3.ZERO) or bounds.grow(0.05).has_point(Vector3.ZERO), "%s's grip is on the model" % id)
assert_true(bounds.size.length() > 0.08 and bounds.size.length() < 2.5, "%s is item-sized: %s" % [id, bounds.size])
func test_weapons_point_forward_and_long_ones_have_a_support_point() -> void:
for id: String in ["fowling_piece", "dock_carbine", "whalers_longgun", "line_thrower", "harpoon_gun", "rivet_repeater", "boathook"]:
var bounds: AABB = ItemModels.model(id).get_aabb()
assert_true(bounds.end.z > -bounds.position.z, "%s's working end is toward +Z" % id)
var support: Variant = ItemModels.info(id).get("support")
assert_true(support is Array, "%s has a place for the left hand" % id)
if support is Array:
assert_true(float(support[2]) > 0.1, "%s's support is ahead of the grip" % id)
func test_silhouettes_differ() -> void:
var seen: Dictionary = {}
for id: String in ItemModels.ids():
var size: Vector3 = ItemModels.model(id).get_aabb().size
var key: String = "%.2f,%.2f,%.2f" % [size.x, size.y, size.z]
assert_false(seen.has(key), "%s has its own outline, not %s's" % [id, seen.get(key, "")])
seen[key] = id
func test_models_are_painted_from_the_palette() -> void:
for id: String in ItemModels.ids():
var mesh: ArrayMesh = ItemModels.model(id, 3)
for surface: int in mesh.get_surface_count():
var name: String = mesh.surface_get_name(surface)
assert_not_null(ItemModels.colour_of(name, 1), "%s's material %s is a Palette colour" % [id, name])
var paint: StandardMaterial3D = mesh.surface_get_material(surface) as StandardMaterial3D
assert_eq(paint.albedo_color, ItemModels.colour_of(name, 3))
func test_tiers_add_trim_and_tier_zero_is_weathered() -> void:
var counts: Array[int] = []
for tier: int in 4:
counts.append(ItemModels.model("dock_carbine", tier).get_surface_count())
assert_eq(counts[0], counts[1], "tiers 0 and 1 have the same parts")
assert_true(counts[2] > counts[1], "rope whipping from tier 2: %s" % [counts])
assert_true(counts[3] > counts[2], "brass bands from tier 3: %s" % [counts])
assert_ne(ItemModels.colour_of("SALVAGE_IRON", 0), ItemModels.colour_of("SALVAGE_IRON", 1), "tier 0 is faded")
assert_eq(ItemModels.trim_level("TRIM3_GILT"), 3)
assert_eq(ItemModels.colour_of("TRIM3_GILT", 3), Palette.GILT)
assert_null(ItemModels.colour_of("NEON", 1))
func _world_with_player(code: int, tier: int) -> Array:
var sim: Simulation = Simulation.new(4, SimGround.flat(0.0))
var player: SimEntity = sim.entities.find(sim.add_player())
player.drop_state = Drop.NONE
if code >= 0:
player.slot_items[0] = code
player.slot_counts[0] = 1
player.slot_tiers[0] = tier
player.selected = 1
return [sim, player]
func test_figures_hold_their_players_item_in_the_right_hand() -> void:
var made: Array = _world_with_player(ItemCatalog.code_of("whalers_longgun"), 3)
var sim: Simulation = made[0]
var player: SimEntity = made[1]
var view: EntityView = EntityView.new()
view.setup(sim)
var figure: Node3D = view.figure_of(player.id)
var held: MeshInstance3D = figure.get_node("Hand/Held")
assert_eq(held.mesh, ItemModels.model("whalers_longgun", 3))
assert_true((figure.get_node("Hand") as Node3D).position.x < 0.0, "the right hand, on the figure's -X side")
player.selected = 0
view.sync()
assert_eq(held.mesh, ItemModels.model("boathook", 1), "the boathook when nothing else is held")
player.pitch = PlayerCommand.PITCH_MAX / 2
view.sync()
var muzzle: Vector3 = (figure.get_node("Hand") as Node3D).transform.basis * Vector3(0.0, 0.0, 1.0)
assert_true(muzzle.y > 0.5, "looking up points the item up")
player.drop_state = Drop.GLIDING
view.sync()
assert_false((figure.get_node("Hand") as Node3D).visible, "both hands on the wing-sail")
view.free()
func test_others_hold_what_the_snapshot_says() -> void:
var sim: Simulation = Simulation.new(4, SimGround.flat(0.0))
var player: SimEntity = sim.entities.create(SimEntity.ARCHETYPE_PLAYER)
player.item = ItemCatalog.code_of("harpoon_gun")
assert_eq(EntityView.held_code(player), player.item, "no slots known: the snapshot's held code")
player.slot_items = PackedInt32Array([ItemCatalog.code_of("dock_carbine"), -1])
player.selected = 1
assert_eq(EntityView.held_code(player), ItemCatalog.code_of("dock_carbine"))
player.selected = 0
assert_eq(EntityView.held_code(player), -1, "the boathook")
func test_pickups_are_drawn_with_their_models() -> void:
var sim: Simulation = Simulation.new(4, SimGround.flat(0.0))
Inventory.spawn_pickup(sim, Vector3(5, 0, 5), ItemCatalog.code_of("brine_tonic"), 1)
Inventory.spawn_pickup(sim, Vector3(6, 0, 5), ItemCatalog.code_of("brine_tonic"), 1)
Inventory.spawn_pickup(sim, Vector3(7, 0, 5), ItemCatalog.code_of("fowling_piece"), 1, 2, 2)
var view: EntityView = EntityView.new()
view.setup(sim)
assert_eq(view.pickup_count(), 3)
var field: MultiMeshInstance3D = view.get_node("Pickups/brine_tonic_1")
assert_not_null(field, "one field per model and tier")
assert_eq(field.multimesh.instance_count, 2)
assert_eq(field.multimesh.mesh, ItemModels.model("brine_tonic", 1), "consumables have no tiers")
for id: String in ItemModels.ids():
var mesh: ArrayMesh = ItemModels.model(id)
var lowest: float = EntityView.pickup_lift(mesh) + mesh.get_aabb().position.y * EntityView.PICKUP_SCALE
assert_near(lowest, 0.02, 0.001, "%s rests on the ground, not sunk into it" % id)
sim.pickups.clear()
view.sync()
assert_eq(view.pickup_count(), 0)
view.free()
func test_the_hotbar_shows_icons() -> void:
var made: Array = _world_with_player(ItemCatalog.code_of("dock_carbine"), 1)
var player: SimEntity = made[1]
var state: HudState = HudState.new()
state.playing = true
HudState._fill_carried(state, player)
assert_eq(state.slots[0]["id"], ItemCatalog.BOATHOOK)
assert_eq(state.slots[1]["id"], "dock_carbine")
assert_not_null(ItemModels.icon(String(state.slots[1]["id"])))
+1
View File
@@ -0,0 +1 @@
uid://b0wsq2r5dcflt
+2 -2
View File
@@ -17,7 +17,7 @@ func test_draws_every_player_and_the_barge() -> void:
assert_true(view.entities.barge().position.distance_to(loop.sim.drop.barge_position(loop.sim.tick)) < 0.001)
# Passengers are spread over the deck, not stacked on one spot.
assert_true(view.entities.figure_of(1).position.distance_to(view.entities.figure_of(2).position) > 1.0)
assert_eq(view.entities.get_node("Pickups").multimesh.instance_count, loop.sim.pickups.size())
assert_eq(view.entities.pickup_count(), loop.sim.pickups.size())
assert_eq(view.entities.get_node("Chests").multimesh.instance_count, loop.sim.loot.chest_positions.size())
assert_not_null(view.terrain)
view.free()
@@ -39,7 +39,7 @@ func test_follows_the_simulation() -> void:
if not bot.eliminated:
assert_true(view.entities.figure_of(2).position.distance_to(bot.position) < 0.001)
assert_near(view.water.level, 6.5, 0.001)
assert_eq(view.entities.get_node("Pickups").multimesh.instance_count, loop.sim.pickups.size())
assert_eq(view.entities.pickup_count(), loop.sim.pickups.size())
view.free()