|
scimesh 0.3.4
Headless CPU-only 3D software renderer for scientific mesh visualization
|
A 3D triangle mesh using an indexed face set representation. More...
#include <mesh.h>

Public Member Functions | |
| bool | has_colors () const |
| Does the mesh have per-vertex colors? | |
| bool | has_face_colors () const |
| Does the mesh have per-face colors? | |
| bool | has_normals () const |
| Does the mesh have per-vertex normals? | |
| bool | has_uvs () const |
| Does the mesh have texture coordinates? | |
| bool | has_texture () const |
| Does the mesh have a texture image? | |
| bool | has_alpha () const |
| Do any of the mesh's colors have alpha < 1.0? | |
| bool | is_transparent () const |
| Does the mesh need the alpha-blending pass? | |
| void | update_transparency () |
Recompute has_transparency from the mesh's colors. | |
| bool | is_valid () const |
| Check whether the mesh is in a valid, renderable state. | |
| bool | empty () const |
| Is the mesh empty (no renderable geometry)? | |
| void | compute_bounding_box (Vec3 &min_bound, Vec3 &max_bound) const |
| Compute the axis-aligned bounding box (AABB) of the mesh. | |
Public Attributes | |
Required data | |
| std::vector< Vec3 > | vertices |
| 3D vertex positions. | |
| std::vector< Triangle > | triangles |
| Triangle index triplets. | |
Optional per-vertex data | |
| std::vector< Color > | colors |
| Per-vertex RGBA colors. | |
| std::vector< Color > | face_colors |
| Per-face RGBA colors. | |
| std::vector< Vec3 > | normals |
| Per-vertex surface normals (unit-length direction vectors). | |
| std::vector< Vec2 > | uvs |
| Per-vertex texture coordinates (UVs). | |
Optional texture | |
| Image | texture |
| An optional texture image mapped via UV coordinates. | |
Default appearance | |
| Color | default_color = DEFAULT_COLOR |
| Fallback color when no per-vertex or per-face color is set. | |
| bool | has_transparency = false |
| Whether the mesh contains any transparent fragments. | |
A 3D triangle mesh using an indexed face set representation.
The Mesh is the heart of scimesh. It holds:
The mesh uses an indexed face set. This means vertices are stored exactly once, and triangles store indices into the vertex array. This saves memory when vertices are shared by multiple triangles.
There is no special constructor — create an empty mesh and populate it:
Or use one of the generator functions:
Or load from a file:
Call is_valid() before rendering to detect common problems:
Compute the axis-aligned bounding box (AABB) of the mesh.
The bounding box is the smallest box aligned with the X, Y, and Z axes that contains all mesh vertices. Output is written to the two Vec3 reference parameters.
| [out] | min_bound | The corner with the smallest x, y, z values. |
| [out] | max_bound | The corner with the largest x, y, z values. |
|
inline |
Is the mesh empty (no renderable geometry)?
true if there are no vertices or no triangles.
|
inline |
Do any of the mesh's colors have alpha < 1.0?
Scans default_color, colors and face_colors. This is a plain query: it does not look at has_transparency.
true if at least one color is not fully opaque.
|
inline |
|
inline |
|
inline |
Does the mesh have per-vertex normals?
true if normals is not empty.
|
inline |
|
inline |
|
inline |
Does the mesh need the alpha-blending pass?
True when has_transparency is set manually, or when any color (or default_color) has alpha < 1.0. The renderer asks this instead of requiring you to keep has_transparency in sync, so per-vertex, per-face and uniform transparency all work out of the box.
true if the mesh contains translucent fragments.
|
inline |
Check whether the mesh is in a valid, renderable state.
This performs several checks:
vertices and triangles are non-empty.[0, vertices.size()).colors, face_colors, normals, uvs) are present, they must have the expected size (one element per vertex or per face, as appropriate).is_valid() to catch errors before rendering. A mesh that fails validation will either produce garbage output or crash the renderer.true if the mesh passes all checks.
|
inline |
Recompute has_transparency from the mesh's colors.
Sets the flag when has_alpha() reports translucent colors. It never clears the flag, so a manually requested blend pass survives.
| std::vector<Color> scimesh::Mesh::colors |
Per-vertex RGBA colors.
If non-empty, must have exactly vertices.size() elements. Used for vertex-colored rendering (interpolated across triangles).
| Color scimesh::Mesh::default_color = DEFAULT_COLOR |
Fallback color when no per-vertex or per-face color is set.
Defaults to DEFAULT_COLOR (neutral light gray). You can change this to give a mesh a uniform color without populating colors.
| std::vector<Color> scimesh::Mesh::face_colors |
Per-face RGBA colors.
If non-empty, must have exactly triangles.size() elements. Overrides per-vertex colors when present (flat shading by face).
Whether the mesh contains any transparent fragments.
You normally do not have to set this yourself: is_transparent() inspects default_color, colors and face_colors and is what the renderer uses, so a mesh whose colors have alpha < 1.0 renders translucent automatically (as do meshes loaded with such colors). Setting this to true forces the alpha-blending pass for a mesh that is not detected automatically (e.g. one whose transparency comes from an RGBA texture: the texture alpha is applied per fragment).
| std::vector<Vec3> scimesh::Mesh::normals |
Per-vertex surface normals (unit-length direction vectors).
If non-empty, must have exactly vertices.size() elements. Normals are used for lighting calculations (Blinn-Phong shading).
You can compute normals automatically with compute_vertex_normals().
| Image scimesh::Mesh::texture |
An optional texture image mapped via UV coordinates.
When set (width > 0), the rasterizer samples this image using the mesh's UV coordinates to color each pixel.
| std::vector<Triangle> scimesh::Mesh::triangles |
| std::vector<Vec2> scimesh::Mesh::uvs |
Per-vertex texture coordinates (UVs).
If non-empty, must have exactly vertices.size() elements.
UVs are image-space coordinates, following the same rule as every other coordinate in scimesh: u = 0 is the left edge of the texture image and v = 0 its top edge, so (0, 0) addresses the top-left pixel of the texture and (1, 1) the bottom-right one. That is exactly what Image::sample_bilinear() expects, so the renderer passes the UVs through unchanged.
Note that OBJ and PLY files, OpenGL, rgl and tools like Blender and MeshLab store UVs with the opposite convention (v = 0 at the bottom), so those coordinates have to be converted once after loading — either by calling flip_uvs() or by subtracting from 1 while copying them (as examples/cpp/spot_cow/ does).
Only used when a texture image is also set; the renderer samples it with bilinear interpolation and multiplies it with the vertex color.
| std::vector<Vec3> scimesh::Mesh::vertices |