From 6b765a85cf81bf4b7162e4c9280dd4054581c611 Mon Sep 17 00:00:00 2001 From: vimene Date: Mon, 11 Dec 2023 12:42:46 +0100 Subject: improved mesh definition - In the context of mesh definition, splited indices into vertex index, normal index and vertex data index to be able to specify different normals and vertex data for different faces using the same vertex --- src/engine.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/engine.cpp') diff --git a/src/engine.cpp b/src/engine.cpp index 96dfd7b..e8cde92 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -23,9 +23,8 @@ #include "o3d/scene.h" #include "o3d/mesh.h" #include "o3d/obj3d.h" -#include "o3d/vertex.h" #include "o3d/vertex_data.h" -#include "o3d/tri_vertex.h" +#include "o3d/tri.h" #include "o3d/camera.h" #include "math/vector.h" #include "math/mat4.h" @@ -87,11 +86,16 @@ static void scene_main(engine::Renderer& renderer, engine::math::Matrix4 final_t for (int i = 0; i < 1; i++) { auto final_mat = pre_final_mat * mats[i]; const auto& mesh = scene.objs[i].mesh; - std::vector pts; - for (const auto& vert : mesh.pts) - pts.push_back({ final_mat * engine::math::Vector4{vert.point}, vert.data }); - for (auto face : mesh.faces) - renderer.draw_triangle({pts[face[0]], pts[face[1]], pts[face[2]]}); + std::vector vertices; + for (const auto& vertex : mesh.vertices) + vertices.push_back(final_mat * vertex); + for (auto triangle_indices : mesh.indices) { + renderer.draw_triangle({ + {vertices[triangle_indices[0][0]], mesh.normals[triangle_indices[0][1]], mesh.vertices_data[triangle_indices[0][2]]}, + {vertices[triangle_indices[1][0]], mesh.normals[triangle_indices[1][1]], mesh.vertices_data[triangle_indices[1][2]]}, + {vertices[triangle_indices[2][0]], mesh.normals[triangle_indices[2][1]], mesh.vertices_data[triangle_indices[2][2]]}, + }); + } } cont = update_frame(); } -- cgit v1.2.3