Files
fn_registry/cpp/functions/gfx/mesh_obj_load.h
T
egutierrez 10ac4c74db feat(gfx): mesh_obj_load — minimal Wavefront .obj parser
mesh_obj_parse (pure) + mesh_obj_load (impure file helper).
Soporta v / vn / f (tris y quads). Genera normales per-face si
faltan (flat shading). Quads se parten en 2 tris; n-gons (>4) se
descartan silenciosamente. Indices 1-based positivos y negativos.

issue 0029
2026-04-25 21:51:05 +02:00

30 lines
1.0 KiB
C++

#pragma once
#include <cstddef>
#include <cstdint>
#include <vector>
namespace fn::gfx {
// CPU-side mesh: positions interleaved with normals stride 3 floats each,
// indexed by `indices`.
struct Mesh {
std::vector<float> positions; // x,y,z stride=3 (count = num_vertices*3)
std::vector<float> normals; // x,y,z stride=3 (same length as positions)
std::vector<uint32_t> indices; // tri-list (count multiple of 3)
};
// Parse Wavefront .obj from a text buffer. Pure: no I/O.
// Supports: v, vn, f (triangles and quads). Ignores: vt, mtllib, usemtl, o, g, s.
// If the file has no vn, normals are generated per-face (flat shading).
// Quads in `f` are split into 2 triangles (fan). N-gons (>4 verts) are not supported.
//
// Returns an empty Mesh ({}, {}, {}) on parse failure (no vertices found).
Mesh mesh_obj_parse(const char* obj_text, size_t len);
// Read file from disk and parse. IMPURE (file I/O).
// Returns empty Mesh on read or parse failure.
Mesh mesh_obj_load(const char* path);
} // namespace fn::gfx