refactor src/objects/rigging
This commit is contained in:
@@ -81,7 +81,7 @@ template<class T>
|
|||||||
void assetload::assets_setup(const Assets* assets) {
|
void assetload::assets_setup(const Assets* assets) {
|
||||||
if (auto mapPtr = assets->getMap<T>()) {
|
if (auto mapPtr = assets->getMap<T>()) {
|
||||||
for (const auto& entry : **mapPtr) {
|
for (const auto& entry : **mapPtr) {
|
||||||
static_cast<T*>(entry.second.get())->setup(assets);
|
static_cast<T*>(entry.second.get())->setup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -245,7 +245,6 @@ void Engine::loadAssets() {
|
|||||||
Shader::preprocessor->setPaths(resPaths.get());
|
Shader::preprocessor->setPaths(resPaths.get());
|
||||||
|
|
||||||
auto new_assets = std::make_unique<Assets>();
|
auto new_assets = std::make_unique<Assets>();
|
||||||
new_assets->addSetupFunc(assetload::assets_setup<rigging::RigConfig>);
|
|
||||||
AssetsLoader loader(new_assets.get(), resPaths.get());
|
AssetsLoader loader(new_assets.get(), resPaths.get());
|
||||||
AssetsLoader::addDefaults(loader, content.get());
|
AssetsLoader::addDefaults(loader, content.get());
|
||||||
|
|
||||||
|
|||||||
+18
-20
@@ -18,9 +18,19 @@ RigNode::RigNode(
|
|||||||
subnodes(std::move(subnodes))
|
subnodes(std::move(subnodes))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void RigNode::setModel(const Assets* assets, const std::string& name) {
|
void RigNode::setModel(const std::string& name) {
|
||||||
|
if (modelName == name) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
modelName = name;
|
modelName = name;
|
||||||
model = assets->get<model::Model>(name);
|
modelUpdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RigNode::refreshModel(const Assets* assets) {
|
||||||
|
if (modelUpdated) {
|
||||||
|
model = assets->get<model::Model>(modelName);
|
||||||
|
modelUpdated = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_all_nodes(std::vector<RigNode*>& nodes, RigNode* node) {
|
static void get_all_nodes(std::vector<RigNode*>& nodes, RigNode* node) {
|
||||||
@@ -53,19 +63,8 @@ void RigConfig::update(Rig& rig, glm::mat4 matrix) const {
|
|||||||
update(0, rig, root.get(), matrix);
|
update(0, rig, root.get(), matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigConfig::setup(const Assets* assets, RigNode* node) const {
|
|
||||||
if (node == nullptr) {
|
|
||||||
setup(assets, root.get());
|
|
||||||
} else {
|
|
||||||
node->setModel(assets, node->getModelName());
|
|
||||||
for (auto& subnode : node->getSubnodes()) {
|
|
||||||
setup(assets, subnode.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RigConfig::render(
|
void RigConfig::render(
|
||||||
Assets*,
|
Assets* assets,
|
||||||
ModelBatch& batch,
|
ModelBatch& batch,
|
||||||
Rig& rig,
|
Rig& rig,
|
||||||
const glm::mat4& matrix) const
|
const glm::mat4& matrix) const
|
||||||
@@ -73,13 +72,12 @@ void RigConfig::render(
|
|||||||
update(rig, matrix);
|
update(rig, matrix);
|
||||||
for (size_t i = 0; i < nodes.size(); i++) {
|
for (size_t i = 0; i < nodes.size(); i++) {
|
||||||
auto* node = nodes[i];
|
auto* node = nodes[i];
|
||||||
auto model = node->getModel();
|
node->refreshModel(assets);
|
||||||
if (model == nullptr) {
|
if (auto model = node->getModel()) {
|
||||||
continue;
|
batch.pushMatrix(rig.calculated.matrices[i]);
|
||||||
|
batch.draw(model, &rig.textures);
|
||||||
|
batch.popMatrix();
|
||||||
}
|
}
|
||||||
batch.pushMatrix(rig.calculated.matrices[i]);
|
|
||||||
batch.draw(model, &rig.textures);
|
|
||||||
batch.popMatrix();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace rigging {
|
|||||||
std::string modelName;
|
std::string modelName;
|
||||||
std::vector<std::unique_ptr<RigNode>> subnodes;
|
std::vector<std::unique_ptr<RigNode>> subnodes;
|
||||||
model::Model* model = nullptr;
|
model::Model* model = nullptr;
|
||||||
|
bool modelUpdated = true;
|
||||||
public:
|
public:
|
||||||
RigNode(
|
RigNode(
|
||||||
size_t index,
|
size_t index,
|
||||||
@@ -41,7 +42,9 @@ namespace rigging {
|
|||||||
std::string model,
|
std::string model,
|
||||||
std::vector<std::unique_ptr<RigNode>> subnodes);
|
std::vector<std::unique_ptr<RigNode>> subnodes);
|
||||||
|
|
||||||
void setModel(const Assets* assets, const std::string& name);
|
void setModel(const std::string& name);
|
||||||
|
|
||||||
|
void refreshModel(const Assets* assets);
|
||||||
|
|
||||||
const std::string& getModelName() const {
|
const std::string& getModelName() const {
|
||||||
return modelName;
|
return modelName;
|
||||||
@@ -90,7 +93,6 @@ namespace rigging {
|
|||||||
size_t nodesCount);
|
size_t nodesCount);
|
||||||
|
|
||||||
void update(Rig& rig, glm::mat4 matrix) const;
|
void update(Rig& rig, glm::mat4 matrix) const;
|
||||||
void setup(const Assets* assets, RigNode* node=nullptr) const;
|
|
||||||
void render(
|
void render(
|
||||||
Assets* assets,
|
Assets* assets,
|
||||||
ModelBatch& batch,
|
ModelBatch& batch,
|
||||||
|
|||||||
Reference in New Issue
Block a user