fix: drawing issue

This commit is contained in:
2025-10-13 21:22:35 +02:00
parent c30419899d
commit 97606d398c

View File

@@ -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<Vertex>& out_vertices,
std::vector<uint16_t>& out_indices)
void process_shape(const tinyobj::shape_t& shape,
const tinyobj::attrib_t& attrib,
std::vector<Vertex>& out_vertices,
std::vector<uint16_t>& 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<uint16_t>(out_vertices.size() - 1));
@@ -118,11 +105,11 @@ std::shared_ptr<Texture> 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<Vertex>& vertices,
const std::vector<uint16_t>& indices, LoadContext& context,
std::shared_ptr<Mesh>& mesh)
void create_buffer_for_shape(const tinyobj::shape_t& shape,
const std::vector<Vertex>& vertices,
const std::vector<uint16_t>& indices,
LoadContext& context,
std::shared_ptr<Mesh>& mesh)
{
auto buffer = std::make_shared<Buffer>(vertices, indices);
@@ -183,17 +170,13 @@ std::shared_ptr<Mesh> Mesh::load(const char* filename,
// Process each shape
auto mesh = std::make_shared<Mesh>();
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<Vertex> vertices;
std::vector<uint16_t> 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(),