Feat/14 movement overhaul #20

Merged
Dotts merged 86 commits from feat/14-movement-overhaul into main 2026-07-17 10:44:23 -07:00
4 changed files with 33 additions and 13 deletions
Showing only changes of commit 22cb0a58b7 - Show all commits
Binary file not shown.
+15
View File
@@ -88,6 +88,8 @@ func load_model(path: String) -> void:
if not skeleton:
push_warning("SkinnedPlayerModel: no skeleton in '%s'" % path)
else:
_ensure_meshes_bound(scene)
if animation_player:
_index_animations()
else:
@@ -103,6 +105,19 @@ func load_model(path: String) -> void:
_play_clip("Idle")
## Make sure every skinned MeshInstance3D is actually driven by the skeleton.
## A correctly-exported GLB binds automatically, but if one imports with a skin
## resource whose `skeleton` NodePath doesn't resolve, the mesh renders its bind
## pose (a permanent T-pose) while the skeleton animates invisibly. This repairs
## that at load time so a bad export degrades gracefully instead of T-posing.
func _ensure_meshes_bound(scene: Node) -> void:
for mi in scene.find_children("*", "MeshInstance3D", true, false):
if mi.skin == null:
continue # not a skinned mesh
if mi.skeleton.is_empty() or mi.get_node_or_null(mi.skeleton) != skeleton:
mi.skeleton = mi.get_path_to(skeleton)
## Map canonical clip names to whatever actually shipped in the GLB and set
## loop modes (glTF has no loop flag, so we set it here).
func _index_animations() -> void:
+8
View File
@@ -79,6 +79,14 @@ func _test_spawn_with_skin(skin_id: String, expect_skinned: bool) -> void:
if _check(skinned != null, "SkinnedModel created for GLB skin"):
_check(skinned.loaded, "GLB model loaded")
_check(skinned.skeleton != null, "skeleton found in GLB")
# The mesh must be bound to the skeleton, else it renders its bind
# pose (T-pose) while the skeleton animates invisibly.
var bound := false
if skinned.skeleton:
for mi in skinned.find_children("*", "MeshInstance3D", true, false):
if mi.skin != null and mi.get_node_or_null(mi.skeleton) == skinned.skeleton:
bound = true
_check(bound, "skinned mesh is bound to the skeleton (won't T-pose)")
if skinned.animation_player:
_check(skinned.animation_player.is_playing(), "animation playing")
print(" clips resolved: ", skinned._resolved_clips)
+10 -13
View File
@@ -269,13 +269,18 @@ def rigid_nearest_bone_weights(mesh, arm):
def bind_mesh_to_armature(mesh, arm):
"""Bind mesh to armature robustly and in a form the glTF exporter skins.
"""Bind mesh to armature so the glTF exporter writes a COMPLETE skin
(skin object + node.skin reference + per-vertex JOINTS/WEIGHTS).
1. Try Blender automatic (bone-heat) weights for smooth deformation.
2. If that assigns (almost) nothing, fall back to rigid nearest-bone.
3. Present the result as a parent_type='ARMATURE' relationship with NO
Armature modifier — the Blender 5.x glTF exporter only emits a skin
for that exact configuration (a lingering modifier yields skins:0).
2. If that assigns (almost) nothing — common on layered hair/clothing
meshes where bone-heat fails — fall back to rigid nearest-bone.
Keep the standard ARMATURE_AUTO result: an Armature modifier plus vertex
groups (parent_type stays OBJECT). That is exactly what the exporter needs
to write the vertex weights. (An earlier version stripped the modifier and
used parent_type='ARMATURE'; that produced an ORPHAN skin with no weights,
so the mesh rendered its bind pose — a permanent T-pose — in game.)
"""
bpy.ops.object.select_all(action="DESELECT")
mesh.select_set(True)
@@ -291,14 +296,6 @@ def bind_mesh_to_armature(mesh, arm):
weighted = rigid_nearest_bone_weights(mesh, arm)
print(f"Bound mesh: {weighted}/{total} verts weighted")
# Normalize to the exporter-friendly form: parent_type=ARMATURE, no modifier.
for m in list(mesh.modifiers):
if m.type == "ARMATURE":
mesh.modifiers.remove(m)
if mesh.parent != arm:
mesh.parent = arm
mesh.parent_type = "ARMATURE"
def main():
clear_scene()