Unravel Engine C++ Reference
Loading...
Searching...
No Matches
unravel::model_component Class Reference

Class that contains core data for meshes. More...

#include <model_component.h>

Inheritance diagram for unravel::model_component:
unravel::component_crtp< model_component, owned_component > unravel::owned_component unravel::basic_component

Public Member Functions

void set_enabled (bool enabled)
 Sets whether the model is enabled.
 
void set_casts_shadow (bool cast_shadow)
 Sets whether the model casts shadows.
 
void set_static (bool is_static)
 Sets whether the model is static.
 
auto is_enabled () const -> bool
 Checks if the model is enabled.
 
auto casts_shadow () const -> bool
 Checks if the model casts shadows.
 
auto is_static () const -> bool
 Checks if the model is static.
 
auto get_model () const -> const model &
 Gets the model.
 
void set_model (const model &model)
 Sets the model.
 
auto get_bone_transforms () const -> const pose_mat4 &
 Gets the bone transforms.
 
auto get_submesh_transforms () const -> const submesh_pose_mat4 &
 Gets the submesh transforms.
 
auto get_armature_entities () const -> const std::vector< entt::handle > &
 Gets the armature entities.
 
auto get_armature_by_index (size_t index) const -> entt::handle
 
auto get_armature_index_by_name_cached (const std::string &node_name) const -> int
 Gets armature index by name using cached lookup (O(1)).
 
auto get_skinning_transforms () const -> const std::vector< pose_mat4 > &
 
auto init_armature (bool force) -> bool
 Updates the armature of the model.
 
auto update_armature () -> bool
 Refreshes pose-derived render data: submesh/bone poses, cached world-space render-proxy bounds, material overrides and skinning palettes.
 
void mark_pose_dirty () noexcept
 Forces the next update_armature call to run a full refresh even when no armature transform is dirty (armature rebuilds, submesh entry settings edits).
 
void set_armature_entities (const std::vector< entt::handle > &submesh_entities)
 Sets the armature entities.
 
auto get_world_bounds () const -> const math::bbox &
 Gets the pose-aware world-space bounding box for this model.
 
auto get_world_bounds_transform () const -> const math::transform &
 
void update_world_bounds (const math::transform &world_transform)
 
auto get_local_bounds (uint32_t lod_index) const -> const math::bbox &
 Gets the bind-pose local bounding box of the mesh asset for a given LOD.
 
auto get_render_proxies () const -> const submesh_render_proxies &
 Retained render proxies: cached world-space per-submesh bounds (including animated bounds for skinned submeshes) refreshed alongside the pose data.
 
auto get_submesh_material_overrides () const -> const std::vector< material::sptr > &
 Per-submesh material overrides (indexed by submesh index; null = model material), resolved from the submesh_component entries on the armature node entities.
 
auto get_submit_extras (bool shadow_pass=false) const -> model_submit_extras
 Convenience: builds the submit extras referencing the retained proxy data.
 
void set_last_render_frame (uint64_t frame)
 
auto is_newly_created () const noexcept -> bool
 
auto get_last_render_frame () const noexcept -> uint64_t
 
auto was_used_last_frame () const noexcept -> bool
 
auto is_skinned () const -> bool
 
auto get_bind_pose () const -> const animation_pose &
 
auto get_armature_root_entity () const -> entt::handle
 Armature root entity (first node of the imported skeleton hierarchy).
 
auto get_facing_adjustment_rotation () const -> math::quat
 Local rotation of the armature root (used for root motion / IK remapping).
 
auto get_lod_data_for_camera (const camera *cam, uint64_t current_frame) -> lod_data &
 Gets the per-view LOD data for a specific camera/view. Creates a new entry if this is the first access from this view.
 
void cleanup_stale_lod_data (uint64_t current_frame, uint64_t max_frames_inactive=120)
 Cleans up stale per-view LOD data entries that haven't been accessed recently. Call this periodically (e.g., once per frame) to prevent unbounded growth.
 
- Public Member Functions inherited from unravel::owned_component
auto operator= (const owned_component &other) -> owned_component &=default
 
void set_owner (entt::handle owner)
 Sets the owner of the component.
 
auto get_owner () const noexcept -> entt::const_handle
 Gets the owner of the component.
 
auto get_owner () noexcept -> entt::handle
 Gets the owner of the component.
 
- Public Member Functions inherited from unravel::basic_component
void touch ()
 Marks the component as 'touched'.
 

Static Public Member Functions

static void on_create_component (entt::registry &r, entt::entity e)
 Called when the component is created.
 
static void on_destroy_component (entt::registry &r, entt::entity e)
 Called when the component is destroyed.
 
- Static Public Member Functions inherited from unravel::owned_component
template<typename T >
static void on_create_component (entt::registry &r, entt::entity e)
 
template<typename T >
static void on_destroy_component (entt::registry &r, entt::entity e)
 

Additional Inherited Members

- Public Types inherited from unravel::component_crtp< model_component, owned_component >
using base
 
- Public Attributes inherited from unravel::basic_component
bool eto {}
 Disable empty type optimizations.
 
