scimesh 0.3.2
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 Mat4transform (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< SceneNodeRefnodes () const
 Non-owning references to all meshes, 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< Meshmeshes
 The meshes in this scene, drawn in order.
 
std::vector< Mat4transforms
 Per-mesh placement transforms, parallel to meshes.
 
std::vector< std::string > names
 Optional per-mesh node names, parallel to meshes.
 

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).

Construction

Scene scene;
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:57
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:75

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:

Vec3 bmin, bmax;
scene.compute_bounding_box(bmin, bmax);
Camera cam = camera_look_at((bmin+bmax)*0.5f, ...);
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:38
A virtual camera that defines the viewpoint for rendering.
Definition camera.h:77
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 tr...
Definition scene.h:152
See also
Mesh, SceneNodeRef, Renderer::render_scene(), camera_fit_scene()

Definition at line 57 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.

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 75 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 152 of file scene.h.

◆ empty()

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

Whether the scene holds no meshes.

Definition at line 120 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 109 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 125 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 134 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 92 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 83 of file scene.h.

◆ size()

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

Number of meshes in the scene.

Definition at line 117 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 101 of file scene.h.

Member Data Documentation

◆ meshes

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

The meshes in this scene, drawn in order.

Definition at line 59 of file scene.h.

◆ names

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

Optional per-mesh node names, parallel to meshes.

Definition at line 67 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 64 of file scene.h.


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