remove bone::addBone

This commit is contained in:
MihailRis 2026-01-15 23:17:47 +03:00
parent 6760d16052
commit 587c140a6b
4 changed files with 23 additions and 23 deletions

View file

@ -23,7 +23,7 @@ static int calc_offsets(
} else {
dst[index] = dst[parent] + bone.getOffset();
}
const auto& subBones = bone.getSubnodes();
const auto& subBones = bone.getBones();
int subIndex = index + 1;
for (int i = 0; i < subBones.size(); i++) {
@ -151,7 +151,7 @@ private:
struct Context {
VcmModel& vcmModel;
Bone& bone;
std::vector<std::unique_ptr<Bone>>& bones;
size_t& boneIndex;
};
@ -372,16 +372,19 @@ static void perform_bone(const xmlelement& root, ModelBuilder& builder, Context&
builder.pop();
} else {
glm::vec3 origin = builder.getTransform() * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
auto& bone = ctx.bone.addBone(
Bone(ctx.boneIndex++, name, name, {}, std::move(origin))
);
Context boneContext {ctx.vcmModel, bone, ctx.boneIndex};
size_t boneIndex = ctx.boneIndex++;
std::vector<std::unique_ptr<Bone>> bones;
Context boneContext {ctx.vcmModel, bones, ctx.boneIndex};
Model boneModel;
ModelBuilder boneModelBuilder(boneModel);
boneModelBuilder.push(std::move(tsf));
for (const auto& elem : root.getElements()) {
perform_element(*elem, boneModelBuilder, boneContext);
}
ctx.bones.push_back(std::make_unique<Bone>(
boneIndex, name, name, std::move(bones), std::move(origin)
));
ctx.vcmModel.parts[std::move(name)] = std::move(boneModel);
}
}
@ -405,9 +408,9 @@ static VcmModel load_model(const xmlelement& root) {
Model model;
ModelBuilder builder(model);
size_t boneIndex = 0;
Bone rootBone(boneIndex++, "root", "root", {}, glm::vec3(0.0f));
Context ctx { vcmModel, rootBone, boneIndex };
size_t boneIndex = 1;
std::vector<std::unique_ptr<Bone>> bones;
Context ctx { vcmModel, bones, boneIndex };
for (const auto& elem : root.getElements()) {
perform_element(*elem, builder, ctx);
@ -415,7 +418,11 @@ static VcmModel load_model(const xmlelement& root) {
vcmModel.parts["root"] = std::move(model);
vcmModel.skeleton = SkeletonConfig(
"", std::make_unique<Bone>(std::move(rootBone)), boneIndex
"",
std::make_unique<Bone>(
0, "root", "root", std::move(bones), glm::vec3(0.0f)
),
boneIndex
);
return vcmModel;
}

View file

@ -333,7 +333,7 @@ static void debug_render_skeleton(
const rigging::Skeleton& skeleton
) {
size_t pindex = bone->getIndex();
for (auto& sub : bone->getSubnodes()) {
for (auto& sub : bone->getBones()) {
size_t sindex = sub->getIndex();
const auto& matrices = skeleton.calculated.matrices;
batch.line(

View file

@ -32,11 +32,6 @@ Bone::Bone(
model({model, nullptr, true}) {
}
Bone& Bone::addBone(Bone&& bone) {
bones.push_back(std::make_unique<Bone>(std::move(bone)));
return *bones[bones.size() - 1];
}
void Bone::setModel(const std::string& name) {
if (model.name == name) {
return;
@ -93,7 +88,7 @@ void Skeleton::deserialize(const dv::value& root) {
static void get_all_nodes(std::vector<Bone*>& nodes, Bone* node) {
nodes[node->getIndex()] = node;
for (auto& subnode : node->getSubnodes()) {
for (auto& subnode : node->getBones()) {
get_all_nodes(nodes, subnode.get());
}
}
@ -116,7 +111,7 @@ size_t SkeletonConfig::update(
}
skeleton.calculated.matrices[index] = matrix * baseMatrix * boneMatrix;
size_t count = 1;
for (auto& subnode : node->getSubnodes()) {
for (auto& subnode : node->getBones()) {
count += update(
index + count,
skeleton,
@ -192,7 +187,7 @@ void SkeletonConfig::render(
}
}
Bone* SkeletonConfig::find(std::string_view str) const {
const Bone* SkeletonConfig::find(std::string_view str) const {
for (size_t i = 0; i < nodes.size(); i++) {
auto* node = nodes[i];
if (node->getName() == str) {

View file

@ -54,8 +54,6 @@ namespace rigging {
const glm::vec3& offset
);
Bone& addBone(Bone&& bone);
void setModel(const std::string& name);
const std::string& getName() const {
@ -70,7 +68,7 @@ namespace rigging {
return offset;
}
const auto& getSubnodes() const {
const auto& getBones() const {
return bones;
}
};
@ -140,7 +138,7 @@ namespace rigging {
return Skeleton(this);
}
Bone* find(std::string_view str) const;
const Bone* find(std::string_view str) const;
static std::unique_ptr<SkeletonConfig> parse(
std::string_view src, std::string_view file, std::string_view name