Fix model track-group movement and RGB destination-alpha blending
This commit is contained in:
@@ -125,6 +125,17 @@ struct BoneTrack {
|
||||
void sample(float t, Transform& out) const;
|
||||
};
|
||||
|
||||
// Preserve group boundaries: an animation can contain an auxiliary object group before its model.
|
||||
struct AnimationTrackGroup {
|
||||
std::string name;
|
||||
Transform initial_placement;
|
||||
int32_t accumulation_flags = 0;
|
||||
float loop_translation[3] = {0.0f, 0.0f, 0.0f};
|
||||
std::vector<TextTrack> text_tracks;
|
||||
size_t first_track = 0;
|
||||
size_t track_count = 0;
|
||||
};
|
||||
|
||||
struct Animation {
|
||||
std::string name;
|
||||
float duration = 0.0f;
|
||||
@@ -137,6 +148,7 @@ struct Animation {
|
||||
int32_t accumulation_flags = 0;
|
||||
float loop_translation[3] = {0.0f, 0.0f, 0.0f};
|
||||
std::vector<BoneTrack> tracks;
|
||||
std::vector<AnimationTrackGroup> track_groups;
|
||||
// t 处每个 track 的局部 4x4(granny_transform 组合语义,行主序)。
|
||||
// out 按 tracks 顺序;bone_index 见各 track。
|
||||
void sample_local(float t, std::vector<Mat4>& out) const;
|
||||
|
||||
+47
-37
@@ -110,47 +110,53 @@ bool File::Impl::extract_animation(Ref anim_obj, Ref anim_type, const Skeleton*
|
||||
out.track_group_count = int32_t(groups.size());
|
||||
const auto& tgms = parse_type(mTG->ref_type);
|
||||
|
||||
// TrackGroups[0].AccumulationFlags (Int32) + LoopTranslation (Real32[3])
|
||||
if (!groups.empty() && groups[0].valid()) {
|
||||
if (const TypeMember* m = find_member(tgms, "AccumulationFlags"))
|
||||
out.accumulation_flags = rd_i32(member_slot(groups[0], *m));
|
||||
if (const TypeMember* m = find_member(tgms, "LoopTranslation")) {
|
||||
Ref r = member_slot(groups[0], *m);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
out.loop_translation[i] = rd_f32(Ref{r.section, r.offset + uint32_t(i) * 4u});
|
||||
}
|
||||
}
|
||||
|
||||
// TrackGroups[0].TextTracks: RefToArray text_track{String Name; RefToArray Entries(
|
||||
// text_track_entry{Real32 TimeStamp; String Text})}(motion event 用)
|
||||
if (!groups.empty() && groups[0].valid())
|
||||
if (const TypeMember* mTx = find_member(tgms, "TextTracks")) {
|
||||
Ref xb; uint32_t xc = 0, xs = 0;
|
||||
if (read_ref_to_array(groups[0], *mTx, xb, xc, xs) && xc && xs) {
|
||||
const auto& xms = parse_type(mTx->ref_type);
|
||||
const TypeMember* mXN = find_member(xms, "Name");
|
||||
const TypeMember* mXE = find_member(xms, "Entries");
|
||||
for (uint32_t i = 0; i < xc && i < 4096; ++i) {
|
||||
Ref x = {xb.section, xb.offset + i * xs};
|
||||
TextTrack tt;
|
||||
if (mXN) tt.name = rd_str(member_slot(x, *mXN));
|
||||
Ref eb; uint32_t ec = 0, es = 0;
|
||||
if (mXE && read_ref_to_array(x, *mXE, eb, ec, es) && ec && es) {
|
||||
const auto& ems = parse_type(mXE->ref_type);
|
||||
const TypeMember* mTS = find_member(ems, "TimeStamp");
|
||||
const TypeMember* mTT = find_member(ems, "Text");
|
||||
for (uint32_t k = 0; k < ec && k < 65536; ++k) {
|
||||
Ref e = {eb.section, eb.offset + k * es};
|
||||
TextTrackEntry te;
|
||||
if (mTS) te.time_stamp = rd_f32(member_slot(e, *mTS));
|
||||
if (mTT) te.text = rd_str(member_slot(e, *mTT));
|
||||
tt.entries.push_back(std::move(te));
|
||||
for (Ref group : groups) {
|
||||
AnimationTrackGroup data;
|
||||
if (group.valid()) {
|
||||
if (const auto* m = find_member(tgms, "Name")) data.name = rd_str(member_slot(group, *m));
|
||||
if (const auto* m = find_member(tgms, "InitialPlacement")) read_transform(member_slot(group, *m), data.initial_placement);
|
||||
if (const auto* m = find_member(tgms, "AccumulationFlags")) data.accumulation_flags = rd_i32(member_slot(group, *m));
|
||||
if (const auto* m = find_member(tgms, "LoopTranslation")) {
|
||||
Ref r = member_slot(group, *m);
|
||||
for (int i = 0; i < 3; ++i) data.loop_translation[i] = rd_f32({r.section, r.offset + uint32_t(i) * 4u});
|
||||
}
|
||||
if (const auto* mTx = find_member(tgms, "TextTracks")) {
|
||||
Ref xb; uint32_t xc = 0, xs = 0;
|
||||
if (read_ref_to_array(group, *mTx, xb, xc, xs) && xc && xs) {
|
||||
const auto& xms = parse_type(mTx->ref_type);
|
||||
const auto* mXN = find_member(xms, "Name");
|
||||
const auto* mXE = find_member(xms, "Entries");
|
||||
for (uint32_t i = 0; i < xc && i < 4096; ++i) {
|
||||
Ref x = {xb.section, xb.offset + i * xs};
|
||||
TextTrack tt;
|
||||
if (mXN) tt.name = rd_str(member_slot(x, *mXN));
|
||||
Ref eb; uint32_t ec = 0, es = 0;
|
||||
if (mXE && read_ref_to_array(x, *mXE, eb, ec, es) && ec && es) {
|
||||
const auto& ems = parse_type(mXE->ref_type);
|
||||
const auto* mTS = find_member(ems, "TimeStamp");
|
||||
const auto* mTT = find_member(ems, "Text");
|
||||
for (uint32_t k = 0; k < ec && k < 65536; ++k) {
|
||||
Ref e = {eb.section, eb.offset + k * es};
|
||||
TextTrackEntry te;
|
||||
if (mTS) te.time_stamp = rd_f32(member_slot(e, *mTS));
|
||||
if (mTT) te.text = rd_str(member_slot(e, *mTT));
|
||||
tt.entries.push_back(std::move(te));
|
||||
}
|
||||
}
|
||||
data.text_tracks.push_back(std::move(tt));
|
||||
}
|
||||
out.text_tracks.push_back(std::move(tt));
|
||||
}
|
||||
}
|
||||
}
|
||||
out.track_groups.push_back(std::move(data));
|
||||
}
|
||||
// Existing inspection API exposes the first group; runtime binding uses track_groups by name.
|
||||
if (!out.track_groups.empty()) {
|
||||
const auto& first = out.track_groups.front();
|
||||
out.accumulation_flags = first.accumulation_flags;
|
||||
std::copy_n(first.loop_translation, 3, out.loop_translation);
|
||||
out.text_tracks = first.text_tracks;
|
||||
}
|
||||
const TypeMember* mTT = find_member(tgms, "TransformTracks");
|
||||
if (!mTT) return true;
|
||||
|
||||
@@ -167,7 +173,10 @@ bool File::Impl::extract_animation(Ref anim_obj, Ref anim_type, const Skeleton*
|
||||
const TypeMember* mPos = find_member(ttms, "PositionCurve");
|
||||
const TypeMember* mScl = find_member(ttms, "ScaleShearCurve");
|
||||
|
||||
for (Ref g : groups) {
|
||||
for (size_t group_index = 0; group_index < groups.size(); ++group_index) {
|
||||
Ref g = groups[group_index];
|
||||
auto& group_data = out.track_groups[group_index];
|
||||
group_data.first_track = out.tracks.size();
|
||||
if (!g.valid()) continue;
|
||||
Ref base; uint32_t count = 0, stride = 0;
|
||||
if (!read_ref_to_array(g, *mTT, base, count, stride) || count == 0) continue;
|
||||
@@ -191,6 +200,7 @@ bool File::Impl::extract_animation(Ref anim_obj, Ref anim_type, const Skeleton*
|
||||
if (skel->bones[k].name == bt.bone_name) { bt.bone_index = int32_t(k); break; }
|
||||
out.tracks.push_back(std::move(bt));
|
||||
}
|
||||
group_data.track_count = out.tracks.size() - group_data.first_track;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user