42 lines
1.7 KiB
C++
42 lines
1.7 KiB
C++
#include <gr2/gr2.h>
|
|
#include <iostream>
|
|
|
|
int main() {
|
|
gr2::LoadError err;
|
|
auto file = gr2::File::load_path("ava2-client/ymir work/pc/warrior/warrior_novice.GR2", &err);
|
|
const auto& sk = file->file_info().skeletons[0];
|
|
auto anim = gr2::File::load_path("ava2-client/ymir work/pc/warrior/intro/wait.gr2", &err);
|
|
const auto& an = anim->file_info().animations[0];
|
|
|
|
const gr2::Mat4 I{1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
|
|
std::vector<gr2::Mat4> world_anim, skin_anim;
|
|
gr2::sample_pose(sk, an, 0.0f, world_anim, skin_anim, &I);
|
|
std::cout << "WITH IDENTITY ROOT_OFFSET: ANIM POSE BONE 0 world pos: ("
|
|
<< world_anim[0][12] << ", " << world_anim[0][13] << ", " << world_anim[0][14] << ")" << std::endl;
|
|
|
|
// Check skinned mesh vertices!
|
|
const auto& mesh = file->file_info().meshes[2]; // warrior_body02
|
|
float minZ = 1e9, maxZ = -1e9;
|
|
for (const auto& v : mesh.vertices) {
|
|
float pz = 0.0f;
|
|
float total_w = 0.0f;
|
|
if (v.bone_weight[0] > 0) {
|
|
for (int b = 0; b < 4; ++b) {
|
|
if (v.bone_weight[b] == 0) continue;
|
|
float w = v.bone_weight[b] / 255.0f;
|
|
int local_slot = v.bone_index[b];
|
|
int sk_bone = mesh.bone_bindings[local_slot];
|
|
const auto& M = skin_anim[sk_bone];
|
|
pz += (v.pos[0] * M[2] + v.pos[1] * M[6] + v.pos[2] * M[10] + M[14]) * w;
|
|
total_w += w;
|
|
}
|
|
}
|
|
if (total_w > 1e-4f) {
|
|
minZ = std::min(minZ, pz);
|
|
maxZ = std::max(maxZ, pz);
|
|
}
|
|
}
|
|
std::cout << "Skinned warrior_body02 Z range: [" << minZ << ", " << maxZ << "]" << std::endl;
|
|
return 0;
|
|
}
|