format: reformat project

Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
Vyacheslav Ivanov
2024-08-03 19:53:48 +03:00
committed by Pugemon
parent 736cd175d5
commit bbf33e8e4d
202 changed files with 7389 additions and 5609 deletions
+43 -32
View File
@@ -1,14 +1,14 @@
#include "rigging.hpp"
#include "../assets/Assets.hpp"
#include "../graphics/render/ModelBatch.hpp"
#include "../graphics/core/Model.hpp"
#include "../coders/json.hpp"
#include "../data/dynamic_util.hpp"
#include "../graphics/core/Model.hpp"
#include "../graphics/render/ModelBatch.hpp"
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/norm.hpp>
#include <glm/ext/matrix_transform.hpp>
#include <glm/gtx/norm.hpp>
using namespace rigging;
@@ -20,17 +20,18 @@ void ModelReference::refresh(const Assets* assets) {
}
Bone::Bone(
size_t index,
std::string name,
size_t index,
std::string name,
std::string model,
std::vector<std::unique_ptr<Bone>> bones,
glm::vec3 offset)
: index(index),
name(std::move(name)),
bones(std::move(bones)),
offset(offset),
model({model, nullptr, true})
{}
glm::vec3 offset
)
: index(index),
name(std::move(name)),
bones(std::move(bones)),
offset(offset),
model({model, nullptr, true}) {
}
void Bone::setModel(const std::string& name) {
if (model.name == name) {
@@ -39,7 +40,7 @@ void Bone::setModel(const std::string& name) {
model = {name, nullptr, true};
}
Skeleton::Skeleton(const SkeletonConfig* config)
Skeleton::Skeleton(const SkeletonConfig* config)
: config(config),
pose(config->getBones().size()),
calculated(config->getBones().size()),
@@ -60,27 +61,31 @@ static void get_all_nodes(std::vector<Bone*>& nodes, Bone* node) {
}
}
SkeletonConfig::SkeletonConfig(const std::string& name, std::unique_ptr<Bone> root, size_t nodesCount)
: name(name), root(std::move(root)), nodes(nodesCount) {
SkeletonConfig::SkeletonConfig(
const std::string& name, std::unique_ptr<Bone> root, size_t nodesCount
)
: name(name), root(std::move(root)), nodes(nodesCount) {
get_all_nodes(nodes, this->root.get());
}
size_t SkeletonConfig::update(
size_t index,
Skeleton& skeleton,
Bone* node,
glm::mat4 matrix) const
{
size_t index, Skeleton& skeleton, Bone* node, glm::mat4 matrix
) const {
auto boneMatrix = skeleton.pose.matrices[index];
auto boneOffset = node->getOffset();
glm::mat4 baseMatrix(1.0f);
if (glm::length2(boneOffset) > 0.0f) {
baseMatrix = glm::translate(glm::mat4(1.0f), boneOffset);
}
skeleton.calculated.matrices[index] = matrix * baseMatrix * boneMatrix;
skeleton.calculated.matrices[index] = matrix * baseMatrix * boneMatrix;
size_t count = 1;
for (auto& subnode : node->getSubnodes()) {
count += update(index+count, skeleton, subnode.get(), skeleton.calculated.matrices[index]);
count += update(
index + count,
skeleton,
subnode.get(),
skeleton.calculated.matrices[index]
);
}
return count;
}
@@ -93,8 +98,8 @@ void SkeletonConfig::render(
Assets* assets,
ModelBatch& batch,
Skeleton& skeleton,
const glm::mat4& matrix) const
{
const glm::mat4& matrix
) const {
update(skeleton, matrix);
if (!skeleton.visible) {
@@ -113,8 +118,12 @@ void SkeletonConfig::render(
}
model = modelOverride.model ? modelOverride.model : model;
if (model) {
batch.draw(skeleton.calculated.matrices[i], skeleton.tint, model,
&skeleton.textures);
batch.draw(
skeleton.calculated.matrices[i],
skeleton.tint,
model,
&skeleton.textures
);
}
}
}
@@ -145,19 +154,19 @@ static std::tuple<size_t, std::unique_ptr<Bone>> read_node(
if (auto nodesList = root->list("nodes")) {
for (size_t i = 0; i < nodesList->size(); i++) {
if (const auto& map = nodesList->map(i)) {
auto [subcount, subNode] = read_node(map, index+count);
auto [subcount, subNode] = read_node(map, index + count);
count += subcount;
bones.push_back(std::move(subNode));
}
}
}
return {count, std::make_unique<Bone>(index, name, model, std::move(bones), offset)};
return {
count,
std::make_unique<Bone>(index, name, model, std::move(bones), offset)};
}
std::unique_ptr<SkeletonConfig> SkeletonConfig::parse(
std::string_view src,
std::string_view file,
std::string_view name
std::string_view src, std::string_view file, std::string_view name
) {
auto root = json::parse(file, src);
auto rootNodeMap = root->map("root");
@@ -165,5 +174,7 @@ std::unique_ptr<SkeletonConfig> SkeletonConfig::parse(
throw std::runtime_error("missing 'root' element");
}
auto [count, rootNode] = read_node(rootNodeMap, 0);
return std::make_unique<SkeletonConfig>(std::string(name), std::move(rootNode), count);
return std::make_unique<SkeletonConfig>(
std::string(name), std::move(rootNode), count
);
}