Files
Bullosseum/tests/rigid_skin_test.gd
T
richard 981ebf1910 Add blood decals, gore, mobile HUD, web start gate + touch/perf tests
Remove tools/fstest.html scratch page used to probe browser
fullscreen/orientation APIs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EznnY8rH2dXhtono1kwsXg
2026-09-04 14:07:57 +03:00

94 lines
3.1 KiB
GDScript

extends SceneTree
## Guard for the web/mobile rigid-skin conversion (rigid_skin.gd). The bug it protects against:
## the converter used to key geometry by destination bone only, so every surface funnelled to a
## bone collapsed onto one material — matadors came out bald with the wrong uniform colour on the
## web build. It now keys per (bone, surface), so all source materials survive. This asserts the
## matador keeps every distinct material after conversion, produces bone-attached pieces, and
## hides the original skinned meshes (so they never hit the invisible-on-Mali skinning path).
## Run: godot --headless --script res://tests/rigid_skin_test.gd
const RigidSkin = preload("res://rigid_skin.gd")
var _pass := 0
var _fail := 0
func _init() -> void:
_run.call_deferred()
func _ok(c: bool, m: String) -> void:
if c:
_pass += 1
print(" PASS: ", m)
else:
_fail += 1
print(" FAIL: ", m)
func _surface_mats(mi: MeshInstance3D) -> Array:
var out: Array = []
var mesh := mi.mesh
if mesh == null:
return out
for s: int in mesh.get_surface_count():
var mat: Material = mi.material_override
if mat == null:
mat = mi.get_surface_override_material(s)
if mat == null:
mat = mesh.surface_get_material(s)
if mat != null and not out.has(mat):
out.append(mat)
return out
func _run() -> void:
var inst: Node = (load("res://Assets/Matador.glb") as PackedScene).instantiate()
root.add_child(inst)
# Distinct materials on the skinned source meshes, before conversion.
var source: Array = []
var skinned: Array = []
for mi: MeshInstance3D in inst.find_children("*", "MeshInstance3D", true, false):
if mi.skin != null:
skinned.append(mi)
for mat: Material in _surface_mats(mi):
if not source.has(mat):
source.append(mat)
_ok(source.size() >= 2, "matador source has multiple distinct materials (%d)" % source.size())
var converted := RigidSkin.convert_tree(inst)
_ok(converted > 0, "convert_tree rebuilt %d skinned mesh(es)" % converted)
# Distinct materials on the generated bone-attached pieces.
var pieces := 0
var piece_mats: Array = []
for att: BoneAttachment3D in inst.find_children("*", "BoneAttachment3D", true, false):
for mi: MeshInstance3D in att.find_children("*", "MeshInstance3D", true, false):
pieces += 1
var mesh := mi.mesh
if mesh == null:
continue
# Pieces are multi-surface now (a bone's materials each stay their own surface), so
# scan every surface — not just surface 0 — to confirm none were dropped.
for s: int in mesh.get_surface_count():
var mat := mesh.surface_get_material(s)
if mat != null and not piece_mats.has(mat):
piece_mats.append(mat)
_ok(pieces > 0, "conversion produced bone-attached pieces (%d)" % pieces)
_ok(piece_mats.size() >= source.size(),
"every source material survives conversion (%d of %d kept)" % [piece_mats.size(), source.size()])
var all_hidden := true
for mi: MeshInstance3D in skinned:
if mi.visible:
all_hidden = false
_ok(all_hidden, "original skinned meshes are hidden (never drawn on the failing path)")
_finish()
func _finish() -> void:
print("Results: %d passed, %d failed" % [_pass, _fail])
quit(1 if _fail > 0 else 0)