mirror of
https://github.com/open-goal/jak-project
synced 2026-06-08 04:17:28 -04:00
f2e7606f1b
This adds a feature to `build_actor` to support importing skeletons and animations from .glb files. Multiple animations are handled and will use the name in the GLB. The default `viewer` process will end up playing back the first animation. There are a few limitations: - You can only have around 100 bones. It is technically possibly to have slightly more, but certain animations may fail to compress when there are more than ~100 bones. - Currently, all animations have 60 keyframes per second. This is a higher quality than what is normally used. If animation size becomes problematic, we could make this customizable somehow. - There is no support for the `align` bone. --------- Co-authored-by: water111 <awaterford1111445@gmail.com>
69 lines
1.9 KiB
C++
69 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "common/common_types.h"
|
|
#include "common/math/Vector.h"
|
|
|
|
#include "third-party/tiny_gltf/tiny_gltf.h"
|
|
|
|
namespace anim {
|
|
|
|
struct UncompressedSingleJointAnim {
|
|
std::vector<math::Vector3f> trans_frames;
|
|
std::vector<math::Vector3f> scale_frames;
|
|
std::vector<math::Vector4f> quat_frames;
|
|
};
|
|
|
|
struct UncompressedJointAnim {
|
|
std::string name;
|
|
std::vector<UncompressedSingleJointAnim> joints;
|
|
float framerate = 60;
|
|
int frames = 0;
|
|
};
|
|
|
|
struct CompressedMatrixMetadata {
|
|
bool is_animated[2];
|
|
};
|
|
|
|
struct CompressedFrame {
|
|
std::vector<u16> data16;
|
|
std::vector<u32> data32;
|
|
std::vector<u64> data64;
|
|
|
|
int size_bytes() const { return data16.size() * 2 + data32.size() * 4 + data64.size() * 8; }
|
|
};
|
|
|
|
struct CompressedJointMetadata {
|
|
bool animated_trans = false;
|
|
bool animated_quat = false;
|
|
bool animated_scale = false;
|
|
bool big_trans_mode = false;
|
|
};
|
|
|
|
struct CompressedAnim {
|
|
std::string name;
|
|
CompressedFrame fixed;
|
|
std::vector<CompressedFrame> frames;
|
|
bool matrix_animated[2] = {false, false};
|
|
std::vector<CompressedJointMetadata> joint_metadata;
|
|
float framerate = 60;
|
|
};
|
|
|
|
/*!
|
|
* Load animation data from GLTF file.
|
|
* @param model The GLTF model containing the animation
|
|
* @param anim The animation to convert
|
|
* @param node_to_joint Mapping from GLTF node index to the joint index
|
|
* @param framerate Number of key-frames per second. (this doesn't have to match frame rate, the
|
|
* game will interpolate between keyframes as needed.)
|
|
*/
|
|
UncompressedJointAnim extract_anim_from_gltf(const tinygltf::Model& model,
|
|
const tinygltf::Animation& anim,
|
|
const std::map<int, int>& node_to_joint,
|
|
float framerate);
|
|
|
|
CompressedAnim compress_animation(const UncompressedJointAnim& in);
|
|
|
|
} // namespace anim
|