#ifndef OBJECTS_RIGGING_HPP_ #define OBJECTS_RIGGING_HPP_ #include "../typedefs.hpp" #include #include #include #include #include class Assets; class ModelBatch; namespace model { struct Model; } namespace rigging { struct Rig; class RigConfig; struct Pose { std::vector matrices; Pose(size_t size) { matrices.resize(size, glm::mat4(1.0f)); } }; class RigNode { size_t index; std::string name; std::string modelName; std::vector> subnodes; model::Model* model = nullptr; public: RigNode( size_t index, std::string name, std::string model, std::vector> subnodes); void setModel(const Assets* assets, const std::string& name); const std::string& getModelName() const { return modelName; } model::Model* getModel() const { return model; } size_t getIndex() const { return index; } const auto& getSubnodes() const { return subnodes; } }; struct Rig { RigConfig* config; Pose pose; Pose calculated; std::unordered_map textures; }; class RigConfig { std::unique_ptr root; std::unordered_map indices; /// Nodes and indices are ordered from root to subnodes. /// Example: /// 0 - root /// 1 --- sub1 /// 2 ----- subsub1 /// 3 --- sub2 std::vector nodes; size_t update( size_t index, Rig& rig, RigNode* node, glm::mat4 matrix) const; public: RigConfig(std::unique_ptr root, size_t nodesCount); void update(Rig& rig, glm::mat4 matrix) const; void setup(const Assets* assets, RigNode* node=nullptr) const; void render( Assets* assets, ModelBatch& batch, Rig& rig, const glm::mat4& matrix) const; Rig instance() { return Rig { this, Pose(nodes.size()), Pose(nodes.size()), {} }; } static std::unique_ptr parse( std::string_view src, std::string_view file ); const std::vector& getNodes() const { return nodes; } }; }; #endif // OBJECTS_RIGGING_HPP_