Files
fn_registry/cpp/functions/viz/mesh_viewer.md
T
egutierrez b557433388 feat(viz): mesh_viewer — componente 3D con FBO + Lambert headlight
Compila/cachea por id un programa GLSL (vertex+fragment) con
iluminacion Lambert (luz=camara), gestiona Framebuffer cacheado por
id, dibuja MeshGpu con orbit camera, muestra via ImGui::Image y
maneja drag (mouse) + wheel (zoom). Wireframe opcional via
glPolygonMode.

gl_loader: añade glUniformMatrix4fv (proc requerido en Windows para
subir las matrices view/proj del mesh_viewer).

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

2.3 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path, framework, emits, output
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports tested tests test_file_path file_path framework emits output
mesh_viewer component cpp viz 1.0.0 impure void mesh_viewer(const char* id, const MeshViewerConfig& cfg) Renderiza un MeshGpu (3D) en un FBO interno cacheado por id, con orbit camera, iluminacion Lambert headlight, opcion wireframe. Drag/wheel del mouse mueven la camara.
imgui
opengl
mesh
3d
viewer
viz
fbo
mesh_gpu_cpp_gfx
orbit_camera_cpp_core
gl_framebuffer_cpp_gfx
false error_go_core
imgui
GL/gl.h
false
cpp/functions/viz/mesh_viewer.cpp imgui
camera_drag
camera_zoom
Renderiza una imagen del mesh dentro del frame ImGui actual; muta cfg.cam in-place segun drag/wheel del mouse cuando el panel esta active/hovered.

mesh_viewer

Componente de viz para inspeccionar geometria 3D dentro de cualquier panel ImGui. Internamente:

  1. Compila/cachea (por id) un programa shader Lambert headlight (vertex + fragment).
  2. Cachea un Framebuffer por id y lo redimensiona segun cfg.size.
  3. Cada frame: bind FBO, draw cfg.mesh, mostrar la textura via ImGui::Image.
  4. Si el panel esta active → llama orbit_camera_handle_drag con MouseDelta.
  5. Si el panel esta hovered y hay scroll → ajusta zoom.

Ejemplo

static fn::core::OrbitCamera cam;
fn::viz::MeshViewerConfig cfg{};
cfg.mesh = &gpu;     // MeshGpu valido
cfg.cam  = &cam;
cfg.size = {-1, 480};
cfg.wireframe = false;
cfg.color = IM_COL32(160, 200, 255, 255);
fn::viz::mesh_viewer("##teapot_view", cfg);

Notas

  • Sin depth buffer: el FBO solo tiene attachment color (sigue el patron de gl_framebuffer). Para meshes complejos con auto-oclusion, esto produce artefactos. Issue futuro puede añadir depth/stencil renderbuffer.
  • Wireframe: usa glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) (no disponible en GL ES; protegido con #ifndef __EMSCRIPTEN__).
  • Cache por id: si el id cambia dinamicamente entre frames, se acumulan FBOs y programas en memoria (leak). Usar IDs estables.
  • Iluminacion: Lambert con luz fija en +Z view-space ("headlight"), suficiente para inspeccion. Sin specular, sin sombras.
  • Matrices: row-major desde orbit_camera_matrices; se suben con transpose=GL_TRUE (GL espera column-major).