scimesh 0.3.4
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
scimesh::Scene Struct Reference

A collection of Mesh objects to be rendered together. More...

#include <scene.h>

Public Member Functions

void add (const Mesh &mesh, const Mat4 &transform=Mat4(1.0f), const std::string &name="")
 Add a mesh to the scene with an optional placement transform and name.
 
void set_transform (size_t index, const Mat4 &transform)
 Set the placement transform of the mesh at index.
 
void set_name (size_t index, const std::string &name)
 Set the name of the mesh at index.
 
const Mat4 & transform (size_t index) const
 The placement transform of the mesh at index (identity when unset).
 
const std::string & name (size_t index) const
 The name of the mesh at index (empty when unset).
 
size_t size () const
 Number of meshes in the scene.
 
bool empty () const
 Whether the scene holds no meshes.
 
SceneNodeRef node (size_t index) const
 A non-owning reference to the mesh at index (mesh + transform + name).
 
std::vector< SceneNodeRef > nodes () const
 Non-owning references to all meshes, in draw order.
 
void add_lines (const LineLayer &layer, const Mat4 &transform=Mat4(1.0f), const std::string &name="")
 Add a line layer to the scene with an optional placement transform and name.
 
void set_line_transform (size_t index, const Mat4 &transform)
 Set the placement transform of the line layer at index.
 
const Mat4 & line_transform (size_t index) const
 The placement transform of the line layer at index (identity when unset).
 
const std::string & line_name (size_t index) const
 The name of the line layer at index (empty when unset).
 
size_t line_count () const
 Number of line layers in the scene.
 
void set_line_affects_bounds (size_t index, bool affects_bounds)
 Set whether the line layer at index contributes to the scene bounds, see LineLayer::affects_bounds.
 
bool set_line_affects_bounds (const std::string &name, bool affects_bounds)
 Set whether the line layer called name contributes to the scene bounds, see LineLayer::affects_bounds.
 
bool line_affects_bounds (size_t index) const
 Whether the line layer at index contributes to the scene bounds.
 
LineNodeRef line_node (size_t index) const
 A non-owning reference to the line layer at index.
 
std::vector< LineNodeRef > line_nodes () const
 Non-owning references to all line layers, in draw order.
 
void add_texts (const TextLayer &layer, const Mat4 &transform=Mat4(1.0f), const std::string &name="")
 Add a text layer to the scene with an optional placement transform and name.
 
void set_text_transform (size_t index, const Mat4 &transform)
 Set the placement transform of the text layer at index.
 
const Mat4 & text_transform (size_t index) const
 The placement transform of the text layer at index (identity when unset).
 
const std::string & text_name (size_t index) const
 The name of the text layer at index (empty when unset).
 
size_t text_count () const
 Number of text layers in the scene.
 
TextNodeRef text_node (size_t index) const
 A non-owning reference to the text layer at index.
 
std::vector< TextNodeRef > text_nodes () const
 Non-owning references to all text layers, in draw order.
 
void compute_bounding_box (Vec3 &min_bound, Vec3 &max_bound) const
 Compute the combined axis-aligned bounding box of all meshes, after applying each mesh's placement transform.
 

Public Attributes

std::vector< Mesh > meshes
 The meshes in this scene, drawn in order.
 
std::vector< Mat4 > transforms
 Per-mesh placement transforms, parallel to meshes.
 
std::vector< std::string > names
 Optional per-mesh node names, parallel to meshes.
 
std::vector< LineLayer > lines
 Line layers drawn together with the meshes, after them.
 
std::vector< Mat4 > line_transforms
 Per-layer placement transforms, parallel to lines.
 
std::vector< std::string > line_names
 Optional per-layer names, parallel to lines.
 
std::vector< TextLayer > texts
 Text layers drawn together with the meshes, after them.
 
std::vector< Mat4 > text_transforms
 Per-layer placement transforms, parallel to texts.
 
