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:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
uid://doj02kfiymqvi
|
||||
@@ -0,0 +1,438 @@
|
||||
## A player's figure (A2): the islander that tools/models/figure.py builds in Blender,
|
||||
## hung on a hierarchy of pivots and animated by an AnimationTree.
|
||||
##
|
||||
## The parts are rigid OBJ models, one per limb, each with its origin at the joint it
|
||||
## turns about (assets/models/figure/, with figure.json giving the joints). Debian's
|
||||
## Blender can't export a skinned glTF, so the figure is jointed like a carved toy
|
||||
## rather than skinned, which suits the folk-art look.
|
||||
##
|
||||
## Every animation is built here in code from key poses (FigurePoses), and played by
|
||||
## one AnimationTree:
|
||||
##
|
||||
## move Transition: ground (idle, walk, run by speed), crouch (still and
|
||||
## creeping by speed), air, skydive, glide, swim, aboard
|
||||
## hold filtered to the arms: how the held item is carried (long, short, carry)
|
||||
## reload, use filtered to the arms and head, blended in while they last
|
||||
## act OneShot on the upper body: fire_long, fire_short, swing, throw, build
|
||||
## hit OneShot flinch
|
||||
##
|
||||
## drive() sets the tree's parameters from a SimEntity, which on a network client is
|
||||
## only what snapshots and FX replicate (position, look, the FLAG_ bits, the held
|
||||
## item and health), and trigger() plays one-off actions from FX records. Nothing
|
||||
## here reads input or any other client-only state. advance() steps the tree; the
|
||||
## tree runs in manual mode so tests and captures can pose a figure exactly.
|
||||
class_name FigureRig
|
||||
extends Node3D
|
||||
|
||||
const MODEL_DIR: String = "res://assets/models/figure"
|
||||
## Joints the animations turn (and, for the hips, move). The spine and hands aren't
|
||||
## animated: the code turns the spine with the player's pitch and points the hand
|
||||
## along the aim.
|
||||
const ANIMATED: Array[String] = [
|
||||
"hips", "waist", "neck", "shoulder_r", "elbow_r", "shoulder_l", "elbow_l",
|
||||
"hip_r", "knee_r", "hip_l", "knee_l",
|
||||
]
|
||||
## Joint -> its parent pivot. "spine" sits on the waist joint and carries the chest.
|
||||
const PARENT: Dictionary = {
|
||||
"hips": "", "waist": "hips", "spine": "waist", "neck": "spine",
|
||||
"shoulder_r": "spine", "elbow_r": "shoulder_r", "shoulder_l": "spine", "elbow_l": "shoulder_l",
|
||||
"hip_r": "hips", "knee_r": "hip_r", "hip_l": "hips", "knee_l": "hip_l", "sail": "",
|
||||
}
|
||||
## Part model -> the joint pivot it hangs on.
|
||||
const PART_JOINT: Dictionary = {
|
||||
"pelvis": "hips", "torso": "spine", "head": "neck",
|
||||
"upper_arm_r": "shoulder_r", "forearm_r": "elbow_r",
|
||||
"upper_arm_l": "shoulder_l", "forearm_l": "elbow_l",
|
||||
"thigh_r": "hip_r", "shin_r": "knee_r", "thigh_l": "hip_l", "shin_l": "knee_l",
|
||||
"sail": "sail",
|
||||
}
|
||||
## Material names in the part models -> Palette colours. COAT and COAT_DARK are the
|
||||
## player's own oilskin.
|
||||
const COLOURS: Dictionary = {
|
||||
"TAR": Palette.TAR, "TAR_WEATHERED": Palette.TAR_WEATHERED, "SKIN": Palette.SKIN,
|
||||
"INK": Palette.INK, "BARK": Palette.BARK, "CANVAS": Palette.CANVAS, "GILT": Palette.GILT,
|
||||
"PLANK": Palette.PLANK, "OCHRE_RED": Palette.OCHRE_RED, "TANNED_SAIL": Palette.TANNED_SAIL,
|
||||
}
|
||||
const COAT_SHADE: float = 0.28
|
||||
## The states of `move`, in input order.
|
||||
const STATES: Array[String] = ["ground", "crouch", "air", "skydive", "glide", "swim", "aboard"]
|
||||
const HOLDS: Array[String] = ["long", "short", "carry"]
|
||||
const ACTIONS: Array[String] = ["fire_long", "fire_short", "swing", "throw", "build"]
|
||||
## How long a figure must be off the ground before it's drawn in the air, so steps
|
||||
## down a slope don't flicker into a leap.
|
||||
const AIR_DELAY: float = 0.12
|
||||
## How quickly the drawn speed follows the real one, per second.
|
||||
const SPEED_FOLLOW: float = 10.0
|
||||
## How much of the look's pitch the chest takes; the held item takes all of it.
|
||||
const SPINE_PITCH: float = 0.35
|
||||
|
||||
static var _layout: Dictionary = {}
|
||||
static var _meshes: Dictionary = {}
|
||||
static var _library: AnimationLibrary = null
|
||||
|
||||
var coat: Color = Palette.OILSKIN
|
||||
var tree: AnimationTree
|
||||
## Joint name -> its pivot node.
|
||||
var joints: Dictionary = {}
|
||||
## The state, hold and speed last driven, for tests and captures.
|
||||
var state: String = "ground"
|
||||
var hold: String = "long"
|
||||
var speed: float = 0.0
|
||||
|
||||
var _hand: Node3D
|
||||
var _held: MeshInstance3D
|
||||
var _sail: Node3D
|
||||
var _pitch: float = 0.0
|
||||
var _holding: bool = true
|
||||
var _airborne: float = 0.0
|
||||
var _last_position: Vector3 = Vector3.INF
|
||||
var _last_health: int = -1
|
||||
var _reload: float = 0.0
|
||||
var _use: float = 0.0
|
||||
var _reloading: bool = false
|
||||
var _using: bool = false
|
||||
|
||||
|
||||
## Builds the figure in `coat_colour`.
|
||||
func _init(coat_colour: Color = Palette.OILSKIN) -> void:
|
||||
coat = coat_colour
|
||||
var layout: Dictionary = FigureRig.layout()
|
||||
var at: Dictionary = layout.get("joints", {})
|
||||
for joint: String in PARENT:
|
||||
var pivot: Node3D = Node3D.new()
|
||||
pivot.name = joint
|
||||
var parent_name: String = PARENT[joint]
|
||||
var place: Vector3 = _vector(at.get("waist" if joint == "spine" else joint, [0, 0, 0]))
|
||||
if parent_name != "":
|
||||
var parent_joint: String = "waist" if parent_name == "spine" else parent_name
|
||||
place -= _vector(at.get(parent_joint, [0, 0, 0]))
|
||||
pivot.position = place
|
||||
joints[joint] = pivot
|
||||
(self if parent_name == "" else joints[parent_name] as Node3D).add_child(pivot)
|
||||
for part: String in PART_JOINT:
|
||||
var mesh: ArrayMesh = FigureRig.part_mesh(part, coat)
|
||||
if mesh == null:
|
||||
continue
|
||||
var instance: MeshInstance3D = MeshInstance3D.new()
|
||||
instance.name = part
|
||||
instance.mesh = mesh
|
||||
(joints[PART_JOINT[part]] as Node3D).add_child(instance)
|
||||
_sail = joints["sail"]
|
||||
_sail.visible = false
|
||||
_hand = Node3D.new()
|
||||
_hand.name = "hand_r"
|
||||
_hand.position = _vector(layout.get("hand_r", [-0.24, 0.86, 0.03])) - _vector(at.get("elbow_r", [0, 0, 0]))
|
||||
(joints["elbow_r"] as Node3D).add_child(_hand)
|
||||
_held = MeshInstance3D.new()
|
||||
_held.name = "Held"
|
||||
_hand.add_child(_held)
|
||||
tree = _build_tree()
|
||||
add_child(tree)
|
||||
|
||||
|
||||
## figure.json: joints, parts and hands.
|
||||
static func layout() -> Dictionary:
|
||||
if _layout.is_empty():
|
||||
var parsed: Variant = JSON.parse_string(FileAccess.get_file_as_string(MODEL_DIR + "/figure.json"))
|
||||
_layout = parsed if parsed is Dictionary else {"joints": {}}
|
||||
return _layout
|
||||
|
||||
|
||||
## A part's model painted for a coat colour; shared, so don't change it.
|
||||
static func part_mesh(part: String, coat_colour: Color) -> ArrayMesh:
|
||||
var key: String = "%s@%s" % [part, coat_colour.to_html(false)]
|
||||
if _meshes.has(key):
|
||||
return _meshes[key]
|
||||
var path: String = "%s/%s.obj" % [MODEL_DIR, part]
|
||||
var made: ArrayMesh = null
|
||||
if ResourceLoader.exists(path):
|
||||
var source: Mesh = load(path) as Mesh
|
||||
if source != null:
|
||||
made = ArrayMesh.new()
|
||||
for surface: int in source.get_surface_count():
|
||||
var material: Material = source.surface_get_material(surface)
|
||||
var name: String = material.resource_name if material != null else ""
|
||||
made.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, source.surface_get_arrays(surface))
|
||||
var paint: StandardMaterial3D = StandardMaterial3D.new()
|
||||
paint.albedo_color = colour_of(name, coat_colour)
|
||||
paint.roughness = 0.6 if name.begins_with("COAT") else 0.88
|
||||
if name == "GILT":
|
||||
paint.metallic = 0.35
|
||||
made.surface_set_material(made.get_surface_count() - 1, paint)
|
||||
made.surface_set_name(made.get_surface_count() - 1, name)
|
||||
made.resource_name = key
|
||||
_meshes[key] = made
|
||||
return made
|
||||
|
||||
|
||||
## The Palette colour of a part's material, with COAT the player's own.
|
||||
static func colour_of(material_name: String, coat_colour: Color) -> Color:
|
||||
if material_name == "COAT":
|
||||
return coat_colour
|
||||
if material_name == "COAT_DARK":
|
||||
return coat_colour.darkened(COAT_SHADE)
|
||||
return COLOURS.get(material_name, Palette.HOLD_SHADOW)
|
||||
|
||||
|
||||
## Every animation the figure has, built once from FigurePoses.
|
||||
static func library() -> AnimationLibrary:
|
||||
if _library == null:
|
||||
_library = AnimationLibrary.new()
|
||||
var rest: Dictionary = layout().get("joints", {})
|
||||
for name: String in FigurePoses.clips():
|
||||
_library.add_animation(name, FigurePoses.animation(name, rest))
|
||||
return _library
|
||||
|
||||
|
||||
static func clear() -> void:
|
||||
_meshes.clear()
|
||||
_layout.clear()
|
||||
_library = null
|
||||
|
||||
|
||||
func hand() -> Node3D:
|
||||
return _hand
|
||||
|
||||
|
||||
func held() -> MeshInstance3D:
|
||||
return _held
|
||||
|
||||
|
||||
func sail() -> Node3D:
|
||||
return _sail
|
||||
|
||||
|
||||
## Sets the tree from an entity's replicated state. `delta` is the time since the last
|
||||
## drive, for the speed it derives from movement and for the delay before the air.
|
||||
func drive(entity: SimEntity, delta: float) -> void:
|
||||
var flat: Vector3 = Vector3(entity.velocity.x, 0.0, entity.velocity.z)
|
||||
var moved: float = flat.length()
|
||||
if moved == 0.0 and _last_position != Vector3.INF and delta > 0.0:
|
||||
var step: Vector3 = entity.position - _last_position
|
||||
moved = Vector2(step.x, step.z).length() / delta
|
||||
# A jump in place (a correction, a respawn) isn't running.
|
||||
if moved > Tuning.SLIDE_MAX_SPEED * 2.0:
|
||||
moved = 0.0
|
||||
_last_position = entity.position
|
||||
speed = moved if delta <= 0.0 else lerpf(speed, moved, clampf(delta * SPEED_FOLLOW, 0.0, 1.0))
|
||||
_airborne = 0.0 if entity.on_ground or entity.swimming else _airborne + delta
|
||||
state = state_of(entity, _airborne >= AIR_DELAY)
|
||||
_holding = state in ["ground", "crouch", "air"]
|
||||
hold = hold_of(EntityView.held_code(entity))
|
||||
_reloading = entity.reload_ticks > 0 and _holding
|
||||
_using = entity.use_ticks > 0 and _holding
|
||||
if _last_health >= 0 and entity.health < _last_health and not entity.eliminated:
|
||||
flinch()
|
||||
_last_health = entity.health
|
||||
_pitch = float(entity.pitch) / PlayerCommand.PITCH_MAX * (PI * 0.5)
|
||||
_sail.visible = state == "glide"
|
||||
_hand.visible = _holding
|
||||
tree.set("parameters/move/transition_request", state)
|
||||
tree.set("parameters/ground/blend_position", speed)
|
||||
tree.set("parameters/crouch/blend_position", speed)
|
||||
tree.set("parameters/ground_pace/scale", clampf(speed / Tuning.WALK_SPEED, 0.75, 1.3) if speed > 0.3 else 1.0)
|
||||
tree.set("parameters/hold/transition_request", hold)
|
||||
tree.set("parameters/holding/blend_amount", 1.0 if _holding else 0.0)
|
||||
|
||||
|
||||
## Which of STATES an entity is drawn in.
|
||||
static func state_of(entity: SimEntity, airborne: bool) -> String:
|
||||
match entity.drop_state:
|
||||
Drop.ABOARD:
|
||||
return "aboard"
|
||||
Drop.FREEFALL:
|
||||
return "skydive"
|
||||
Drop.GLIDING:
|
||||
return "glide"
|
||||
if entity.swimming:
|
||||
return "swim"
|
||||
if airborne:
|
||||
return "air"
|
||||
return "crouch" if entity.crouching else "ground"
|
||||
|
||||
|
||||
## How an item is carried: long things in both hands, small weapons in one, and
|
||||
## everything else (tonics, bandages, kegs) held up in front.
|
||||
static func hold_of(code: int) -> String:
|
||||
var id: String = ItemModels.id_of(code)
|
||||
if ItemModels.info(id).get("support") != null:
|
||||
return "long"
|
||||
var def: ItemDef = ItemCatalog.get_def(code)
|
||||
if def != null and def.is_weapon() and id != "powder_keg":
|
||||
return "short"
|
||||
return "carry"
|
||||
|
||||
|
||||
## Plays the one-off action an FX record shows: a shot, a swing or throw, a harvest
|
||||
## hit (a swing) or a piece placed.
|
||||
func hear(record: Dictionary) -> void:
|
||||
match int(record.get("kind", 0)):
|
||||
NetFx.SHOT:
|
||||
var id: String = ItemModels.id_of(int(record.get("item", -1)))
|
||||
if id == ItemCatalog.BOATHOOK:
|
||||
act("swing")
|
||||
elif id == "powder_keg":
|
||||
act("throw")
|
||||
else:
|
||||
act("fire_long" if hold_of(int(record["item"])) == "long" else "fire_short")
|
||||
NetFx.PLACE:
|
||||
act("build")
|
||||
|
||||
|
||||
## Plays one of ACTIONS on the upper body, from its start.
|
||||
func act(action: String) -> void:
|
||||
if not ACTIONS.has(action) or not _holding:
|
||||
return
|
||||
tree.set("parameters/action/transition_request", action)
|
||||
tree.set("parameters/act/request", AnimationNodeOneShot.ONE_SHOT_REQUEST_FIRE)
|
||||
|
||||
|
||||
func flinch() -> void:
|
||||
tree.set("parameters/hit/request", AnimationNodeOneShot.ONE_SHOT_REQUEST_FIRE)
|
||||
|
||||
|
||||
## Steps the animation by `delta` and points the chest and held item along the look.
|
||||
func advance(delta: float) -> void:
|
||||
_reload = move_toward(_reload, 1.0 if _reloading else 0.0, delta * 6.0)
|
||||
_use = move_toward(_use, 1.0 if _using else 0.0, delta * 6.0)
|
||||
tree.set("parameters/reload/blend_amount", _reload)
|
||||
tree.set("parameters/use/blend_amount", _use)
|
||||
tree.advance(delta)
|
||||
_aim()
|
||||
|
||||
|
||||
## Whether an action or flinch is playing.
|
||||
func acting() -> bool:
|
||||
return bool(tree.get("parameters/act/active")) or bool(tree.get("parameters/hit/active"))
|
||||
|
||||
|
||||
## The hand's orientation relative to the figure.
|
||||
func hand_basis() -> Basis:
|
||||
return relative(_hand).basis
|
||||
|
||||
|
||||
## A node's transform relative to this figure, without needing the scene tree.
|
||||
func relative(node: Node3D) -> Transform3D:
|
||||
var out: Transform3D = Transform3D.IDENTITY
|
||||
var at: Node = node
|
||||
while at != null and at != self:
|
||||
out = (at as Node3D).transform * out
|
||||
at = at.get_parent()
|
||||
return out
|
||||
|
||||
|
||||
func _aim() -> void:
|
||||
var spine: Node3D = joints["spine"]
|
||||
spine.rotation = Vector3(-_pitch * SPINE_PITCH if _holding else 0.0, 0.0, 0.0)
|
||||
# The item points along the look whatever the arm is doing; the arm only places it.
|
||||
var parent: Transform3D = relative(_hand.get_parent() as Node3D)
|
||||
_hand.basis = parent.basis.orthonormalized().inverse() * Basis(Vector3.RIGHT, -_pitch)
|
||||
|
||||
|
||||
func _build_tree() -> AnimationTree:
|
||||
var made: AnimationTree = AnimationTree.new()
|
||||
made.name = "Animation"
|
||||
made.add_animation_library("", FigureRig.library())
|
||||
made.callback_mode_process = AnimationMixer.ANIMATION_CALLBACK_MODE_PROCESS_MANUAL
|
||||
made.deterministic = true
|
||||
var root: AnimationNodeBlendTree = AnimationNodeBlendTree.new()
|
||||
|
||||
var ground: AnimationNodeBlendSpace1D = AnimationNodeBlendSpace1D.new()
|
||||
ground.add_blend_point(_clip("idle"), 0.0, -1, &"idle")
|
||||
ground.add_blend_point(_clip("walk"), Tuning.WALK_SPEED, -1, &"walk")
|
||||
ground.add_blend_point(_clip("run"), Tuning.SPRINT_SPEED, -1, &"run")
|
||||
ground.min_space = 0.0
|
||||
ground.max_space = Tuning.SPRINT_SPEED
|
||||
ground.sync = true
|
||||
root.add_node("ground", ground)
|
||||
root.add_node("ground_pace", AnimationNodeTimeScale.new())
|
||||
root.connect_node("ground_pace", 0, "ground")
|
||||
var crouch: AnimationNodeBlendSpace1D = AnimationNodeBlendSpace1D.new()
|
||||
crouch.add_blend_point(_clip("crouch_idle"), 0.0, -1, &"crouch_idle")
|
||||
crouch.add_blend_point(_clip("crouch_walk"), Tuning.CROUCH_SPEED, -1, &"crouch_walk")
|
||||
crouch.min_space = 0.0
|
||||
crouch.max_space = Tuning.CROUCH_SPEED
|
||||
crouch.sync = true
|
||||
root.add_node("crouch", crouch)
|
||||
|
||||
var move: AnimationNodeTransition = AnimationNodeTransition.new()
|
||||
move.xfade_time = 0.18
|
||||
move.input_count = STATES.size()
|
||||
for index: int in STATES.size():
|
||||
move.set_input_name(index, STATES[index])
|
||||
root.add_node("move", move)
|
||||
root.connect_node("move", 0, "ground_pace")
|
||||
root.connect_node("move", 1, "crouch")
|
||||
for index: int in range(2, STATES.size()):
|
||||
root.add_node("clip_" + STATES[index], _clip(STATES[index]))
|
||||
root.connect_node("move", index, "clip_" + STATES[index])
|
||||
|
||||
var holds: AnimationNodeTransition = AnimationNodeTransition.new()
|
||||
holds.xfade_time = 0.15
|
||||
holds.input_count = HOLDS.size()
|
||||
for index: int in HOLDS.size():
|
||||
holds.set_input_name(index, HOLDS[index])
|
||||
root.add_node("hold_" + HOLDS[index], _clip("hold_" + HOLDS[index]))
|
||||
root.add_node("hold", holds)
|
||||
for index: int in HOLDS.size():
|
||||
root.connect_node("hold", index, "hold_" + HOLDS[index])
|
||||
var holding: AnimationNodeBlend2 = _filtered(AnimationNodeBlend2.new(), FigurePoses.ARMS) as AnimationNodeBlend2
|
||||
root.add_node("holding", holding)
|
||||
root.connect_node("holding", 0, "move")
|
||||
root.connect_node("holding", 1, "hold")
|
||||
|
||||
var last: String = "holding"
|
||||
for layer: String in ["reload", "use"]:
|
||||
root.add_node("clip_" + layer, _clip(layer))
|
||||
root.add_node(layer, _filtered(AnimationNodeBlend2.new(), FigurePoses.ARMS_AND_HEAD))
|
||||
root.connect_node(layer, 0, last)
|
||||
root.connect_node(layer, 1, "clip_" + layer)
|
||||
last = layer
|
||||
|
||||
var actions: AnimationNodeTransition = AnimationNodeTransition.new()
|
||||
actions.xfade_time = 0.0
|
||||
actions.input_count = ACTIONS.size()
|
||||
for index: int in ACTIONS.size():
|
||||
actions.set_input_name(index, ACTIONS[index])
|
||||
root.add_node("clip_" + ACTIONS[index], _clip(ACTIONS[index]))
|
||||
root.add_node("action", actions)
|
||||
for index: int in ACTIONS.size():
|
||||
root.connect_node("action", index, "clip_" + ACTIONS[index])
|
||||
var act_shot: AnimationNodeOneShot = _filtered(AnimationNodeOneShot.new(), FigurePoses.UPPER) as AnimationNodeOneShot
|
||||
act_shot.fadein_time = 0.04
|
||||
act_shot.fadeout_time = 0.12
|
||||
root.add_node("act", act_shot)
|
||||
root.connect_node("act", 0, last)
|
||||
root.connect_node("act", 1, "action")
|
||||
|
||||
root.add_node("clip_flinch", _clip("flinch"))
|
||||
var hit: AnimationNodeOneShot = _filtered(AnimationNodeOneShot.new(), FigurePoses.TORSO) as AnimationNodeOneShot
|
||||
hit.fadein_time = 0.03
|
||||
hit.fadeout_time = 0.1
|
||||
root.add_node("hit", hit)
|
||||
root.connect_node("hit", 0, "act")
|
||||
root.connect_node("hit", 1, "clip_flinch")
|
||||
root.connect_node("output", 0, "hit")
|
||||
|
||||
made.tree_root = root
|
||||
made.root_node = NodePath("..")
|
||||
made.active = true
|
||||
return made
|
||||
|
||||
|
||||
func _clip(name: String) -> AnimationNodeAnimation:
|
||||
var node: AnimationNodeAnimation = AnimationNodeAnimation.new()
|
||||
node.animation = name
|
||||
return node
|
||||
|
||||
|
||||
func _filtered(node: AnimationNode, filtered: Array[String]) -> AnimationNode:
|
||||
node.filter_enabled = true
|
||||
for joint: String in filtered:
|
||||
node.set_filter_path(NodePath(FigurePoses.path_of(joint)), true)
|
||||
return node
|
||||
|
||||
|
||||
static func _vector(values: Variant) -> Vector3:
|
||||
var list: Array = values if values is Array else [0, 0, 0]
|
||||
return Vector3(float(list[0]), float(list[1]), float(list[2]))
|
||||
@@ -0,0 +1 @@
|
||||
uid://12b1bqsxv725
|
||||
Reference in New Issue
Block a user