281502ac92
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
56 lines
2.3 KiB
Markdown
56 lines
2.3 KiB
Markdown
---
|
|
name: mesh_viewer
|
|
kind: component
|
|
lang: cpp
|
|
domain: viz
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "void mesh_viewer(const char* id, const MeshViewerConfig& cfg)"
|
|
description: "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."
|
|
tags: [imgui, opengl, mesh, 3d, viewer, viz, fbo]
|
|
uses_functions: [mesh_gpu_cpp_gfx, orbit_camera_cpp_core, gl_framebuffer_cpp_gfx]
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [imgui, GL/gl.h]
|
|
tested: false
|
|
tests: []
|
|
test_file_path: ""
|
|
file_path: "cpp/functions/viz/mesh_viewer.cpp"
|
|
framework: imgui
|
|
emits: ["camera_drag", "camera_zoom"]
|
|
output: "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
|
|
|
|
```cpp
|
|
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).
|