mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
fix: destroyed skeleton config access on skeleton reload
This commit is contained in:
parent
33db2633a2
commit
9893c09fd5
9 changed files with 35 additions and 22 deletions
|
|
@ -39,7 +39,7 @@ void Bone::setModel(const std::string& name) {
|
|||
model = {name, nullptr, true};
|
||||
}
|
||||
|
||||
Skeleton::Skeleton(const SkeletonConfig* config)
|
||||
Skeleton::Skeleton(std::shared_ptr<const SkeletonConfig> config)
|
||||
: config(config),
|
||||
pose(config->getBones().size()),
|
||||
calculated(config->getBones().size()),
|
||||
|
|
@ -86,6 +86,16 @@ void Skeleton::deserialize(const dv::value& root) {
|
|||
}
|
||||
}
|
||||
|
||||
void Skeleton::setConfig(std::shared_ptr<const SkeletonConfig> rigConfig) {
|
||||
config = std::move(rigConfig);
|
||||
pose.matrices.resize(
|
||||
config->getBones().size(), glm::mat4(1.0f)
|
||||
);
|
||||
calculated.matrices.resize(
|
||||
config->getBones().size(), glm::mat4(1.0f)
|
||||
);
|
||||
}
|
||||
|
||||
static void get_all_nodes(std::vector<Bone*>& nodes, Bone* node) {
|
||||
nodes[node->getIndex()] = node;
|
||||
for (auto& subnode : node->getBones()) {
|
||||
|
|
@ -97,6 +107,7 @@ SkeletonConfig::SkeletonConfig(
|
|||
const std::string& name, std::unique_ptr<Bone> root, size_t nodesCount
|
||||
)
|
||||
: name(name), root(std::move(root)), nodes(nodesCount) {
|
||||
assert(this->root.get() != nullptr);
|
||||
get_all_nodes(nodes, this->root.get());
|
||||
}
|
||||
|
||||
|
|
@ -159,6 +170,9 @@ void SkeletonConfig::render(
|
|||
const glm::vec3& position,
|
||||
const glm::vec3& scale
|
||||
) const {
|
||||
if (skeleton.config->root == nullptr) {
|
||||
return;
|
||||
}
|
||||
update(skeleton, rotation, position, scale);
|
||||
|
||||
if (!skeleton.visible) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue