Fix stl parser bug

This commit is contained in:
Alex Selimov 2026-09-16 09:29:38 -04:00
parent 7fd66963ca
commit dc7cb9d0d2

View file

@ -81,11 +81,12 @@ pub const Mesh = struct {
indices[i] = new_idx; indices[i] = new_idx;
} }
} }
// skip attribute bytes
offset += 2;
try triangle_vertices.append(allocator, indices); try triangle_vertices.append(allocator, indices);
try triangle_normals.append(allocator, normal); try triangle_normals.append(allocator, normal);
} }
std.debug.print("{}", .{vertices});
return .{ return .{
.triangle_vertices = triangle_vertices, .triangle_vertices = triangle_vertices,
.triangle_normals = triangle_normals, .triangle_normals = triangle_normals,
@ -150,4 +151,16 @@ test "Test binary stl is parsed correctly" {
vec3.Vec3F64.init(1, 1, 1), vec3.Vec3F64.init(1, 1, 1),
1e-12, 1e-12,
)); ));
try std.testing.expect(vec3.vec3ApproxEq(
mesh.triangle_normals.items[0],
vec3.Vec3F64.init(1, 0, 0),
1e-12,
));
try std.testing.expect(vec3.vec3ApproxEq(
mesh.triangle_normals.items[1],
vec3.Vec3F64.init(0, -0.7071067690849304, 0.7071067690849304),
1e-12,
));
} }