- Static Public Attributes inherited from unravel::component_crtp< model_component, owned_component >
static constexpr bool in_place_delete
 Indicates if the component can be deleted in place.
 

Detailed Description

Class that contains core data for meshes.

Definition at line 15 of file model_component.h.

Member Function Documentation

◆ casts_shadow()

auto unravel::model_component::casts_shadow ( ) const -> bool

Checks if the model casts shadows.

Returns
True if the model casts shadows, false otherwise.

Definition at line 818 of file model_component.cpp.

◆ cleanup_stale_lod_data()

void unravel::model_component::cleanup_stale_lod_data ( uint64_t current_frame,
uint64_t max_frames_inactive = 120 )

Cleans up stale per-view LOD data entries that haven't been accessed recently. Call this periodically (e.g., once per frame) to prevent unbounded growth.

Parameters
current_frameCurrent render frame number.
max_frames_inactiveMaximum frames since last access before cleanup (default: 120 = ~2 seconds at 60fps).

Definition at line 975 of file model_component.cpp.

◆ get_armature_by_index()

auto unravel::model_component::get_armature_by_index ( size_t index) const -> entt::handle

Definition at line 948 of file model_component.cpp.

◆ get_armature_entities()

auto unravel::model_component::get_armature_entities ( ) const -> const std::vector<entt::handle>&

Gets the armature entities.

Returns
A constant reference to the vector of armature entity handles.

Definition at line 943 of file model_component.cpp.

◆ get_armature_index_by_name_cached()

auto unravel::model_component::get_armature_index_by_name_cached ( const std::string & node_name) const -> int

Gets armature index by name using cached lookup (O(1)).

Parameters
node_nameThe name of the node to find.
Returns
The index of the armature node, or -1 if not found.

Definition at line 933 of file model_component.cpp.

◆ get_armature_root_entity()

auto unravel::model_component::get_armature_root_entity ( ) const -> entt::handle

Armature root entity (first node of the imported skeleton hierarchy).

Definition at line 717 of file model_component.cpp.

◆ get_bind_pose()

auto unravel::model_component::get_bind_pose ( ) const -> const animation_pose&

Definition at line 712 of file model_component.cpp.

◆ get_bone_transforms()

auto unravel::model_component::get_bone_transforms ( ) const -> const pose_mat4&

Gets the bone transforms.

Returns
A constant reference to the vector of bone transforms.

Definition at line 847 of file model_component.cpp.

◆ get_facing_adjustment_rotation()

auto unravel::model_component::get_facing_adjustment_rotation ( ) const -> math::quat

Local rotation of the armature root (used for root motion / IK remapping).

Definition at line 748 of file model_component.cpp.

◆ get_last_render_frame()

auto unravel::model_component::get_last_render_frame ( ) const -> uint64_t
noexcept

Definition at line 677 of file model_component.cpp.

◆ get_local_bounds()

auto unravel::model_component::get_local_bounds ( uint32_t lod_index) const -> const math::bbox&

Gets the bind-pose local bounding box of the mesh asset for a given LOD.

NEVER use this for culling: it does not track node or bone animation. It is only meaningful for editor tooling (placement helpers, bounds gizmos).

Definition at line 655 of file model_component.cpp.

◆ get_lod_data_for_camera()

auto unravel::model_component::get_lod_data_for_camera ( const camera * cam,
uint64_t current_frame ) -> lod_data&

Gets the per-view LOD data for a specific camera/view. Creates a new entry if this is the first access from this view.

Parameters
view_idUnique identifier for the view (typically camera pointer as uintptr_t).
current_frameCurrent render frame number for tracking access.
Returns
Reference to the LOD data for this view.

Definition at line 958 of file model_component.cpp.

◆ get_model()

auto unravel::model_component::get_model ( ) const -> const model&

Gets the model.

Returns
A constant reference to the model.

Definition at line 828 of file model_component.cpp.

◆ get_render_proxies()

auto unravel::model_component::get_render_proxies ( ) const -> const submesh_render_proxies&

Retained render proxies: cached world-space per-submesh bounds (including animated bounds for skinned submeshes) refreshed alongside the pose data.

Definition at line 862 of file model_component.cpp.

◆ get_skinning_transforms()

auto unravel::model_component::get_skinning_transforms ( ) const -> const std::vector<pose_mat4>&

Definition at line 852 of file model_component.cpp.

◆ get_submesh_material_overrides()

auto unravel::model_component::get_submesh_material_overrides ( ) const -> const std::vector<material::sptr>&

Per-submesh material overrides (indexed by submesh index; null = model material), resolved from the submesh_component entries on the armature node entities.

Definition at line 867 of file model_component.cpp.

◆ get_submesh_transforms()

auto unravel::model_component::get_submesh_transforms ( ) const -> const submesh_pose_mat4&

Gets the submesh transforms.

Returns
A constant reference to the submesh pose structure.

Definition at line 857 of file model_component.cpp.

◆ get_submit_extras()

auto unravel::model_component::get_submit_extras ( bool shadow_pass = false) const -> model_submit_extras