std::vector< std::string > text_names
 Optional per-layer names, parallel to texts.
 

Detailed Description

A collection of Mesh objects to be rendered together.

A Scene is a list of meshes with optional per-mesh placement transforms and names. When rendered, meshes are drawn in order — later meshes appear on top of earlier ones. Each mesh's placement transform is applied as a model matrix at render time (meshes themselves are never modified).

Next to meshes a scene can hold two kinds of screen-oriented decorations, which create no geometry and are drawn after the meshes: LineLayer objects (see lines / add_lines()) and text labels (see texts / add_texts()). Line layers contribute to the bounding box of the scene (and thus to the camera fitted to it) unless their affects_bounds flag is set to false, because lines usually are the content of a figure; text labels are ignored by the bounding box, since their extent depends on the font and the output size. Both kinds are skipped by the mesh exporters.

Construction

scene.add(sphere); // identity transform
scene.add(cube, glm::translate(Mat4(1.0f), Vec3(2.0f, 0.0f, 0.0f)));
scene.add(arrow_mesh, glm::rotate(Mat4(1.0f), 0.5f, Vec3(0,1,0)), "arrow");
glm::mat4 Mat4
4×4 floating-point matrix.
Definition types.h:65
glm::vec3 Vec3
3-component floating-point vector (xyz).
Definition types.h:46
A collection of Mesh objects to be rendered together.
Definition scene.h:69
void add(const Mesh &mesh, const Mat4 &transform=Mat4(1.0f), const std::string &name="")
Add a mesh to the scene with an optional placement transform and name.
Definition scene.h:125
int x
Left edge of the bitmap, in image pixels.
Definition text.cpp:223

For convenience the raw meshes vector is still public and can be modified directly (e.g. scene.meshes.push_back(m)); any mesh without a matching transform is treated as identity.

Bounding box

The combined bounding box of all meshes (after their transforms) can be computed for camera framing:

scene.compute_bounding_box(bmin, bmax);
Camera camera_look_at(const Vec3 &center, float radius, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin, ProjectionType projection)
Create a camera that looks at a point from a given distance and direction.
Definition camera.cpp:71
A virtual camera that defines the viewpoint for rendering.
Definition camera.h:77
See also
Mesh, SceneNodeRef, Renderer::render_scene(), camera_fit_scene()

Definition at line 69 of file scene.h.

Member Function Documentation

◆ add()

void scimesh::Scene::add ( const Mesh &  mesh,
const Mat4 &  transform = Mat4(1.0f),
const std::string &  name = "" 
)
inline

Add a mesh to the scene with an optional placement transform and name.

The mesh's transparency flag is refreshed on the stored copy, so meshes whose colors (or default_color) have alpha < 1.0 are rendered translucently without any extra bookkeeping by the caller.

Parameters
meshThe mesh to add (copied into the scene).
transformModel matrix placing the mesh in world space (default: identity).
nameOptional node name (used by exporters / debugging).

Definition at line 125 of file scene.h.

◆ add_lines()

void scimesh::Scene::add_lines ( const LineLayer &  layer,
const Mat4 &  transform = Mat4(1.0f),
const std::string &  name = "" 
)
inline

Add a line layer to the scene with an optional placement transform and name.

Line layers are drawn after the meshes and use a screen-space width (see LineLayer). They do not contribute to the bounding box, so they never change the camera framing.

Parameters
layerThe line layer to add (copied into the scene).
transformModel matrix placing the lines in world space (default: identity).
nameOptional node name (used by exporters / debugging).

Definition at line 204 of file scene.h.

◆ add_texts()

void scimesh::Scene::add_texts ( const TextLayer &  layer,
const Mat4 &  transform = Mat4(1.0f),
const std::string &  name = "" 
)
inline

Add a text layer to the scene with an optional placement transform and name.

