mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 04:21:50 +00:00
feat: named bones and skeleton building
This commit is contained in:
parent
495e5fa994
commit
c34cb57fb8
6 changed files with 147 additions and 15 deletions
|
|
@ -162,6 +162,12 @@ void Mesh::transform(const glm::mat4& matrix) {
|
|||
}
|
||||
}
|
||||
|
||||
void Mesh::translate(const glm::vec3& offset) {
|
||||
for (auto& vertex : vertices) {
|
||||
vertex.coord += offset;
|
||||
}
|
||||
}
|
||||
|
||||
void Model::clean() {
|
||||
meshes.erase(
|
||||
std::remove_if(meshes.begin(), meshes.end(),
|
||||
|
|
@ -178,6 +184,12 @@ void Model::transform(const glm::mat4& matrix) {
|
|||
}
|
||||
}
|
||||
|
||||
void Model::translate(const glm::vec3& offset) {
|
||||
for (auto& mesh : meshes) {
|
||||
mesh.translate(offset);
|
||||
}
|
||||
}
|
||||
|
||||
void Model::merge(const Model& source) {
|
||||
for (const auto& srcMesh : source.meshes) {
|
||||
auto& dstMesh = addMesh(srcMesh.texture, srcMesh.shading);
|
||||
|
|
@ -188,3 +200,18 @@ void Model::merge(const Model& source) {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
void Model::merge(Model&& source) {
|
||||
for (auto& srcMesh : source.meshes) {
|
||||
auto& dstMesh = addMesh(srcMesh.texture, srcMesh.shading);
|
||||
if (dstMesh.vertices.empty()) {
|
||||
dstMesh = std::move(srcMesh);
|
||||
} else {
|
||||
dstMesh.vertices.insert(
|
||||
dstMesh.vertices.end(),
|
||||
srcMesh.vertices.begin(),
|
||||
srcMesh.vertices.end()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,9 @@ namespace model {
|
|||
|
||||
/// @brief Apply transformation matrix to vertices coordinates
|
||||
void transform(const glm::mat4& matrix);
|
||||
|
||||
/// @brief Move vertices coordinates by offset
|
||||
void translate(const glm::vec3& offset);
|
||||
};
|
||||
|
||||
struct Model {
|
||||
|
|
@ -92,14 +95,22 @@ namespace model {
|
|||
meshes.push_back({texture, {}, shading});
|
||||
return meshes[meshes.size() - 1];
|
||||
}
|
||||
|
||||
/// @brief Remove all empty meshes
|
||||
void clean();
|
||||
|
||||
/// @brief Apply transformation matrix to vertices coordinates
|
||||
void transform(const glm::mat4& matrix);
|
||||
|
||||
/// @brief Move vertices coordinates by offset
|
||||
void translate(const glm::vec3& offset);
|
||||
|
||||
/// @brief Copy or merge meshes from source model to this.
|
||||
/// Does not remove duplicates
|
||||
void merge(const Model& source);
|
||||
|
||||
/// @brief Move or merge meshes from source model to this.
|
||||
/// Does not remove duplicates
|
||||
void merge(Model&& source);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue