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:
@@ -0,0 +1,310 @@
|
||||
## The figure's animations (A2) as key poses, turned into Animation resources for
|
||||
## FigureRig. Each pose maps a joint to its rotation in degrees (Euler, Godot's YXZ
|
||||
## order), from the rest pose: standing straight, arms hanging. "lift" moves the hips
|
||||
## from their rest height, in metres.
|
||||
##
|
||||
## Which way is which, for a figure facing +Z with its right toward -X:
|
||||
## - limbs hang down, so a negative X turn swings a leg or arm forward;
|
||||
## - the waist and neck stand up, so a positive X turn leans forward or looks down;
|
||||
## - a negative Z turn takes a right limb out to the side, a positive one a left limb.
|
||||
class_name FigurePoses
|
||||
extends RefCounted
|
||||
|
||||
const ARMS: Array[String] = ["shoulder_r", "elbow_r", "shoulder_l", "elbow_l"]
|
||||
const ARMS_AND_HEAD: Array[String] = ["shoulder_r", "elbow_r", "shoulder_l", "elbow_l", "neck"]
|
||||
const UPPER: Array[String] = ["waist", "neck", "shoulder_r", "elbow_r", "shoulder_l", "elbow_l"]
|
||||
## A flinch moves only the chest and head, so the arms keep their hold.
|
||||
const TORSO: Array[String] = ["waist", "neck"]
|
||||
|
||||
const PATHS: Dictionary = {
|
||||
"hips": "hips",
|
||||
"waist": "hips/waist",
|
||||
"neck": "hips/waist/spine/neck",
|
||||
"shoulder_r": "hips/waist/spine/shoulder_r",
|
||||
"elbow_r": "hips/waist/spine/shoulder_r/elbow_r",
|
||||
"shoulder_l": "hips/waist/spine/shoulder_l",
|
||||
"elbow_l": "hips/waist/spine/shoulder_l/elbow_l",
|
||||
"hip_r": "hips/hip_r",
|
||||
"knee_r": "hips/hip_r/knee_r",
|
||||
"hip_l": "hips/hip_l",
|
||||
"knee_l": "hips/hip_l/knee_l",
|
||||
}
|
||||
|
||||
## Arms a little away from the coat, as they hang at rest.
|
||||
const EASE: Dictionary = {"shoulder_r": Vector3(0, 0, -6), "shoulder_l": Vector3(0, 0, 6), "elbow_r": Vector3(-8, 0, 0), "elbow_l": Vector3(-8, 0, 0)}
|
||||
|
||||
## Name -> [length in seconds, loops, keys as [time, pose] in time order]. A looping
|
||||
## clip's last key is its first again, added by animation().
|
||||
static var _all: Dictionary = {}
|
||||
|
||||
|
||||
static func clips() -> Dictionary:
|
||||
if _all.is_empty():
|
||||
_all = _clips()
|
||||
return _all
|
||||
|
||||
|
||||
static func path_of(joint: String) -> String:
|
||||
return PATHS[joint]
|
||||
|
||||
|
||||
## The pose with right and left swapped, as the other half of a stride.
|
||||
static func mirror(pose: Dictionary) -> Dictionary:
|
||||
var out: Dictionary = {}
|
||||
for key: String in pose:
|
||||
var value: Variant = pose[key]
|
||||
var other: String = key
|
||||
if key.ends_with("_r"):
|
||||
other = key.trim_suffix("_r") + "_l"
|
||||
elif key.ends_with("_l"):
|
||||
other = key.trim_suffix("_l") + "_r"
|
||||
if value is Vector3 and key != "lift":
|
||||
var turn: Vector3 = value
|
||||
out[other] = Vector3(turn.x, -turn.y, -turn.z)
|
||||
else:
|
||||
out[other] = value
|
||||
return out
|
||||
|
||||
|
||||
## `pose` laid over `base`: joints in `pose` replace those in `base`.
|
||||
static func over(base: Dictionary, pose: Dictionary) -> Dictionary:
|
||||
var out: Dictionary = base.duplicate()
|
||||
for key: String in pose:
|
||||
out[key] = pose[key]
|
||||
return out
|
||||
|
||||
|
||||
## Builds a clip. `rest` is figure.json's joints, for the hips' rest position.
|
||||
static func animation(name: String, rest: Dictionary) -> Animation:
|
||||
var clip: Array = clips()[name]
|
||||
var length: float = clip[0]
|
||||
var loops: bool = clip[1]
|
||||
var keys: Array = (clip[2] as Array).duplicate()
|
||||
if loops:
|
||||
keys.append([length, (keys[0] as Array)[1]])
|
||||
var made: Animation = Animation.new()
|
||||
made.length = length
|
||||
made.loop_mode = Animation.LOOP_LINEAR if loops else Animation.LOOP_NONE
|
||||
var hips_rest: Array = rest.get("hips", [0.0, 0.92, 0.0])
|
||||
var hips_at: Vector3 = Vector3(float(hips_rest[0]), float(hips_rest[1]), float(hips_rest[2]))
|
||||
var lift_track: int = made.add_track(Animation.TYPE_POSITION_3D)
|
||||
made.track_set_path(lift_track, NodePath(PATHS["hips"]))
|
||||
for joint: String in PATHS:
|
||||
var track: int = made.add_track(Animation.TYPE_ROTATION_3D)
|
||||
made.track_set_path(track, NodePath(PATHS[joint]))
|
||||
for key: Array in keys:
|
||||
var pose: Dictionary = key[1]
|
||||
var degrees: Vector3 = pose.get(joint, Vector3.ZERO)
|
||||
made.rotation_track_insert_key(track, float(key[0]), Basis.from_euler(degrees * (PI / 180.0)).get_rotation_quaternion())
|
||||
for key: Array in keys:
|
||||
var pose: Dictionary = key[1]
|
||||
made.position_track_insert_key(lift_track, float(key[0]), hips_at + (pose.get("lift", Vector3.ZERO) as Vector3))
|
||||
return made
|
||||
|
||||
|
||||
static func _clips() -> Dictionary:
|
||||
var clips: Dictionary = {}
|
||||
var stand: Dictionary = EASE.duplicate()
|
||||
|
||||
# Standing: slow breath, a little shift of weight.
|
||||
clips["idle"] = [2.4, true, [
|
||||
[0.0, over(stand, {"waist": Vector3(2, 0, 0)})],
|
||||
[1.2, over(stand, {"waist": Vector3(4, 2, 0), "neck": Vector3(-2, -3, 0), "shoulder_r": Vector3(0, 0, -8), "shoulder_l": Vector3(0, 0, 8), "lift": Vector3(0, -0.012, 0)})],
|
||||
]]
|
||||
clips["aboard"] = [3.0, true, [
|
||||
[0.0, over(stand, {"waist": Vector3(3, 0, 0), "hip_r": Vector3(0, 0, -6), "hip_l": Vector3(0, 0, 6), "lift": Vector3(0, -0.01, 0)})],
|
||||
[1.5, over(stand, {"waist": Vector3(3, 0, -3), "neck": Vector3(6, 8, 0), "hip_r": Vector3(0, 0, -6), "hip_l": Vector3(0, 0, 6), "lift": Vector3(0, -0.02, 0)})],
|
||||
]]
|
||||
|
||||
# Walking: right foot forward at 0, passing at a quarter, left forward at a half.
|
||||
var walk_contact: Dictionary = {
|
||||
"hip_r": Vector3(-28, 0, 0), "knee_r": Vector3(8, 0, 0),
|
||||
"hip_l": Vector3(22, 0, 0), "knee_l": Vector3(22, 0, 0),
|
||||
"shoulder_r": Vector3(20, 0, -6), "shoulder_l": Vector3(-20, 0, 6),
|
||||
"elbow_r": Vector3(-10, 0, 0), "elbow_l": Vector3(-28, 0, 0),
|
||||
"waist": Vector3(4, -5, 0), "hips": Vector3(0, 6, 0), "lift": Vector3(0, -0.035, 0),
|
||||
}
|
||||
var walk_pass: Dictionary = {
|
||||
"hip_r": Vector3(2, 0, 0), "knee_r": Vector3(4, 0, 0),
|
||||
"hip_l": Vector3(-12, 0, 0), "knee_l": Vector3(48, 0, 0),
|
||||
"shoulder_r": Vector3(0, 0, -6), "shoulder_l": Vector3(0, 0, 6),
|
||||
"elbow_r": Vector3(-14, 0, 0), "elbow_l": Vector3(-14, 0, 0),
|
||||
"waist": Vector3(4, 0, 0), "lift": Vector3(0, 0.015, 0),
|
||||
}
|
||||
clips["walk"] = [0.72, true, [
|
||||
[0.0, walk_contact], [0.18, walk_pass], [0.36, mirror(walk_contact)], [0.54, mirror(walk_pass)],
|
||||
]]
|
||||
var run_contact: Dictionary = {
|
||||
"hip_r": Vector3(-48, 0, 0), "knee_r": Vector3(22, 0, 0),
|
||||
"hip_l": Vector3(30, 0, 0), "knee_l": Vector3(70, 0, 0),
|
||||
"shoulder_r": Vector3(42, 0, -8), "shoulder_l": Vector3(-46, 0, 8),
|
||||
"elbow_r": Vector3(-60, 0, 0), "elbow_l": Vector3(-95, 0, 0),
|
||||
"waist": Vector3(12, -9, 0), "hips": Vector3(4, 9, 0), "neck": Vector3(-8, 4, 0), "lift": Vector3(0, -0.05, 0),
|
||||
}
|
||||
var run_flight: Dictionary = {
|
||||
"hip_r": Vector3(-10, 0, 0), "knee_r": Vector3(30, 0, 0),
|
||||
"hip_l": Vector3(-30, 0, 0), "knee_l": Vector3(95, 0, 0),
|
||||
"shoulder_r": Vector3(5, 0, -8), "shoulder_l": Vector3(-5, 0, 8),
|
||||
"elbow_r": Vector3(-80, 0, 0), "elbow_l": Vector3(-80, 0, 0),
|
||||
"waist": Vector3(12, 0, 0), "hips": Vector3(4, 0, 0), "neck": Vector3(-8, 0, 0), "lift": Vector3(0, 0.06, 0),
|
||||
}
|
||||
clips["run"] = [0.56, true, [
|
||||
[0.0, run_contact], [0.14, run_flight], [0.28, mirror(run_contact)], [0.42, mirror(run_flight)],
|
||||
]]
|
||||
|
||||
# Crouched: hips low, knees forward, leaning in.
|
||||
var crouch: Dictionary = over(stand, {
|
||||
"hip_r": Vector3(-78, 0, -4), "knee_r": Vector3(100, 0, 0),
|
||||
"hip_l": Vector3(-62, 0, 4), "knee_l": Vector3(104, 0, 0),
|
||||
"waist": Vector3(26, 0, 0), "neck": Vector3(-20, 0, 0), "lift": Vector3(0, -0.38, 0),
|
||||
})
|
||||
clips["crouch_idle"] = [2.0, true, [
|
||||
[0.0, crouch],
|
||||
[1.0, over(crouch, {"waist": Vector3(28, 2, 0), "lift": Vector3(0, -0.39, 0)})],
|
||||
]]
|
||||
var creep: Dictionary = over(crouch, {
|
||||
"hip_r": Vector3(-92, 0, -4), "knee_r": Vector3(98, 0, 0),
|
||||
"hip_l": Vector3(-50, 0, 4), "knee_l": Vector3(108, 0, 0),
|
||||
"shoulder_r": Vector3(14, 0, -8), "shoulder_l": Vector3(-14, 0, 8),
|
||||
})
|
||||
var creep_pass: Dictionary = over(crouch, {
|
||||
"hip_r": Vector3(-70, 0, -4), "knee_r": Vector3(96, 0, 0),
|
||||
"hip_l": Vector3(-80, 0, 4), "knee_l": Vector3(124, 0, 0), "lift": Vector3(0, -0.36, 0),
|
||||
})
|
||||
clips["crouch_walk"] = [0.9, true, [
|
||||
[0.0, creep], [0.225, creep_pass], [0.45, mirror(creep)], [0.675, mirror(creep_pass)],
|
||||
]]
|
||||
|
||||
# In the air from a jump or a fall: knees up, arms out for balance.
|
||||
var air: Dictionary = {
|
||||
"hip_r": Vector3(-38, 0, -4), "knee_r": Vector3(52, 0, 0),
|
||||
"hip_l": Vector3(-14, 0, 4), "knee_l": Vector3(34, 0, 0),
|
||||
"shoulder_r": Vector3(-24, 0, -38), "shoulder_l": Vector3(-24, 0, 38),
|
||||
"elbow_r": Vector3(-30, 0, 0), "elbow_l": Vector3(-30, 0, 0),
|
||||
"waist": Vector3(6, 0, 0),
|
||||
}
|
||||
clips["air"] = [0.8, true, [
|
||||
[0.0, air],
|
||||
[0.4, over(air, {"shoulder_r": Vector3(-20, 0, -46), "shoulder_l": Vector3(-20, 0, 46)})],
|
||||
]]
|
||||
|
||||
# Falling from the barge, belly down, spread out.
|
||||
var skydive: Dictionary = {
|
||||
"hips": Vector3(72, 0, 0), "waist": Vector3(6, 0, 0), "neck": Vector3(-55, 0, 0),
|
||||
"shoulder_r": Vector3(-70, 0, -70), "shoulder_l": Vector3(-70, 0, 70),
|
||||
"elbow_r": Vector3(-30, 0, 0), "elbow_l": Vector3(-30, 0, 0),
|
||||
"hip_r": Vector3(6, 0, -14), "hip_l": Vector3(6, 0, 14),
|
||||
"knee_r": Vector3(40, 0, 0), "knee_l": Vector3(40, 0, 0), "lift": Vector3(0, 0.2, 0),
|
||||
}
|
||||
clips["skydive"] = [1.0, true, [
|
||||
[0.0, skydive],
|
||||
[0.5, over(skydive, {"shoulder_r": Vector3(-74, 0, -64), "shoulder_l": Vector3(-74, 0, 64), "knee_r": Vector3(48, 0, 0), "knee_l": Vector3(34, 0, 0)})],
|
||||
]]
|
||||
|
||||
# Hanging under the wing-sail, both hands up on its lines.
|
||||
var glide: Dictionary = {
|
||||
"hips": Vector3(12, 0, 0), "waist": Vector3(-4, 0, 0), "neck": Vector3(10, 0, 0),
|
||||
"shoulder_r": Vector3(-158, 0, -16), "shoulder_l": Vector3(-158, 0, 16),
|
||||
"elbow_r": Vector3(-22, 0, 0), "elbow_l": Vector3(-22, 0, 0),
|
||||
"hip_r": Vector3(14, 0, -3), "hip_l": Vector3(10, 0, 3),
|
||||
"knee_r": Vector3(18, 0, 0), "knee_l": Vector3(26, 0, 0),
|
||||
}
|
||||
clips["glide"] = [1.6, true, [
|
||||
[0.0, glide],
|
||||
[0.8, over(glide, {"hips": Vector3(12, 0, 4), "hip_r": Vector3(8, 0, -3), "hip_l": Vector3(16, 0, 3)})],
|
||||
]]
|
||||
|
||||
# Swimming: lying along the water, a crawl stroke and a flutter kick.
|
||||
var swim: Dictionary = {
|
||||
"hips": Vector3(78, 0, 0), "waist": Vector3(-4, 0, 0), "neck": Vector3(-58, 0, 0),
|
||||
"shoulder_r": Vector3(-170, 0, -10), "elbow_r": Vector3(-10, 0, 0),
|
||||
"shoulder_l": Vector3(-30, 0, 20), "elbow_l": Vector3(-50, 0, 0),
|
||||
"hip_r": Vector3(-12, 0, -4), "knee_r": Vector3(20, 0, 0),
|
||||
"hip_l": Vector3(12, 0, 4), "knee_l": Vector3(10, 0, 0), "lift": Vector3(0, 0.18, 0),
|
||||
}
|
||||
var swim_pull: Dictionary = over(swim, {
|
||||
"shoulder_r": Vector3(-90, 0, -6), "elbow_r": Vector3(-30, 0, 0),
|
||||
"shoulder_l": Vector3(-110, 0, 46), "elbow_l": Vector3(-80, 0, 0),
|
||||
"hip_r": Vector3(12, 0, -4), "hip_l": Vector3(-12, 0, 4), "waist": Vector3(-4, 10, 0),
|
||||
})
|
||||
clips["swim"] = [1.3, true, [
|
||||
[0.0, swim], [0.325, swim_pull], [0.65, mirror(swim)], [0.975, mirror(swim_pull)],
|
||||
]]
|
||||
|
||||
# How the held item is carried (arms only).
|
||||
# Long things at the chest, the right hand at the grip and the left reaching
|
||||
# along to the fore-end.
|
||||
clips["hold_long"] = [1.0, true, [[0.0, {
|
||||
"shoulder_r": Vector3(2, 0, 12), "elbow_r": Vector3(-92, 0, 0),
|
||||
"shoulder_l": Vector3(-62, 0, -22), "elbow_l": Vector3(-16, 0, 0),
|
||||
}]]]
|
||||
clips["hold_short"] = [1.0, true, [[0.0, {
|
||||
"shoulder_r": Vector3(-72, 0, 10), "elbow_r": Vector3(-14, 0, 0),
|
||||
"shoulder_l": Vector3(4, 0, 8), "elbow_l": Vector3(-22, 0, 0),
|
||||
}]]]
|
||||
clips["hold_carry"] = [1.0, true, [[0.0, {
|
||||
"shoulder_r": Vector3(-36, 0, 14), "elbow_r": Vector3(-74, 0, 0),
|
||||
"shoulder_l": Vector3(-30, 0, -14), "elbow_l": Vector3(-70, 0, 0),
|
||||
}]]]
|
||||
|
||||
# Reloading: the left hand works at the breech, the head bent to it.
|
||||
var reload: Dictionary = {
|
||||
"shoulder_r": Vector3(-28, 0, 18), "elbow_r": Vector3(-78, 0, 0),
|
||||
"shoulder_l": Vector3(-46, 0, -30), "elbow_l": Vector3(-96, 0, 0), "neck": Vector3(22, 0, 0),
|
||||
}
|
||||
clips["reload"] = [0.8, true, [
|
||||
[0.0, reload],
|
||||
[0.4, over(reload, {"shoulder_l": Vector3(-30, 0, -20), "elbow_l": Vector3(-112, 0, 0)})],
|
||||
]]
|
||||
# Using something: the hand to the mouth, head back.
|
||||
var use: Dictionary = {
|
||||
"shoulder_r": Vector3(-58, 0, 34), "elbow_r": Vector3(-128, 0, 0),
|
||||
"shoulder_l": Vector3(-6, 0, 8), "elbow_l": Vector3(-20, 0, 0), "neck": Vector3(-18, 0, 0),
|
||||
}
|
||||
clips["use"] = [1.0, true, [
|
||||
[0.0, use],
|
||||
[0.5, over(use, {"neck": Vector3(-24, 0, 0), "elbow_r": Vector3(-134, 0, 0)})],
|
||||
]]
|
||||
|
||||
# One-off actions on the upper body, each starting and ending at its carry.
|
||||
var long: Dictionary = (clips["hold_long"][2][0][1] as Dictionary).duplicate()
|
||||
var short: Dictionary = (clips["hold_short"][2][0][1] as Dictionary).duplicate()
|
||||
clips["fire_long"] = [0.28, false, [
|
||||
[0.0, over(long, {"waist": Vector3(0, 0, 0)})],
|
||||
[0.04, over(long, {"waist": Vector3(-6, 3, 0), "neck": Vector3(-4, 0, 0), "shoulder_r": Vector3(-26, 0, 18), "elbow_r": Vector3(-62, 0, 0)})],
|
||||
[0.28, over(long, {"waist": Vector3(0, 0, 0)})],
|
||||
]]
|
||||
clips["fire_short"] = [0.25, false, [
|
||||
[0.0, short],
|
||||
[0.04, over(short, {"shoulder_r": Vector3(-92, 0, 10), "elbow_r": Vector3(-30, 0, 0), "waist": Vector3(-3, 0, 0)})],
|
||||
[0.25, short],
|
||||
]]
|
||||
clips["swing"] = [0.5, false, [
|
||||
[0.0, long],
|
||||
[0.16, over(long, {"waist": Vector3(-6, 32, 0), "shoulder_r": Vector3(-140, 0, -20), "elbow_r": Vector3(-70, 0, 0), "shoulder_l": Vector3(-120, 0, -10), "elbow_l": Vector3(-60, 0, 0)})],
|
||||
[0.26, over(long, {"waist": Vector3(18, -24, 0), "shoulder_r": Vector3(-50, 0, 20), "elbow_r": Vector3(-10, 0, 0), "shoulder_l": Vector3(-56, 0, -30), "elbow_l": Vector3(-20, 0, 0), "neck": Vector3(10, 0, 0)})],
|
||||
[0.5, long],
|
||||
]]
|
||||
var carry: Dictionary = (clips["hold_carry"][2][0][1] as Dictionary).duplicate()
|
||||
clips["throw"] = [0.55, false, [
|
||||
[0.0, carry],
|
||||
[0.2, over(carry, {"waist": Vector3(-10, 20, 0), "shoulder_r": Vector3(-160, 0, -24), "elbow_r": Vector3(-80, 0, 0), "shoulder_l": Vector3(-60, 0, 10)})],
|
||||
[0.32, over(carry, {"waist": Vector3(16, -16, 0), "shoulder_r": Vector3(-70, 0, 6), "elbow_r": Vector3(-6, 0, 0)})],
|
||||
[0.55, carry],
|
||||
]]
|
||||
# Building: two strokes of a mallet.
|
||||
clips["build"] = [0.5, false, [
|
||||
[0.0, long],
|
||||
[0.1, over(long, {"shoulder_r": Vector3(-128, 0, 0), "elbow_r": Vector3(-96, 0, 0), "waist": Vector3(-4, 0, 0)})],
|
||||
[0.2, over(long, {"shoulder_r": Vector3(-56, 0, 10), "elbow_r": Vector3(-22, 0, 0), "waist": Vector3(14, 0, 0), "neck": Vector3(14, 0, 0)})],
|
||||
[0.3, over(long, {"shoulder_r": Vector3(-120, 0, 0), "elbow_r": Vector3(-92, 0, 0)})],
|
||||
[0.4, over(long, {"shoulder_r": Vector3(-56, 0, 10), "elbow_r": Vector3(-22, 0, 0), "waist": Vector3(14, 0, 0), "neck": Vector3(14, 0, 0)})],
|
||||
[0.5, long],
|
||||
]]
|
||||
# Struck: the chest jerks back and the head turns away (the waist and neck only).
|
||||
clips["flinch"] = [0.32, false, [
|
||||
[0.0, {}],
|
||||
[0.06, {"waist": Vector3(-14, 10, 5), "neck": Vector3(-16, -14, 0)}],
|
||||
[0.32, {}],
|
||||
]]
|
||||
return clips
|
||||
Reference in New Issue
Block a user