The weapon lab could tune how a character HOLDS a gun. It could not tune where
the gun sits in the hand, and that is a different question with a different
scope: a hold is per character and weapon, an anchor is a fact about the hand.
RigAnchors adds it. A hand bone's origin is the WRIST, not the palm, and how far
down the palm a grip should sit — and how the gun rolls in the fingers — depends
on how big that character's hand is and how the artist posed the thumb. It
cannot be derived, it differs per character, and it is small. So it is an offset
that defaults to identity, and identity means exactly what the code derived
before anchors existed: an untuned character is bit-for-bit unchanged.
Deliberately NOT a fixed rotation on the mount. There used to be one, and a bone
attachment is expressed in the BONE's axes, which no two rigs agree on — that
constant is why the hand mount points were wrong on every character. The derived
mount stays derived; the anchor is a nudge on top of it, and nothing here spells
a bone name.
The layering, the JSON round trip and the res://-then-user:// write are now
TuningStore, because none of that was ever specific to weapons and two copies of
it would mean two places for "an exported build's tuning pass is silently
discarded" to come back. WeaponHoldTuning is built on it with its file format
unchanged.
The lab is a rig lab now, and it grew three things:
ANCHORS a second knob group. It cost a spec table — everything in the lab is
written against "which specs, which file, keyed on what" rather than
twice against the two groups, so anchors got sliders, live preview,
reset, save and clipboard for free. A third group is a third row in
GROUPS.
CLIP audition one animation on its own. The four pose buttons are the
states the game drives; watching a whole clip end to end is how you
see where a retarget went wrong, and there was no way to do it.
SURFACES what the importer decided each surface IS, and a click to isolate a
class. Isolating is how the decision gets CHECKED: click `hair` and
anything else still standing was misclassified. Hidden by swapping
in a transparent material rather than hiding the node, because a
mesh is not one class — Miku's body, face and hair are three
surfaces of one mesh.
And it takes the game's theme, applied to its own panel rather than only to the
Window, for the same reason the pause menu needed it: a CanvasLayer is not a
Control, so theme inheritance stops at one.
debug/rig_anchor_check.gd asserts the physical consequence rather than the
plumbing — an anchor system is easy to build so that the sliders move, the file
saves, the JSON round-trips and the gun does not budge. All six characters move
their weapon by exactly the offset asked for, measured in the attachment's frame
because a world-space delta on an animating skeleton is mostly the idle
animation, and all six return exactly to the derived mount when it is cleared.
Also fixes BoltRule, whose zigzag was self-intersecting: draw_colored_polygon
triangulates, and a crossing outline fails triangulation and draws nothing at
all except a console full of "Invalid polygon data". Same silhouette, walked as
a closed loop, with the ink edge as a polyline rather than a grown polygon —
growing a concave shape from its centroid reintroduces the crossing.
Co-Authored-By: Claude Opus 5 <[email protected]>
116 lines
4.0 KiB
GDScript
116 lines
4.0 KiB
GDScript
extends SceneTree
|
|
|
|
## Does a rig anchor actually move anything?
|
|
##
|
|
## The anchor system is easy to build so that it looks right and does nothing:
|
|
## the lab shows sliders, the file saves, the JSON round-trips, and the gun does
|
|
## not move a millimetre — because the value was read into a variable nobody
|
|
## consumed, or because the weapon was measured before the offset was applied
|
|
## and the hands are still being solved onto the old grip.
|
|
##
|
|
## So this asserts the physical consequence. Set an anchor, and the weapon must
|
|
## move by that much, in the hand bone's own axes, on every character.
|
|
##
|
|
## godot --headless --path . -s res://debug/rig_anchor_check.gd
|
|
|
|
const OFFSET := Vector3(0.03, -0.02, 0.05)
|
|
## Millimetres of slack. The weapon is parented to a BoneAttachment3D that
|
|
## follows an animating skeleton, so the two samples are a frame apart on a
|
|
## moving arm; this has to be loose enough to survive that and tight enough that
|
|
## "did not move at all" fails.
|
|
const TOLERANCE := 0.004
|
|
|
|
var _fails := 0
|
|
|
|
|
|
func _init() -> void:
|
|
# Autoloads are not in the tree yet when a `-s` script's _init runs.
|
|
await process_frame
|
|
await process_frame
|
|
var data = JSON.parse_string(FileAccess.get_file_as_string(
|
|
"res://assets/characters/skins/skins.json"))
|
|
var weapon := _first_weapon()
|
|
if weapon == "":
|
|
print("no weapon script in the loadout database")
|
|
quit(1)
|
|
return
|
|
for entry in data["skins"]:
|
|
await _check_skin(entry["id"], entry.get("model", ""), weapon)
|
|
print("\n=== RIG ANCHORS ===\nFailures: %d" % _fails)
|
|
quit(1 if _fails > 0 else 0)
|
|
|
|
|
|
func _first_weapon() -> String:
|
|
var db = root.get_node("LoadoutManager").weapon_db
|
|
var ids: Array = db.keys()
|
|
ids.sort()
|
|
for id in ids:
|
|
var script: String = db[id].get("script", "")
|
|
if script != "" and ResourceLoader.exists(script):
|
|
return script
|
|
return ""
|
|
|
|
|
|
func _check_skin(id: String, path: String, weapon: String) -> void:
|
|
if path == "" or not ResourceLoader.exists(path):
|
|
return
|
|
var model := SkinnedPlayerModel.new()
|
|
model.model_path = path
|
|
model.skin_id = id
|
|
root.add_child(model)
|
|
for _i in 4:
|
|
await process_frame
|
|
model.set_weapon(weapon)
|
|
for _i in 4:
|
|
await process_frame
|
|
|
|
var w := _weapon_node(model)
|
|
if w == null:
|
|
print(" FAIL: '%s' did not mount a weapon at all" % id)
|
|
_fails += 1
|
|
model.queue_free()
|
|
return
|
|
|
|
# Measured in the ATTACHMENT's frame, not the world's. The attachment tracks
|
|
# a bone on an animating skeleton, so a world-space delta would be the sum of
|
|
# the anchor and a frame of the idle animation — and the idle is bigger.
|
|
var before: Vector3 = w.position
|
|
model.set_anchors({"grip_offset": OFFSET})
|
|
await process_frame
|
|
w = _weapon_node(model)
|
|
var moved: Vector3 = w.position - before
|
|
|
|
var err := (moved - OFFSET).length()
|
|
if err <= TOLERANCE:
|
|
print(" OK: '%s' grip anchor moved the weapon by %.1f, %.1f, %.1f mm"
|
|
% [id, moved.x * 1000.0, moved.y * 1000.0, moved.z * 1000.0])
|
|
else:
|
|
print(" FAIL: '%s' asked for (%.3f, %.3f, %.3f), got (%.3f, %.3f, %.3f)"
|
|
% [id, OFFSET.x, OFFSET.y, OFFSET.z, moved.x, moved.y, moved.z])
|
|
_fails += 1
|
|
|
|
# ...and back to nothing tuned, which must restore the untouched mount
|
|
# exactly. An anchor that cannot be cleared is a one-way door in a tool whose
|
|
# whole purpose is trying things out.
|
|
model.set_anchors({})
|
|
await process_frame
|
|
w = _weapon_node(model)
|
|
if w.position.distance_to(before) <= TOLERANCE:
|
|
print(" OK: '%s' clearing the anchor restores the derived mount" % id)
|
|
else:
|
|
print(" FAIL: '%s' did not return to the derived mount" % id)
|
|
_fails += 1
|
|
model.queue_free()
|
|
|
|
|
|
## The attachment is a child of the SKELETON, which is nested somewhere inside
|
|
## the loaded glTF scene rather than being a direct child of the model — so it
|
|
## is reached from the skeleton, not by a path from the model.
|
|
func _weapon_node(model) -> Node3D:
|
|
if model.skeleton == null:
|
|
return null
|
|
var attach: Node = model.skeleton.get_node_or_null("WeaponAttachment")
|
|
if attach == null or attach.get_child_count() == 0:
|
|
return null
|
|
return attach.get_child(0) as Node3D
|