|
| 1 | +// L3 regression guard — split/threedim finding #9 (AnimationPlayer never |
| 2 | +// deforms skinned meshes: it wrote an ignored buffer and left joint TRS at |
| 3 | +// bind pose). |
| 4 | +// |
| 5 | +// The skinning block recomputed joint_matrix = world x inverse_bind into |
| 6 | +// skeleton_component::joint_matrices_buffer, but the sole skinning consumer |
| 7 | +// (SceneGPUState) ALWAYS derives its joint matrices from joints[].{translation, |
| 8 | +// rotation,scale} via its own forward kinematics and never reads |
| 9 | +// joint_matrices_buffer. AnimationPlayer meanwhile animated only the rigid |
| 10 | +// scene_transform payloads and never touched joints[] — so the animated pose |
| 11 | +// never reached the skinning path and skinned meshes stayed frozen in bind |
| 12 | +// pose. |
| 13 | +// |
| 14 | +// The fix writes each sampled TRS override (keyed by scene_node id) into the |
| 15 | +// cloned skeleton's joints[] local TRS, mapped joint -> node via |
| 16 | +// joint_node_ids, and bumps the skeleton dirty_index. |
| 17 | +// |
| 18 | +// This is a pure state test (no GPU): we build a scene with one animated |
| 19 | +// rotation channel targeting the node that backs joint 0, tick once, and read |
| 20 | +// the OUTPUT scene's skeleton. Post-fix, joints[0].rotation has moved off the |
| 21 | +// bind-pose identity quaternion to the sampled value; pre-fix it stays at the |
| 22 | +// bind pose (0,0,0,1) (RED). We observe the published skeleton_component state, |
| 23 | +// not a rendered image. |
| 24 | + |
| 25 | +#include <Threedim/AnimationPlayer.hpp> |
| 26 | + |
| 27 | +#include <ossia/dataflow/geometry_port.hpp> |
| 28 | + |
| 29 | +#include <catch2/catch_test_macros.hpp> |
| 30 | + |
| 31 | +#include <cmath> |
| 32 | +#include <memory> |
| 33 | +#include <vector> |
| 34 | + |
| 35 | +namespace |
| 36 | +{ |
| 37 | +// scene_node id that backs the animated joint. |
| 38 | +constexpr uint64_t kJointNodeId = 77; |
| 39 | + |
| 40 | +// A 90 degrees rotation about +Z as a glTF (x,y,z,w) quaternion. |
| 41 | +constexpr float kQz = 0.70710678f; // sin(45deg) == cos(45deg) |
| 42 | + |
| 43 | +std::shared_ptr<ossia::scene_state> makeSkinnedScene() |
| 44 | +{ |
| 45 | + // Minimal non-empty root (scene_state::empty() gates AnimationPlayer). The |
| 46 | + // root does not need to be the joint node — the skinning path resolves joints |
| 47 | + // via joint_node_ids against the sampled overrides, independent of the tree. |
| 48 | + auto root = std::make_shared<ossia::scene_node>(); |
| 49 | + root->id.value = 1; |
| 50 | + auto roots = std::make_shared<std::vector<ossia::scene_node_ptr>>(); |
| 51 | + roots->push_back(root); |
| 52 | + |
| 53 | + // One rotation channel on node 77, constant 90deg-about-Z at both keyframes, |
| 54 | + // so any sampled t yields the same non-identity quaternion. |
| 55 | + auto anim = std::make_shared<ossia::animation_component>(); |
| 56 | + anim->duration = 1.f; |
| 57 | + ossia::animation_channel ch; |
| 58 | + ch.target_node_id = kJointNodeId; |
| 59 | + ch.target_path = ossia::animation_target::rotation; |
| 60 | + ch.interpolation = ossia::animation_interpolation::linear; |
| 61 | + ch.times = std::make_shared<std::vector<float>>(std::vector<float>{0.f, 1.f}); |
| 62 | + ch.values = std::make_shared<std::vector<float>>( |
| 63 | + std::vector<float>{0.f, 0.f, kQz, kQz, 0.f, 0.f, kQz, kQz}); |
| 64 | + anim->channels.push_back(ch); |
| 65 | + auto anims |
| 66 | + = std::make_shared<std::vector<ossia::animation_component_ptr>>(); |
| 67 | + anims->push_back(anim); |
| 68 | + |
| 69 | + // One skeleton, one joint at bind pose (identity rotation), mapped to node 77. |
| 70 | + auto skel = std::make_shared<ossia::skeleton_component>(); |
| 71 | + ossia::skeleton_joint joint; // defaults: rotation {0,0,0,1}, scale {1,1,1} |
| 72 | + joint.name = "j0"; |
| 73 | + skel->joints.push_back(joint); |
| 74 | + skel->joint_node_ids.push_back(ossia::scene_node_id{kJointNodeId}); |
| 75 | + skel->dirty_index = 0; |
| 76 | + auto skels |
| 77 | + = std::make_shared<std::vector<ossia::skeleton_component_ptr>>(); |
| 78 | + skels->push_back(skel); |
| 79 | + |
| 80 | + auto st = std::make_shared<ossia::scene_state>(); |
| 81 | + st->roots = roots; |
| 82 | + st->animations = anims; |
| 83 | + st->skeletons = skels; |
| 84 | + return st; |
| 85 | +} |
| 86 | + |
| 87 | +const ossia::skeleton_component* |
| 88 | +outputSkeleton(Threedim::AnimationPlayer& node) |
| 89 | +{ |
| 90 | + const auto& out = node.outputs.scene_out.scene.state; |
| 91 | + if(!out || !out->skeletons || out->skeletons->empty()) |
| 92 | + return nullptr; |
| 93 | + return (*out->skeletons)[0].get(); |
| 94 | +} |
| 95 | +} // namespace |
| 96 | + |
| 97 | +TEST_CASE( |
| 98 | + "AnimationPlayer writes sampled TRS into skeleton joints", |
| 99 | + "[threedim][animation][f9]") |
| 100 | +{ |
| 101 | + Threedim::AnimationPlayer node; |
| 102 | + node.inputs.scene_in.scene.state = makeSkinnedScene(); |
| 103 | + node.inputs.time.value = 0.f; |
| 104 | + node.inputs.speed.value = 1.f; |
| 105 | + node.inputs.loop.value = false; |
| 106 | + node.inputs.clip_index.value = -1; |
| 107 | + |
| 108 | + node(); |
| 109 | + |
| 110 | + const ossia::skeleton_component* skel = outputSkeleton(node); |
| 111 | + REQUIRE(skel != nullptr); |
| 112 | + REQUIRE(skel->joints.size() == 1u); |
| 113 | + |
| 114 | + // The fix: the joint's LOCAL rotation TRS (the data SceneGPUState's forward |
| 115 | + // kinematics actually consumes) is now the sampled 90deg-about-Z quaternion, |
| 116 | + // no longer the bind-pose identity. Pre-fix the joint stays at bind pose and |
| 117 | + // both component checks fail (RED). |
| 118 | + const auto& r = skel->joints[0].rotation; // (x,y,z,w) |
| 119 | + CHECK(std::abs(r[2] - kQz) < 1e-4f); |
| 120 | + CHECK(std::abs(r[3] - kQz) < 1e-4f); |
| 121 | + |
| 122 | + // It has genuinely moved off the bind-pose identity (0,0,0,1). |
| 123 | + const bool movedFromBind |
| 124 | + = std::abs(r[0]) > 1e-4f || std::abs(r[1]) > 1e-4f |
| 125 | + || std::abs(r[2]) > 1e-4f || std::abs(r[3] - 1.f) > 1e-4f; |
| 126 | + CHECK(movedFromBind); |
| 127 | + |
| 128 | + // And the skeleton is flagged dirty so the renderer re-runs FK. |
| 129 | + CHECK(skel->dirty_index > 0); |
| 130 | +} |
0 commit comments