diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2022-08-29 23:11:29 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2022-08-29 23:11:29 +0200 |
| commit | 8b8b3c8aaa859ceff95e82e26b81410688613cd7 (patch) | |
| tree | 4cdac9321f34d5dc948fc16eb6a1c4953b98eded /src/scene.cpp | |
| parent | ae0ea5fb65b0340eabf4e9e424ba79787600dc1b (diff) | |
Fix meshes attributes copy to arrays
Diffstat (limited to 'src/scene.cpp')
| -rw-r--r-- | src/scene.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/scene.cpp b/src/scene.cpp index 4093ff7..2f4aa97 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -89,32 +89,34 @@ scene::scene(const camera& cam, uint32_t width, uint32_t height) const auto& mesh_positions = mesh->get_attribute(ATTRIBUTE_TYPE::POSITION);
const auto& mesh_indices = mesh->get_indices();
- indices.resize(indices.size() + (size_t)mesh->triangle_count() * 3);
- positions.resize(vertices_offset + (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::POSITION));
+ indices.resize(indices.size() + mesh_indices.size());
+ positions.resize(vertices_offset + mesh_positions.size());
normals.resize(vertices_offset + (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::NORMAL));
uvs.resize(vertices_offset + (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::UV_0));
std::memcpy(
positions.data() + vertices_offset * Mesh::attribute_components(ATTRIBUTE_TYPE::POSITION),
- positions.data(),
- (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::POSITION)
+ mesh_positions.data(),
+ mesh_positions.size() * sizeof(float)
);
std::memcpy(
normals.data() + vertices_offset * Mesh::attribute_components(ATTRIBUTE_TYPE::NORMAL),
mesh->get_attribute(ATTRIBUTE_TYPE::NORMAL).data(),
- (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::NORMAL)
+ (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::NORMAL) * sizeof(float)
);
std::memcpy(
uvs.data() + vertices_offset * Mesh::attribute_components(ATTRIBUTE_TYPE::UV_0),
mesh->get_attribute(ATTRIBUTE_TYPE::UV_0).data(),
- (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::UV_0)
+ (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::UV_0) * sizeof(float)
);
// Add offset to indices in order to have absolute indices
for (const auto& submesh: mesh->get_submeshes()) {
- for (size_t element_index = 0; element_index < submesh.element_count; element_index++) {
+ auto vertex_offset = vertices_offset + submesh.vertex_offset;
+
+ for (size_t element_index { 0U }; element_index < submesh.element_count; element_index++) {
auto global_index = submesh.index_offset + element_index * 3;
size_t i1 = mesh_indices[global_index];
size_t i2 = mesh_indices[global_index + 1];
@@ -127,7 +129,6 @@ scene::scene(const camera& cam, uint32_t width, uint32_t height) );
auto triangle_offset = triangles_offset * 3 + global_index;
- auto vertex_offset = vertices_offset + submesh.vertex_offset;
indices[triangle_offset] = (i1 + vertex_offset); // | (0xff000000 & (materials.size() << 8));
indices[triangle_offset + 1] = (i2 + vertex_offset); // | (0xff000000 & (materials.size() << 16));
|