Text layers are drawn after the meshes and the line layers (see TextLayer). They do not contribute to the bounding box, so they never change the camera framing.

Parameters
layerThe text layer to add (copied into the scene).
transformModel matrix applied to the anchor positions of the layer (default: identity).
nameOptional node name (used for debugging).

Definition at line 306 of file scene.h.

◆ compute_bounding_box()

void scimesh::Scene::compute_bounding_box ( Vec3 &  min_bound,
Vec3 &  max_bound 
) const
inline

Compute the combined axis-aligned bounding box of all meshes, after applying each mesh's placement transform.

Iterates over all meshes, transforms the 8 corners of each mesh's bounding box, and computes the union. Empty meshes are skipped.

Parameters
[out]min_boundMinimum corner of the combined AABB.
[out]max_boundMaximum corner of the combined AABB.
See also
Mesh::compute_bounding_box()

Definition at line 371 of file scene.h.

◆ empty()

bool scimesh::Scene::empty ( ) const
inline

Whether the scene holds no meshes.

Definition at line 171 of file scene.h.

◆ line_affects_bounds()

bool scimesh::Scene::line_affects_bounds ( size_t  index) const
inline

Whether the line layer at index contributes to the scene bounds.

Returns
false when index is out of range.

Definition at line 269 of file scene.h.

◆ line_count()

size_t scimesh::Scene::line_count ( ) const
inline

Number of line layers in the scene.

Definition at line 238 of file scene.h.

◆ line_name()

const std::string & scimesh::Scene::line_name ( size_t  index) const
inline

The name of the line layer at index (empty when unset).

Definition at line 230 of file scene.h.

◆ line_node()

LineNodeRef scimesh::Scene::line_node ( size_t  index) const
inline

A non-owning reference to the line layer at index.

Precondition
index < lines.size()

Definition at line 278 of file scene.h.

◆ line_nodes()

std::vector< LineNodeRef > scimesh::Scene::line_nodes ( ) const
inline

Non-owning references to all line layers, in draw order.

Definition at line 287 of file scene.h.

◆ line_transform()

const Mat4 & scimesh::Scene::line_transform ( size_t  index) const
inline

The placement transform of the line layer at index (identity when unset).

Definition at line 222 of file scene.h.

◆ name()

const std::string & scimesh::Scene::name ( size_t  index) const
inline

The name of the mesh at index (empty when unset).

Definition at line 160 of file scene.h.

◆ node()

SceneNodeRef scimesh::Scene::node ( size_t  index) const
inline

A non-owning reference to the mesh at index (mesh + transform + name).

Precondition
index < meshes.size()

Definition at line 176 of file scene.h.

◆ nodes()

std::vector< SceneNodeRef > scimesh::Scene::nodes ( ) const
inline

Non-owning references to all meshes, in draw order.

Definition at line 185 of file scene.h.

◆ set_line_affects_bounds() [1/2]

bool scimesh::Scene::set_line_affects_bounds ( const std::string &  name,
bool  affects_bounds 
)
inline

Set whether the line layer called name contributes to the scene bounds, see LineLayer::affects_bounds.

The first layer with that name is updated, see line_name().

Returns
true if a layer with that name exists, false otherwise.

Definition at line 256 of file scene.h.

◆ set_line_affects_bounds() [2/2]

void scimesh::Scene::set_line_affects_bounds ( size_t  index,
bool  affects_bounds 
)
inline

Set whether the line layer at index contributes to the scene bounds, see LineLayer::affects_bounds.

Does nothing when index is out of range (like set_line_transform()).

Definition at line 244 of file scene.h.

◆ set_line_transform()

void scimesh::Scene::set_line_transform ( size_t  index,
const Mat4 &  transform 
)
inline

Set the placement transform of the line layer at index.

Definition at line 212 of file scene.h.

◆ set_name()

void scimesh::Scene::set_name ( size_t  index,
const std::string &  name 
)
inline

Set the name of the mesh at index.