Convenience: builds the submit extras referencing the retained proxy data.

Parameters
shadow_passTrue when the submit target is a shadow pass.

Definition at line 872 of file model_component.cpp.

◆ get_world_bounds()

auto unravel::model_component::get_world_bounds ( ) const -> const math::bbox&

Gets the pose-aware world-space bounding box for this model.

Static mesh bounds transformed to world space, unioned with the cached pose bounds (node-attached submesh placements and skinned geometry). Refreshed every frame by model_system::on_frame_before_render, before any render path runs. This is the ONLY box that is valid for culling.

Definition at line 645 of file model_component.cpp.

◆ get_world_bounds_transform()

auto unravel::model_component::get_world_bounds_transform ( ) const -> const math::transform&

Definition at line 650 of file model_component.cpp.

◆ init_armature()

auto unravel::model_component::init_armature ( bool force) -> bool

Updates the armature of the model.

Definition at line 504 of file model_component.cpp.

◆ is_enabled()

auto unravel::model_component::is_enabled ( ) const -> bool

Checks if the model is enabled.

Returns
True if the model is enabled, false otherwise.

Definition at line 813 of file model_component.cpp.

◆ is_newly_created()

auto unravel::model_component::is_newly_created ( ) const -> bool
noexcept

Definition at line 682 of file model_component.cpp.

◆ is_skinned()

auto unravel::model_component::is_skinned ( ) const -> bool

Definition at line 695 of file model_component.cpp.

◆ is_static()

auto unravel::model_component::is_static ( ) const -> bool

Checks if the model is static.

Returns
True if the model is static, false otherwise.

Definition at line 823 of file model_component.cpp.

◆ mark_pose_dirty()

void unravel::model_component::mark_pose_dirty ( )
noexcept

Forces the next update_armature call to run a full refresh even when no armature transform is dirty (armature rebuilds, submesh entry settings edits).

Definition at line 912 of file model_component.cpp.

◆ on_create_component()

void unravel::model_component::on_create_component ( entt::registry & r,
entt::entity e )
static

Called when the component is created.

Parameters
rThe registry containing the component.
eThe entity associated with the component.

Definition at line 763 of file model_component.cpp.

◆ on_destroy_component()

void unravel::model_component::on_destroy_component ( entt::registry & r,
entt::entity e )
static

Called when the component is destroyed.

Parameters
rThe registry containing the component.
eThe entity associated with the component.

Definition at line 773 of file model_component.cpp.

◆ set_armature_entities()

void unravel::model_component::set_armature_entities ( const std::vector< entt::handle > & submesh_entities)

Sets the armature entities.

Parameters
submesh_entitiesA vector of handles to the armature entities.

Definition at line 885 of file model_component.cpp.

◆ set_casts_shadow()

void unravel::model_component::set_casts_shadow ( bool cast_shadow)

Sets whether the model casts shadows.

Parameters
cast_shadowTrue if the model casts shadows, false otherwise.

Definition at line 789 of file model_component.cpp.

◆ set_enabled()

void unravel::model_component::set_enabled ( bool enabled)

Sets whether the model is enabled.

Parameters
enabledTrue if the model is enabled, false otherwise.

Definition at line 777 of file model_component.cpp.

◆ set_last_render_frame()

void unravel::model_component::set_last_render_frame ( uint64_t frame)

Definition at line 672 of file model_component.cpp.

◆ set_model()

void unravel::model_component::set_model ( const model & model)

Sets the model.

Parameters
modelThe model to set.

Definition at line 833 of file model_component.cpp.

◆ set_static()

void unravel::model_component::set_static ( bool is_static)

Sets whether the model is static.

Parameters
is_staticTrue if the model is static, false otherwise.

Definition at line 801 of file model_component.cpp.

◆ update_armature()

auto unravel::model_component::update_armature ( ) -> bool

Refreshes pose-derived render data: submesh/bone poses, cached world-space render-proxy bounds, material overrides and skinning palettes.

Two gates keep this cheap:

  • Visibility: models not consumed by any view (camera/shadow) recently skip both the dirty scan and the refresh entirely (O(1)). Whole-model culling stays valid because update_world_bounds switches to the conservative grow-only culling bounds anchored to the root bone, which never depend on fresh proxies. When those bounds enter a frustum the model is drawn conservatively (stale proxies withheld), which marks it used and un-gates the full refresh on the next frame - a wrong skip self-heals in one frame and can never permanently hide a model.
  • Change-driven: visible models early-out when no armature entity transform changed since the last refresh (transform_component::dirty_ids::model_pose bit-scan).
Returns
True when a refresh actually ran, false when skipped or no mesh is loaded.

Definition at line 381 of file model_component.cpp.

◆ update_world_bounds()

void unravel::model_component::update_world_bounds ( const math::transform & world_transform)

Definition at line 531 of file model_component.cpp.

◆ was_used_last_frame()

auto unravel::model_component::was_used_last_frame ( ) const -> bool
noexcept

Definition at line 687 of file model_component.cpp.


The documentation for this class was generated from the following files: