update RigConfig
This commit is contained in:
parent
1b41a75cf4
commit
beac332c96
@ -6,5 +6,8 @@
|
|||||||
"models": [
|
"models": [
|
||||||
"cube",
|
"cube",
|
||||||
"item"
|
"item"
|
||||||
|
],
|
||||||
|
"rigs": [
|
||||||
|
"drop"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
5
res/content/base/rigs/drop.json
Normal file
5
res/content/base/rigs/drop.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"root": {
|
||||||
|
"model": "cube"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
local tsf = entity.transform
|
local tsf = entity.transform
|
||||||
local body = entity.rigidbody
|
local body = entity.rigidbody
|
||||||
|
local rig = entity.modeltree
|
||||||
|
|
||||||
inair = true
|
inair = true
|
||||||
ready = false
|
ready = false
|
||||||
|
|||||||
@ -24,13 +24,14 @@ static debug::Logger logger("assets-loader");
|
|||||||
AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
|
AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
|
||||||
: assets(assets), paths(paths)
|
: assets(assets), paths(paths)
|
||||||
{
|
{
|
||||||
addLoader(AssetType::shader, assetload::shader);
|
addLoader(AssetType::SHADER, assetload::shader);
|
||||||
addLoader(AssetType::texture, assetload::texture);
|
addLoader(AssetType::TEXTURE, assetload::texture);
|
||||||
addLoader(AssetType::font, assetload::font);
|
addLoader(AssetType::FONT, assetload::font);
|
||||||
addLoader(AssetType::atlas, assetload::atlas);
|
addLoader(AssetType::ATLAS, assetload::atlas);
|
||||||
addLoader(AssetType::layout, assetload::layout);
|
addLoader(AssetType::LAYOUT, assetload::layout);
|
||||||
addLoader(AssetType::sound, assetload::sound);
|
addLoader(AssetType::SOUND, assetload::sound);
|
||||||
addLoader(AssetType::model, assetload::model);
|
addLoader(AssetType::MODEL, assetload::model);
|
||||||
|
addLoader(AssetType::RIG, assetload::rig);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetsLoader::addLoader(AssetType tag, aloader_func func) {
|
void AssetsLoader::addLoader(AssetType tag, aloader_func func) {
|
||||||
@ -80,7 +81,7 @@ void addLayouts(const scriptenv& env, const std::string& prefix, const fs::path&
|
|||||||
if (file.extension().u8string() != ".xml")
|
if (file.extension().u8string() != ".xml")
|
||||||
continue;
|
continue;
|
||||||
std::string name = prefix+":"+file.stem().u8string();
|
std::string name = prefix+":"+file.stem().u8string();
|
||||||
loader.add(AssetType::layout, file.u8string(), name, std::make_shared<LayoutCfg>(env));
|
loader.add(AssetType::LAYOUT, file.u8string(), name, std::make_shared<LayoutCfg>(env));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,18 +90,19 @@ void AssetsLoader::tryAddSound(const std::string& name) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string file = SOUNDS_FOLDER+"/"+name;
|
std::string file = SOUNDS_FOLDER+"/"+name;
|
||||||
add(AssetType::sound, file, name);
|
add(AssetType::SOUND, file, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string assets_def_folder(AssetType tag) {
|
static std::string assets_def_folder(AssetType tag) {
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case AssetType::font: return FONTS_FOLDER;
|
case AssetType::FONT: return FONTS_FOLDER;
|
||||||
case AssetType::shader: return SHADERS_FOLDER;
|
case AssetType::SHADER: return SHADERS_FOLDER;
|
||||||
case AssetType::texture: return TEXTURES_FOLDER;
|
case AssetType::TEXTURE: return TEXTURES_FOLDER;
|
||||||
case AssetType::atlas: return TEXTURES_FOLDER;
|
case AssetType::ATLAS: return TEXTURES_FOLDER;
|
||||||
case AssetType::layout: return LAYOUTS_FOLDER;
|
case AssetType::LAYOUT: return LAYOUTS_FOLDER;
|
||||||
case AssetType::sound: return SOUNDS_FOLDER;
|
case AssetType::SOUND: return SOUNDS_FOLDER;
|
||||||
case AssetType::model: return MODELS_FOLDER;
|
case AssetType::MODEL: return MODELS_FOLDER;
|
||||||
|
case AssetType::RIG: return RIGS_FOLDER;
|
||||||
}
|
}
|
||||||
return "<error>";
|
return "<error>";
|
||||||
}
|
}
|
||||||
@ -118,7 +120,7 @@ void AssetsLoader::processPreload(
|
|||||||
}
|
}
|
||||||
map->str("path", path);
|
map->str("path", path);
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case AssetType::sound:
|
case AssetType::SOUND:
|
||||||
add(tag, path, name, std::make_shared<SoundCfg>(
|
add(tag, path, name, std::make_shared<SoundCfg>(
|
||||||
map->get("keep-pcm", false)
|
map->get("keep-pcm", false)
|
||||||
));
|
));
|
||||||
@ -153,11 +155,12 @@ void AssetsLoader::processPreloadList(AssetType tag, dynamic::List* list) {
|
|||||||
|
|
||||||
void AssetsLoader::processPreloadConfig(const fs::path& file) {
|
void AssetsLoader::processPreloadConfig(const fs::path& file) {
|
||||||
auto root = files::read_json(file);
|
auto root = files::read_json(file);
|
||||||
processPreloadList(AssetType::font, root->list("fonts"));
|
processPreloadList(AssetType::FONT, root->list("fonts"));
|
||||||
processPreloadList(AssetType::shader, root->list("shaders"));
|
processPreloadList(AssetType::SHADER, root->list("shaders"));
|
||||||
processPreloadList(AssetType::texture, root->list("textures"));
|
processPreloadList(AssetType::TEXTURE, root->list("textures"));
|
||||||
processPreloadList(AssetType::sound, root->list("sounds"));
|
processPreloadList(AssetType::SOUND, root->list("sounds"));
|
||||||
processPreloadList(AssetType::model, root->list("models"));
|
processPreloadList(AssetType::MODEL, root->list("models"));
|
||||||
|
processPreloadList(AssetType::RIG, root->list("rigs"));
|
||||||
// layouts are loaded automatically
|
// layouts are loaded automatically
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,18 +179,18 @@ void AssetsLoader::processPreloadConfigs(const Content* content) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
|
void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
|
||||||
loader.add(AssetType::font, FONTS_FOLDER+"/font", "normal");
|
loader.add(AssetType::FONT, FONTS_FOLDER+"/font", "normal");
|
||||||
loader.add(AssetType::shader, SHADERS_FOLDER+"/ui", "ui");
|
loader.add(AssetType::SHADER, SHADERS_FOLDER+"/ui", "ui");
|
||||||
loader.add(AssetType::shader, SHADERS_FOLDER+"/main", "main");
|
loader.add(AssetType::SHADER, SHADERS_FOLDER+"/main", "main");
|
||||||
loader.add(AssetType::shader, SHADERS_FOLDER+"/lines", "lines");
|
loader.add(AssetType::SHADER, SHADERS_FOLDER+"/lines", "lines");
|
||||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/menubg", "gui/menubg");
|
loader.add(AssetType::TEXTURE, TEXTURES_FOLDER+"/gui/menubg", "gui/menubg");
|
||||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/delete_icon", "gui/delete_icon");
|
loader.add(AssetType::TEXTURE, TEXTURES_FOLDER+"/gui/delete_icon", "gui/delete_icon");
|
||||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/no_icon", "gui/no_icon");
|
loader.add(AssetType::TEXTURE, TEXTURES_FOLDER+"/gui/no_icon", "gui/no_icon");
|
||||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/no_world_icon", "gui/no_world_icon");
|
loader.add(AssetType::TEXTURE, TEXTURES_FOLDER+"/gui/no_world_icon", "gui/no_world_icon");
|
||||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/warning", "gui/warning");
|
loader.add(AssetType::TEXTURE, TEXTURES_FOLDER+"/gui/warning", "gui/warning");
|
||||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/error", "gui/error");
|
loader.add(AssetType::TEXTURE, TEXTURES_FOLDER+"/gui/error", "gui/error");
|
||||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/cross", "gui/cross");
|
loader.add(AssetType::TEXTURE, TEXTURES_FOLDER+"/gui/cross", "gui/cross");
|
||||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/refresh", "gui/refresh");
|
loader.add(AssetType::TEXTURE, TEXTURES_FOLDER+"/gui/refresh", "gui/refresh");
|
||||||
if (content) {
|
if (content) {
|
||||||
loader.processPreloadConfigs(content);
|
loader.processPreloadConfigs(content);
|
||||||
|
|
||||||
@ -206,8 +209,8 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
|
|||||||
addLayouts(pack->getEnvironment(), info.id, folder, loader);
|
addLayouts(pack->getEnvironment(), info.id, folder, loader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loader.add(AssetType::atlas, TEXTURES_FOLDER+"/blocks", "blocks");
|
loader.add(AssetType::ATLAS, TEXTURES_FOLDER+"/blocks", "blocks");
|
||||||
loader.add(AssetType::atlas, TEXTURES_FOLDER+"/items", "items");
|
loader.add(AssetType::ATLAS, TEXTURES_FOLDER+"/items", "items");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AssetsLoader::loadExternalTexture(
|
bool AssetsLoader::loadExternalTexture(
|
||||||
|
|||||||
@ -20,13 +20,14 @@ namespace dynamic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum class AssetType {
|
enum class AssetType {
|
||||||
texture,
|
TEXTURE,
|
||||||
shader,
|
SHADER,
|
||||||
font,
|
FONT,
|
||||||
atlas,
|
ATLAS,
|
||||||
layout,
|
LAYOUT,
|
||||||
sound,
|
SOUND,
|
||||||
model,
|
MODEL,
|
||||||
|
RIG,
|
||||||
};
|
};
|
||||||
|
|
||||||
class ResPaths;
|
class ResPaths;
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
#include "../graphics/core/Font.hpp"
|
#include "../graphics/core/Font.hpp"
|
||||||
#include "../graphics/core/Model.hpp"
|
#include "../graphics/core/Model.hpp"
|
||||||
#include "../graphics/core/TextureAnimation.hpp"
|
#include "../graphics/core/TextureAnimation.hpp"
|
||||||
|
#include "../objects/rigging.hpp"
|
||||||
#include "../frontend/UiDocument.hpp"
|
#include "../frontend/UiDocument.hpp"
|
||||||
#include "../constants.hpp"
|
#include "../constants.hpp"
|
||||||
|
|
||||||
@ -216,7 +217,7 @@ assetload::postfunc assetload::model(
|
|||||||
for (auto& mesh : model->meshes) {
|
for (auto& mesh : model->meshes) {
|
||||||
if (mesh.texture.find('$') == std::string::npos) {
|
if (mesh.texture.find('$') == std::string::npos) {
|
||||||
auto filename = TEXTURES_FOLDER+"/"+mesh.texture;
|
auto filename = TEXTURES_FOLDER+"/"+mesh.texture;
|
||||||
loader->add(AssetType::texture, filename, mesh.texture, nullptr);
|
loader->add(AssetType::TEXTURE, filename, mesh.texture, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assets->store(std::unique_ptr<model::Model>(model), name);
|
assets->store(std::unique_ptr<model::Model>(model), name);
|
||||||
@ -227,6 +228,27 @@ assetload::postfunc assetload::model(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assetload::postfunc assetload::rig(
|
||||||
|
AssetsLoader* loader,
|
||||||
|
const ResPaths* paths,
|
||||||
|
const std::string& file,
|
||||||
|
const std::string& name,
|
||||||
|
const std::shared_ptr<AssetCfg>&
|
||||||
|
) {
|
||||||
|
auto path = paths->find(file+".json");
|
||||||
|
auto text = files::read_string(path);
|
||||||
|
try {
|
||||||
|
auto rig = rigging::RigConfig::parse(text, path.u8string()).release();
|
||||||
|
return [=](Assets* assets) {
|
||||||
|
// TODO: add models loading
|
||||||
|
assets->store(std::unique_ptr<rigging::RigConfig>(rig), name);
|
||||||
|
};
|
||||||
|
} catch (const parsing_error& err) {
|
||||||
|
std::cerr << err.errorLog() << std::endl;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void read_anim_file(
|
static void read_anim_file(
|
||||||
const std::string& animFile,
|
const std::string& animFile,
|
||||||
std::vector<std::pair<std::string, int>>& frameList
|
std::vector<std::pair<std::string, int>>& frameList
|
||||||
|
|||||||
@ -63,6 +63,13 @@ namespace assetload {
|
|||||||
const std::string& name,
|
const std::string& name,
|
||||||
const std::shared_ptr<AssetCfg>& settings
|
const std::shared_ptr<AssetCfg>& settings
|
||||||
);
|
);
|
||||||
|
postfunc rig(
|
||||||
|
AssetsLoader*,
|
||||||
|
const ResPaths* paths,
|
||||||
|
const std::string& file,
|
||||||
|
const std::string& name,
|
||||||
|
const std::shared_ptr<AssetCfg>& settings
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ASSETS_ASSET_LOADERS_HPP_
|
#endif // ASSETS_ASSET_LOADERS_HPP_
|
||||||
|
|||||||
@ -238,11 +238,11 @@ Value Parser::parseValue() {
|
|||||||
throw error("unexpected character '"+std::string({next})+"'");
|
throw error("unexpected character '"+std::string({next})+"'");
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic::Map_sptr json::parse(const std::string& filename, const std::string& source) {
|
dynamic::Map_sptr json::parse(std::string_view filename, std::string_view source) {
|
||||||
Parser parser(filename, source);
|
Parser parser(filename, source);
|
||||||
return parser.parse();
|
return parser.parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic::Map_sptr json::parse(const std::string& source) {
|
dynamic::Map_sptr json::parse(std::string_view source) {
|
||||||
return parse("<string>", source);
|
return parse("<string>", source);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,8 +9,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace json {
|
namespace json {
|
||||||
dynamic::Map_sptr parse(const std::string& filename, const std::string& source);
|
dynamic::Map_sptr parse(std::string_view filename, std::string_view source);
|
||||||
dynamic::Map_sptr parse(const std::string& source);
|
dynamic::Map_sptr parse(std::string_view source);
|
||||||
|
|
||||||
std::string stringify(
|
std::string stringify(
|
||||||
const dynamic::Map* obj,
|
const dynamic::Map* obj,
|
||||||
|
|||||||
@ -50,5 +50,6 @@ inline const std::string FONTS_FOLDER = "fonts";
|
|||||||
inline const std::string LAYOUTS_FOLDER = "layouts";
|
inline const std::string LAYOUTS_FOLDER = "layouts";
|
||||||
inline const std::string SOUNDS_FOLDER = "sounds";
|
inline const std::string SOUNDS_FOLDER = "sounds";
|
||||||
inline const std::string MODELS_FOLDER = "models";
|
inline const std::string MODELS_FOLDER = "models";
|
||||||
|
inline const std::string RIGS_FOLDER = "rigs";
|
||||||
|
|
||||||
#endif // CONSTANTS_HPP_
|
#endif // CONSTANTS_HPP_
|
||||||
|
|||||||
@ -36,7 +36,8 @@ entityid_t Entities::spawn(EntityDef& def, glm::vec3 pos, dynamic::Value args) {
|
|||||||
auto id = nextID++;
|
auto id = nextID++;
|
||||||
registry.emplace<EntityId>(entity, static_cast<entityid_t>(id), def);
|
registry.emplace<EntityId>(entity, static_cast<entityid_t>(id), def);
|
||||||
registry.emplace<Transform>(entity, pos, size, glm::mat3(1.0f));
|
registry.emplace<Transform>(entity, pos, size, glm::mat3(1.0f));
|
||||||
auto& body = registry.emplace<Rigidbody>(entity, true, Hitbox {pos, def.hitbox}, std::vector<Trigger>{});
|
auto& body = registry.emplace<Rigidbody>(
|
||||||
|
entity, true, Hitbox {pos, def.hitbox}, std::vector<Trigger>{});
|
||||||
for (auto& box : def.triggers) {
|
for (auto& box : def.triggers) {
|
||||||
body.triggers.emplace_back(Trigger{true, id, box, AABB{}, {}, {},
|
body.triggers.emplace_back(Trigger{true, id, box, AABB{}, {}, {},
|
||||||
[=](auto entityid, auto index, auto otherid) {
|
[=](auto entityid, auto index, auto otherid) {
|
||||||
@ -140,7 +141,8 @@ void Entities::updatePhysics(float delta) {
|
|||||||
hitbox.linearDamping = hitbox.grounded * 24;
|
hitbox.linearDamping = hitbox.grounded * 24;
|
||||||
transform.setPos(hitbox.position);
|
transform.setPos(hitbox.position);
|
||||||
if (hitbox.grounded && !grounded) {
|
if (hitbox.grounded && !grounded) {
|
||||||
scripting::on_entity_grounded(*get(eid.uid), glm::length(prevVel-hitbox.velocity));
|
scripting::on_entity_grounded(
|
||||||
|
*get(eid.uid), glm::length(prevVel-hitbox.velocity));
|
||||||
}
|
}
|
||||||
if (!hitbox.grounded && grounded) {
|
if (!hitbox.grounded && grounded) {
|
||||||
scripting::on_entity_fall(*get(eid.uid));
|
scripting::on_entity_fall(*get(eid.uid));
|
||||||
|
|||||||
@ -77,7 +77,12 @@ class Entity {
|
|||||||
entt::registry& registry;
|
entt::registry& registry;
|
||||||
const entt::entity entity;
|
const entt::entity entity;
|
||||||
public:
|
public:
|
||||||
Entity(Entities& entities, entityid_t id, entt::registry& registry, const entt::entity entity)
|
Entity(
|
||||||
|
Entities& entities,
|
||||||
|
entityid_t id,
|
||||||
|
entt::registry& registry,
|
||||||
|
const entt::entity entity
|
||||||
|
)
|
||||||
: entities(entities), id(id), registry(registry), entity(entity) {}
|
: entities(entities), id(id), registry(registry), entity(entity) {}
|
||||||
|
|
||||||
EntityId& getID() const {
|
EntityId& getID() const {
|
||||||
|
|||||||
@ -8,6 +8,10 @@
|
|||||||
#include "../typedefs.hpp"
|
#include "../typedefs.hpp"
|
||||||
#include "../maths/aabb.hpp"
|
#include "../maths/aabb.hpp"
|
||||||
|
|
||||||
|
namespace rigging {
|
||||||
|
class RigConfig;
|
||||||
|
}
|
||||||
|
|
||||||
struct EntityDef {
|
struct EntityDef {
|
||||||
/// @brief Entity string id (with prefix included)
|
/// @brief Entity string id (with prefix included)
|
||||||
std::string const name;
|
std::string const name;
|
||||||
@ -15,9 +19,11 @@ struct EntityDef {
|
|||||||
std::string scriptName = name.substr(name.find(':')+1);
|
std::string scriptName = name.substr(name.find(':')+1);
|
||||||
glm::vec3 hitbox {0.5f};
|
glm::vec3 hitbox {0.5f};
|
||||||
std::vector<AABB> triggers {};
|
std::vector<AABB> triggers {};
|
||||||
|
std::string rigName = name.substr(name.find(":")+1);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
entityid_t id;
|
entityid_t id;
|
||||||
|
rigging::RigConfig* rig;
|
||||||
} rt {};
|
} rt {};
|
||||||
|
|
||||||
EntityDef(const std::string& name) : name(name) {}
|
EntityDef(const std::string& name) : name(name) {}
|
||||||
|
|||||||
@ -1,10 +1,89 @@
|
|||||||
#include "rigging.hpp"
|
#include "rigging.hpp"
|
||||||
|
|
||||||
|
#include "../assets/Assets.hpp"
|
||||||
|
#include "../graphics/core/Model.hpp"
|
||||||
|
#include "../coders/json.hpp"
|
||||||
|
|
||||||
using namespace rigging;
|
using namespace rigging;
|
||||||
|
|
||||||
RigNode::RigNode(size_t index, std::string name, std::vector<std::unique_ptr<RigNode>> subnodes)
|
RigNode::RigNode(
|
||||||
: index(index), name(std::move(name)), subnodes(std::move(subnodes)) {
|
size_t index,
|
||||||
|
std::string name,
|
||||||
|
std::string model,
|
||||||
|
std::vector<std::unique_ptr<RigNode>> subnodes)
|
||||||
|
: index(index),
|
||||||
|
name(std::move(name)),
|
||||||
|
modelName(model),
|
||||||
|
subnodes(std::move(subnodes))
|
||||||
|
{}
|
||||||
|
|
||||||
|
void RigNode::setModel(const Assets* assets, const std::string& name) {
|
||||||
|
modelName = name;
|
||||||
|
model = assets->get<model::Model>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
RigConfig::RigConfig(std::unique_ptr<RigNode> root) : root(std::move(root)) {
|
RigConfig::RigConfig(std::unique_ptr<RigNode> root) : root(std::move(root)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t RigConfig::update(
|
||||||
|
size_t index,
|
||||||
|
Rig& rig,
|
||||||
|
RigNode* node,
|
||||||
|
glm::mat4 matrix)
|
||||||
|
{
|
||||||
|
rig.calculated.matrices[index] = matrix * rig.pose.matrices[index];
|
||||||
|
index++;
|
||||||
|
for (auto& subnode : node->getSubnodes()) {
|
||||||
|
index = update(index, rig, subnode.get(), rig.calculated.matrices[index]);
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RigConfig::update(Rig& rig, glm::mat4 matrix) {
|
||||||
|
update(0, rig, root.get(), matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RigConfig::setup(const Assets* assets, RigNode* node) {
|
||||||
|
if (node == nullptr) {
|
||||||
|
setup(assets, root.get());
|
||||||
|
} else {
|
||||||
|
node->setModel(assets, node->getModelName());
|
||||||
|
for (auto& subnode : node->getSubnodes()) {
|
||||||
|
setup(assets, subnode.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::tuple<size_t, std::unique_ptr<RigNode>> read_node(
|
||||||
|
dynamic::Map* root, size_t index
|
||||||
|
) {
|
||||||
|
std::string name;
|
||||||
|
std::string model;
|
||||||
|
root->str("name", name);
|
||||||
|
root->str("model", model);
|
||||||
|
std::vector<std::unique_ptr<RigNode>> subnodes;
|
||||||
|
size_t count = 1;
|
||||||
|
if (auto nodesList = root->list("nodes")) {
|
||||||
|
for (size_t i = 0; i < nodesList->size(); i++) {
|
||||||
|
if (auto map = nodesList->map(i)) {
|
||||||
|
auto [subcount, subNode] = read_node(map, index+count);
|
||||||
|
subcount += count;
|
||||||
|
subnodes.push_back(std::move(subNode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {index, std::make_unique<RigNode>(index, name, model, std::move(subnodes))};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<RigConfig> RigConfig::parse(
|
||||||
|
std::string_view src,
|
||||||
|
std::string_view file
|
||||||
|
) {
|
||||||
|
auto root = json::parse(file, src);
|
||||||
|
auto rootNodeMap = root->map("root");
|
||||||
|
if (rootNodeMap == nullptr) {
|
||||||
|
throw std::runtime_error("missing 'root' element");
|
||||||
|
}
|
||||||
|
auto [count, rootNode] = read_node(root.get(), 0);
|
||||||
|
return std::make_unique<RigConfig>(std::move(rootNode));
|
||||||
|
}
|
||||||
|
|||||||
@ -9,6 +9,12 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
class Assets;
|
||||||
|
|
||||||
|
namespace model {
|
||||||
|
struct Model;
|
||||||
|
}
|
||||||
|
|
||||||
namespace rigging {
|
namespace rigging {
|
||||||
struct Rig;
|
struct Rig;
|
||||||
|
|
||||||
@ -19,9 +25,21 @@ namespace rigging {
|
|||||||
class RigNode {
|
class RigNode {
|
||||||
size_t index;
|
size_t index;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
std::string modelName;
|
||||||
std::vector<std::unique_ptr<RigNode>> subnodes;
|
std::vector<std::unique_ptr<RigNode>> subnodes;
|
||||||
|
model::Model* model = nullptr;
|
||||||
public:
|
public:
|
||||||
RigNode(size_t index, std::string name, std::vector<std::unique_ptr<RigNode>> subnodes);
|
RigNode(
|
||||||
|
size_t index,
|
||||||
|
std::string name,
|
||||||
|
std::string model,
|
||||||
|
std::vector<std::unique_ptr<RigNode>> subnodes);
|
||||||
|
|
||||||
|
void setModel(const Assets* assets, const std::string& name);
|
||||||
|
|
||||||
|
const std::string& getModelName() const {
|
||||||
|
return modelName;
|
||||||
|
}
|
||||||
|
|
||||||
size_t getIndex() const {
|
size_t getIndex() const {
|
||||||
return index;
|
return index;
|
||||||
@ -36,13 +54,28 @@ namespace rigging {
|
|||||||
std::unique_ptr<RigNode> root;
|
std::unique_ptr<RigNode> root;
|
||||||
std::unordered_map<std::string, size_t> indices;
|
std::unordered_map<std::string, size_t> indices;
|
||||||
std::vector<RigNode*> nodes;
|
std::vector<RigNode*> nodes;
|
||||||
|
|
||||||
|
size_t update(
|
||||||
|
size_t index,
|
||||||
|
Rig& rig,
|
||||||
|
RigNode* node,
|
||||||
|
glm::mat4 matrix);
|
||||||
public:
|
public:
|
||||||
RigConfig(std::unique_ptr<RigNode> root);
|
RigConfig(std::unique_ptr<RigNode> root);
|
||||||
|
|
||||||
|
void update(Rig& rig, glm::mat4 matrix);
|
||||||
|
void setup(const Assets* assets, RigNode* node=nullptr);
|
||||||
|
|
||||||
|
static std::unique_ptr<RigConfig> parse(
|
||||||
|
std::string_view src,
|
||||||
|
std::string_view file
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Rig {
|
struct Rig {
|
||||||
RigConfig* config;
|
RigConfig* config;
|
||||||
Pose pose;
|
Pose pose;
|
||||||
|
Pose calculated;
|
||||||
std::vector<std::string> textures;
|
std::vector<std::string> textures;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user