Definition at line 143 of file scene.h.

◆ set_text_transform()

void scimesh::Scene::set_text_transform ( size_t  index,
const Mat4 &  transform 
)
inline

Set the placement transform of the text layer at index.

Definition at line 314 of file scene.h.

◆ set_transform()

void scimesh::Scene::set_transform ( size_t  index,
const Mat4 &  transform 
)
inline

Set the placement transform of the mesh at index.

Definition at line 134 of file scene.h.

◆ size()

size_t scimesh::Scene::size ( ) const
inline

Number of meshes in the scene.

Definition at line 168 of file scene.h.

◆ text_count()

size_t scimesh::Scene::text_count ( ) const
inline

Number of text layers in the scene.

Definition at line 340 of file scene.h.

◆ text_name()

const std::string & scimesh::Scene::text_name ( size_t  index) const
inline

The name of the text layer at index (empty when unset).

Definition at line 332 of file scene.h.

◆ text_node()

TextNodeRef scimesh::Scene::text_node ( size_t  index) const
inline

A non-owning reference to the text layer at index.

Precondition
index < texts.size()

Definition at line 345 of file scene.h.

◆ text_nodes()

std::vector< TextNodeRef > scimesh::Scene::text_nodes ( ) const
inline

Non-owning references to all text layers, in draw order.

Definition at line 354 of file scene.h.

◆ text_transform()

const Mat4 & scimesh::Scene::text_transform ( size_t  index) const
inline

The placement transform of the text layer at index (identity when unset).

Definition at line 324 of file scene.h.

◆ transform()

const Mat4 & scimesh::Scene::transform ( size_t  index) const
inline

The placement transform of the mesh at index (identity when unset).

Definition at line 152 of file scene.h.

Member Data Documentation

◆ line_names

std::vector<std::string> scimesh::Scene::line_names

Optional per-layer names, parallel to lines.

Definition at line 95 of file scene.h.

◆ line_transforms

std::vector<Mat4> scimesh::Scene::line_transforms

Per-layer placement transforms, parallel to lines.

May be shorter than lines; missing entries default to identity.

Definition at line 92 of file scene.h.

◆ lines

std::vector<LineLayer> scimesh::Scene::lines

Line layers drawn together with the meshes, after them.

Line layers use a screen-space width and create no geometry, see LineLayer. A layer contributes to compute_bounding_box() unless its affects_bounds flag is false, and all of them are skipped by the mesh exporters.

Definition at line 87 of file scene.h.

◆ meshes

std::vector<Mesh> scimesh::Scene::meshes

The meshes in this scene, drawn in order.

Definition at line 71 of file scene.h.

◆ names

std::vector<std::string> scimesh::Scene::names

Optional per-mesh node names, parallel to meshes.

Definition at line 79 of file scene.h.

◆ text_names

std::vector<std::string> scimesh::Scene::text_names

Optional per-layer names, parallel to texts.

Definition at line 113 of file scene.h.

◆ text_transforms

std::vector<Mat4> scimesh::Scene::text_transforms

Per-layer placement transforms, parallel to texts.

May be shorter than texts; missing entries default to identity. The transform is applied to the anchor positions and ignored for screen-space layers.

Definition at line 110 of file scene.h.

◆ texts

std::vector<TextLayer> scimesh::Scene::texts

Text layers drawn together with the meshes, after them.

Text layers hold strings with world-space or screen-space positions and are drawn as billboards (see TextLayer). Like line layers, they create no geometry and are ignored by compute_bounding_box() and by the mesh exporters, so adding labels never changes the camera framing.

Definition at line 103 of file scene.h.

◆ transforms

std::vector<Mat4> scimesh::Scene::transforms

Per-mesh placement transforms, parallel to meshes.

May be shorter than meshes; missing entries default to identity.

Definition at line 76 of file scene.h.


The documentation for this struct was generated from the following file: