aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesh.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh.cpp')
-rw-r--r--src/mesh.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/mesh.cpp b/src/mesh.cpp
new file mode 100644
index 0000000..c9b5358
--- /dev/null
+++ b/src/mesh.cpp
@@ -0,0 +1,45 @@
+#include "mesh.hpp"
+
+static std::vector<Mesh> meshes {};
+
+void Mesh::add_submesh(const submesh& submesh) {
+ auto position_components = attribute_components(ATTRIBUTE_TYPE::POSITION);
+ submeshes.emplace_back(submesh_info {
+ (uint32_t)attributes[ATTRIBUTE_TYPE::POSITION].size() / position_components,
+ (uint32_t)indices.size(),
+ submesh.index_count,
+ 0
+ });
+
+ {
+ auto indices_off = indices.size();
+ indices.resize(indices_off + submesh.index_count);
+ std::memcpy(&indices[indices_off], submesh.indices.data, submesh.indices.length);
+ }
+
+ for (uint32_t attribute_index { ATTRIBUTE_TYPE::POSITION }; attribute_index < ATTRIBUTE_TYPE::MAX_ATTRIBUTE; attribute_index++) {
+ const auto& submesh_attribute = submesh.attributes[attribute_index];
+ if (submesh_attribute.data == nullptr) continue;
+
+ auto& mesh_attribute = attributes[attribute_index];
+ auto attribute_off = mesh_attribute.size();
+ auto element_components = attribute_components(static_cast<ATTRIBUTE_TYPE>(attribute_index));
+ auto elements_count = submesh.vertex_count * element_components;
+
+ mesh_attribute.resize(attribute_off + elements_count);
+ std::memcpy(&mesh_attribute[attribute_off], submesh_attribute.data, submesh_attribute.length);
+ }
+
+ vertex_count += submesh.vertex_count;
+ index_count += submesh.index_count;
+}
+
+[[nodiscard]] Mesh::mesh_instance Mesh::instantiate () const {
+ return {
+ *this
+ };
+}
+
+void Mesh::register_mesh(const Mesh& mesh) {
+ meshes.emplace_back(mesh);
+}