refactor src/objects/rigging
This commit is contained in:
parent
0d230f2449
commit
2c7b5de50a
@ -81,7 +81,7 @@ template<class T>
|
||||
void assetload::assets_setup(const Assets* assets) {
|
||||
if (auto mapPtr = assets->getMap<T>()) {
|
||||
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());
|
||||
|
||||
auto new_assets = std::make_unique<Assets>();
|
||||
new_assets->addSetupFunc(assetload::assets_setup<rigging::RigConfig>);
|
||||
AssetsLoader loader(new_assets.get(), resPaths.get());
|
||||
AssetsLoader::addDefaults(loader, content.get());
|
||||
|
||||
|
||||
@ -18,9 +18,19 @@ RigNode::RigNode(
|
||||
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;
|
||||
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) {
|
||||
@ -53,19 +63,8 @@ void RigConfig::update(Rig& rig, glm::mat4 matrix) const {
|
||||
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(
|
||||
Assets*,
|
||||
Assets* assets,
|
||||
ModelBatch& batch,
|
||||
Rig& rig,
|
||||
const glm::mat4& matrix) const
|
||||
@ -73,13 +72,12 @@ void RigConfig::render(
|
||||
update(rig, matrix);
|
||||
for (size_t i = 0; i < nodes.size(); i++) {
|
||||
auto* node = nodes[i];
|
||||
auto model = node->getModel();
|
||||
if (model == nullptr) {
|
||||
continue;
|
||||
node->refreshModel(assets);
|
||||
if (auto model = node->getModel()) {
|
||||
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::vector<std::unique_ptr<RigNode>> subnodes;
|
||||
model::Model* model = nullptr;
|
||||
bool modelUpdated = true;
|
||||
public:
|
||||
RigNode(
|
||||
size_t index,
|
||||
@ -41,7 +42,9 @@ namespace rigging {
|
||||
std::string model,
|
||||
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 {
|
||||
return modelName;
|
||||
@ -90,7 +93,6 @@ namespace rigging {
|
||||
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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user