diff --git a/src/mesh.cpp b/src/mesh.cpp index 869f38b..3348d4c 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -39,39 +39,26 @@ Vertex create_vertex(const tinyobj::attrib_t& attrib, // Color (default to white) vertex.color = glm::vec3(1.0f, 1.0f, 1.0f); - // Texture coordinates (default to 0,0) + // Texture coordinates vertex.tex_coord = glm::vec2(0.0f, 0.0f); if (idx.texcoord_index >= 0) { - vertex.tex_coord.x = - attrib.texcoords[2 * idx.texcoord_index + 0]; - vertex.tex_coord.y = - attrib.texcoords[2 * idx.texcoord_index + 1]; // No Y-flip + vertex.tex_coord.x = attrib.texcoords[2 * idx.texcoord_index + 0]; + vertex.tex_coord.y = attrib.texcoords[2 * idx.texcoord_index + 1]; } return vertex; } -void process_shape_simple(const tinyobj::shape_t& shape, - const tinyobj::attrib_t& attrib, - std::vector& out_vertices, - std::vector& out_indices) +void process_shape(const tinyobj::shape_t& shape, + const tinyobj::attrib_t& attrib, + std::vector& out_vertices, + std::vector& out_indices) { - // Process all indices directly - one vertex per index + // Process all indices - create one vertex per index for (size_t i = 0; i < shape.mesh.indices.size(); ++i) { const tinyobj::index_t& idx = shape.mesh.indices[i]; Vertex vertex = create_vertex(attrib, idx); - // Debug: Print first 3 vertices - if (i < 3) { - Logger::info(sstr(" Vertex ", i, ": pos(", - vertex.position.x, ",", - vertex.position.y, ",", - vertex.position.z, ") tex(", - vertex.tex_coord.x, ",", - vertex.tex_coord.y, ") texidx=", - idx.texcoord_index)); - } - out_vertices.push_back(vertex); out_indices.push_back( static_cast(out_vertices.size() - 1)); @@ -118,11 +105,11 @@ std::shared_ptr load_material_texture(int material_id, return texture; } -// Create a single buffer for the shape with first material -void create_buffer_simple(const tinyobj::shape_t& shape, - const std::vector& vertices, - const std::vector& indices, LoadContext& context, - std::shared_ptr& mesh) +void create_buffer_for_shape(const tinyobj::shape_t& shape, + const std::vector& vertices, + const std::vector& indices, + LoadContext& context, + std::shared_ptr& mesh) { auto buffer = std::make_shared(vertices, indices); @@ -183,17 +170,13 @@ std::shared_ptr Mesh::load(const char* filename, // Process each shape auto mesh = std::make_shared(); for (const auto& shape : shapes) { - Logger::info(sstr("Processing shape: ", shape.name, " with ", - shape.mesh.indices.size(), " indices")); + Logger::info(sstr("Processing shape: ", shape.name)); std::vector vertices; std::vector indices; - process_shape_simple(shape, attrib, vertices, indices); - create_buffer_simple(shape, vertices, indices, context, mesh); - - Logger::info(sstr("Created buffer with ", vertices.size(), - " vertices")); + process_shape(shape, attrib, vertices, indices); + create_buffer_for_shape(shape, vertices, indices, context, mesh); } Logger::info(sstr("Mesh loaded successfully with ", mesh->num_buffers(),