|
Unravel Engine C++ Reference
|
Structure describing a LOD group (set of meshes), LOD transitions, and their materials. More...
#include <model.h>
Classes | |
| struct | submit_callbacks |
| Callbacks for submitting the model for rendering. More... | |
| struct | submit_vertex_pulling_callbacks |
| Callbacks for submitting the model using vertex-pulling rendering. More... | |
Public Types | |
| using | seconds_t = std::chrono::duration<float> |
Public Member Functions | |
| auto | is_valid () const -> bool |
| Checks if the model is valid. | |
| auto | get_lod (uint32_t lod) const -> asset_handle< mesh > |
| Gets the LOD (Level of Detail) mesh for the specified level. | |
| void | set_lod (asset_handle< mesh > mesh, uint32_t lod) |
| Sets the LOD (Level of Detail) mesh for the specified level. | |
| void | set_material (asset_handle< material > material, uint32_t index) |
| Sets the material for the specified index. | |
| void | set_material_instance (material::sptr material, uint32_t index) |
| auto | get_lods () const -> const std::vector< asset_handle< mesh > > & |
| Gets all the LOD meshes. | |
| auto | get_lods_count () const -> uint32_t |
| Gets the number of LOD levels available. If there is only one explicit mesh, returns the internal LOD count of that mesh. Otherwise, returns the number of mesh LODs. | |
| void | set_lods (const std::vector< asset_handle< mesh > > &lods) |
| Sets the LOD meshes. | |
| auto | get_materials () const -> const std::vector< asset_handle< material > > & |
| Gets all the materials. | |
| auto | get_material_instances () const -> const std::vector< material::sptr > & |
| void | set_materials (const std::vector< asset_handle< material > > &materials) |
| Sets the materials. | |
| void | set_material_instances (const std::vector< material::sptr > &materials) |
| auto | get_material (uint32_t index) const -> asset_handle< material > |
| Gets the material for the specified index. | |
| auto | get_material_instance (uint32_t index) const -> material::sptr |
| auto | get_or_emplace_material_instance (uint32_t index) -> material::sptr |
| auto | get_lod_override_enabled () const -> bool |
| Gets whether LOD override is enabled. | |
| void | set_lod_override_enabled (bool enabled) |
| Sets whether LOD override is enabled. | |
| auto | get_lod_override_level () const -> uint32_t |
| Gets the LOD override level. | |
| void | set_lod_override_level (uint32_t level) |
| Sets the LOD override level. | |
| auto | get_lod_selection_bias () const -> float |
| Gets the LOD selection bias. | |
| void | set_lod_selection_bias (float bias) |
| Sets the LOD selection bias. | |
| auto | get_lod_hysteresis () const -> float |
| Gets the LOD hysteresis factor used to prevent rapid LOD switching. | |
| void | set_lod_hysteresis (float hysteresis) |
| Sets the LOD hysteresis factor. | |
| auto | get_lod_transition_time () const -> seconds_t |
| Gets the LOD transition time in seconds. | |
| void | set_lod_transition_time (seconds_t time) |
| Sets the LOD transition time in seconds. | |
| auto | calculate_lod_data (lod_data &data, const math::bbox &world_bounds, const camera &cam, float dt) const -> bool |
| Calculates the LOD data for the model using distance-based hysteresis with time-based transitions. Hysteresis prevents rapid LOD switching; transitions smooth the actual switch when it occurs. Uses data.current_lod_index for hysteresis and updates target_lod_index when a switch is triggered. | |
| auto | calculate_submesh_lod (const mesh &m, uint32_t submesh_index, uint32_t base_lod, const math::mat4 &world_matrix, const camera &cam) const -> uint32_t |
| Selects a LOD for a specific submesh based on its own screen size. | |
| auto | calculate_submesh_lod_from_world_bounds (const mesh &m, uint32_t submesh_index, uint32_t base_lod, const math::bbox &world_bounds, const camera &cam) const -> uint32_t |
| Selects a LOD for a submesh from an already-known world-space AABB. | |
| auto | compute_lod_index (const math::bbox &world_bounds, const camera &cam, float extra_bias=0.0f) const -> uint32_t |
| Computes a LOD index for this model without hysteresis, transitions or visibility culling. | |
| auto | get_lod_screen_size_min () const -> float |
| Gets the minimum screen size used by the screen-radius-squared LOD and culling method. | |
| void | set_lod_screen_size_min (float value) |
| Sets the minimum screen size used by the screen-radius-squared LOD and culling method. | |
| auto | get_lod_auto_screen_size_power_base () const -> float |
| Gets the auto LOD screen size power base (used for generating a screen-size table). | |
| void | set_lod_auto_screen_size_power_base (float value) |
| Sets the auto LOD screen size power base (used for generating a screen-size table). | |
| auto | get_lod_screen_sizes () const -> const std::vector< float > & |
| Gets the per-LOD screen size table used by the screen-radius-squared method. | |
| void | set_lod_screen_sizes (const std::vector< float > &sizes) |
| Sets the per-LOD screen size table used by the screen-radius-squared method. | |
| void | recalulate_lod_screen_size_limits (uint32_t lod_count) |
| Recalculates the screen-size LOD thresholds for the provided LOD count. This is a separate mechanism from the percent-based LOD limits and is used by calculate_lod_data_screen_size. | |
| void | submit (const math::mat4 &world_transform, const submesh_pose_mat4 &submesh_transforms, const pose_mat4 &bone_transforms, const std::vector< pose_mat4 > &skinning_transforms, unsigned int lod, const submit_callbacks &callbacks, const math::frustum *frustum=nullptr, const camera *view=nullptr, const model_submit_extras &extras={}) const |
| Submits the model for rendering. | |
| void | submit_for_vertex_pulling (const math::mat4 &world_transform, const submesh_pose_mat4 &submesh_transforms, const std::vector< pose_mat4 > &skinning_transforms, unsigned int lod, const submit_vertex_pulling_callbacks &callbacks, const math::frustum *frustum=nullptr, const camera *view=nullptr, const model_submit_extras &extras={}) const |
| Submits the model using vertex-pulling rendering. | |
| void | submit_for_batching (batch_collector &collector, const math::mat4 &world_transform, const submesh_pose_mat4 &submesh_transforms, uint32_t lod_index, float lod_param=0.0f, const math::frustum *frustum=nullptr, const camera *view=nullptr, const model_submit_extras &extras={}) const |
| Collects this model into a batch collector for instanced rendering. | |
| auto | submit_for_shadow_batching_cascaded (std::vector< shadow_batch_collector > &collectors, uint8_t cascade_count, const math::mat4 &world_transform, const submesh_pose_mat4 &submesh_transforms, uint32_t lod_index, float lod_param, const math::frustum *frustums, bool nested_cascades, const model_submit_extras &extras={}) const -> bool |
| Collects shadow-map geometry into per-cascade shadow batch collectors. Batches by mesh/lod/submesh/cull and alpha-cutout state instead of material pointer. | |
Public Member Functions inherited from crtp_meta_type< model > | |
| virtual auto | get_meta_type () const -> entt::meta_type |
| auto | is () const -> bool |
| auto | is (const entt::meta_type &type) const -> bool |
| virtual auto | as_derived () -> entt::meta_any |
Static Public Member Functions | |
| static auto | default_material () -> asset_handle< material > & |
| Gets the default material. | |
| static auto | fallback_material () -> asset_handle< material > & |
| Gets the fallback material. | |
Static Public Member Functions inherited from crtp_meta_type< model > | |
| static auto | get_static_meta_type () -> entt::meta_type |
Structure describing a LOD group (set of meshes), LOD transitions, and their materials.
| using unravel::model::seconds_t = std::chrono::duration<float> |
| auto unravel::model::calculate_lod_data | ( | lod_data & | data, |
| const math::bbox & | world_bounds, | ||
| const camera & | cam, | ||
| float | dt ) const -> bool |
Calculates the LOD data for the model using distance-based hysteresis with time-based transitions. Hysteresis prevents rapid LOD switching; transitions smooth the actual switch when it occurs. Uses data.current_lod_index for hysteresis and updates target_lod_index when a switch is triggered.
Screen size is measured from the pose-aware world bounds (the same box culling uses - see model_component::get_world_bounds), so animated/root-motion models select LOD from where their geometry actually is, not from the bind-pose box at the entity transform.
| data | The LOD data to calculate and update. |
| world_bounds | Pose-aware world-space bounds of the model. |
| cam | The camera. |
| dt | Delta time for updating transition progress. |
| auto unravel::model::calculate_submesh_lod | ( | const mesh & | m, |
| uint32_t | submesh_index, | ||
| uint32_t | base_lod, | ||
| const math::mat4 & | world_matrix, | ||
| const camera & | cam ) const -> uint32_t |
Selects a LOD for a specific submesh based on its own screen size.
Used at submit time when per-submesh culling is active (multi-submesh meshes) and a view camera is available. Each submesh independently picks its LOD from its world- space bounding sphere so tiny/distant submeshes on a large model can drop to a cheaper LOD than the model-wide selection would.
The returned LOD is CLAMPED to be at least base_lod: per-submesh selection is only allowed to drop quality relative to the model-wide LOD, never raise it. This preserves the guarantee made by calculate_lod_data (with its hysteresis and dithered transitions) that the model-wide LOD is a quality floor.
Returns base_lod (i.e. "no change") when per-submesh LOD is not viable:
Must run on the graphics API thread.
| m | The mesh asset (must be the same one returned by get_lod for base_lod). |
| submesh_index | Index into m's submesh array at base_lod. |
| base_lod | Model-wide LOD (floor for the returned value). |
| world_matrix | World transform for this submesh instance. |
| cam | Camera whose position/projection drives the screen-size computation. |
| auto unravel::model::calculate_submesh_lod_from_world_bounds | ( | const mesh & | m, |
| uint32_t | submesh_index, | ||
| uint32_t | base_lod, | ||
| const math::bbox & | world_bounds, | ||
| const camera & | cam ) const -> uint32_t |
Selects a LOD for a submesh from an already-known world-space AABB.
Same semantics and guards as calculate_submesh_lod but skips the per-call world matrix decomposition by using cached world bounds (see submesh_render_proxies). Also usable for skinned submeshes whose animated bounds are tracked per frame.
| auto unravel::model::compute_lod_index | ( | const math::bbox & | world_bounds, |
| const camera & | cam, | ||
| float | extra_bias = 0.0f ) const -> uint32_t |
Computes a LOD index for this model without hysteresis, transitions or visibility culling.
Used by passes that need a distance-appropriate LOD but do not track per-camera LOD state (e.g. shadow rendering, which previously always used LOD 0).
| world_bounds | Pose-aware world-space bounds of the model (see model_component::get_world_bounds). |
| cam | Camera whose position drives the screen-size computation. |
| extra_bias | Additional LOD bias on top of the model's own selection bias (positive = coarser). |
|
static |
|
static |
| auto unravel::model::get_lod | ( | uint32_t | lod | ) | const -> asset_handle<mesh> |
| auto unravel::model::get_lod_auto_screen_size_power_base | ( | ) | const -> float |
| auto unravel::model::get_lod_hysteresis | ( | ) | const -> float |
| auto unravel::model::get_lod_override_enabled | ( | ) | const -> bool |
| auto unravel::model::get_lod_override_level | ( | ) | const -> uint32_t |
| auto unravel::model::get_lod_screen_size_min | ( | ) | const -> float |
| auto unravel::model::get_lod_screen_sizes | ( | ) | const -> const std::vector<float>& |
| auto unravel::model::get_lod_selection_bias | ( | ) | const -> float |
| auto unravel::model::get_lod_transition_time | ( | ) | const -> seconds_t |
| auto unravel::model::get_lods | ( | ) | const -> const std::vector<asset_handle<mesh>>& |
| auto unravel::model::get_lods_count | ( | ) | const -> uint32_t |
| auto unravel::model::get_material | ( | uint32_t | index | ) | const -> asset_handle<material> |
| auto unravel::model::get_material_instance | ( | uint32_t | index | ) | const -> material::sptr |
| auto unravel::model::get_material_instances | ( | ) | const -> const std::vector<material::sptr>& |
| auto unravel::model::get_materials | ( | ) | const -> const std::vector<asset_handle<material>>& |
| auto unravel::model::get_or_emplace_material_instance | ( | uint32_t | index | ) | -> material::sptr |
| auto unravel::model::is_valid | ( | ) | const -> bool |
| void unravel::model::recalulate_lod_screen_size_limits | ( | uint32_t | lod_count | ) |
| void unravel::model::set_lod | ( | asset_handle< mesh > | mesh, |
| uint32_t | lod ) |
| void unravel::model::set_lod_auto_screen_size_power_base | ( | float | value | ) |
| void unravel::model::set_lod_hysteresis | ( | float | hysteresis | ) |
| void unravel::model::set_lod_override_enabled | ( | bool | enabled | ) |
| void unravel::model::set_lod_override_level | ( | uint32_t | level | ) |
| void unravel::model::set_lod_screen_size_min | ( | float | value | ) |
| void unravel::model::set_lod_screen_sizes | ( | const std::vector< float > & | sizes | ) |
| void unravel::model::set_lod_selection_bias | ( | float | bias | ) |
| void unravel::model::set_lod_transition_time | ( | seconds_t | time | ) |
| void unravel::model::set_lods | ( | const std::vector< asset_handle< mesh > > & | lods | ) |
| void unravel::model::set_material | ( | asset_handle< material > | material, |
| uint32_t | index ) |
| void unravel::model::set_material_instance | ( | material::sptr | material, |
| uint32_t | index ) |
| void unravel::model::set_material_instances | ( | const std::vector< material::sptr > & | materials | ) |
| void unravel::model::set_materials | ( | const std::vector< asset_handle< material > > & | materials | ) |
| void unravel::model::submit | ( | const math::mat4 & | world_transform, |
| const submesh_pose_mat4 & | submesh_transforms, | ||
| const pose_mat4 & | bone_transforms, | ||
| const std::vector< pose_mat4 > & | skinning_transforms, | ||
| unsigned int | lod, | ||
| const submit_callbacks & | callbacks, | ||
| const math::frustum * | frustum = nullptr, | ||
| const camera * | view = nullptr, | ||
| const model_submit_extras & | extras = {} ) const |
Submits the model for rendering.
| world_transform | The world transform of the model. |
| submesh_transforms | The submesh transforms (many-to-many mapping). |
| bone_transforms | The bone transforms for skinned models. |
| skinning_transforms | The skinning matrices per submesh. |
| lod | The level of detail to render. |
| callbacks | The submit callbacks. |
| frustum | Optional view frustum for per-submesh culling on large meshes. |
| view | Optional camera enabling per-submesh LOD selection. When supplied together with frustum and the mesh has enough submeshes to warrant per-submesh work, distant submeshes may pick a cheaper LOD than lod via calculate_submesh_lod. Only affects non-skinned submeshes. |
| void unravel::model::submit_for_batching | ( | batch_collector & | collector, |
| const math::mat4 & | world_transform, | ||
| const submesh_pose_mat4 & | submesh_transforms, | ||
| uint32_t | lod_index, | ||
| float | lod_param = 0.0f, | ||
| const math::frustum * | frustum = nullptr, | ||
| const camera * | view = nullptr, | ||
| const model_submit_extras & | extras = {} ) const |
Collects this model into a batch collector for instanced rendering.
| collector | The batch collector to add this model to. |
| world_transform | The world transform of the model. |
| submesh_transforms | The submesh transforms (many-to-many mapping). |
| lod_index | The level of detail to use. |
| lod_param | The LOD transition parameter (for smooth LOD transitions). |
| frustum | Optional view frustum for per-submesh culling on large meshes. |
| view | Optional camera enabling per-submesh LOD selection. When supplied and the mesh has many submeshes, each submesh may be collected under a batch key with a per-submesh LOD >= lod_index. The batching layer already keys on LOD, so mixed-LOD submeshes for the same model land in the correct batches automatically. |
| auto unravel::model::submit_for_shadow_batching_cascaded | ( | std::vector< shadow_batch_collector > & | collectors, |
| uint8_t | cascade_count, | ||
| const math::mat4 & | world_transform, | ||
| const submesh_pose_mat4 & | submesh_transforms, | ||
| uint32_t | lod_index, | ||
| float | lod_param, | ||
| const math::frustum * | frustums, | ||
| bool | nested_cascades, | ||
| const model_submit_extras & | extras = {} ) const -> bool |
| void unravel::model::submit_for_vertex_pulling | ( | const math::mat4 & | world_transform, |
| const submesh_pose_mat4 & | submesh_transforms, | ||
| const std::vector< pose_mat4 > & | skinning_transforms, | ||
| unsigned int | lod, | ||
| const submit_vertex_pulling_callbacks & | callbacks, | ||
| const math::frustum * | frustum = nullptr, | ||
| const camera * | view = nullptr, | ||
| const model_submit_extras & | extras = {} ) const |
Submits the model using vertex-pulling rendering.
Mirrors submit but skips per-submesh material handling and bind_render_buffers calls, and instead exposes the raw vertex/index buffers as read-only compute buffers so the shader can procedurally generate vertices from gl_VertexID.
| world_transform | The world transform of the model. |
| submesh_transforms | The submesh transforms (many-to-many mapping). |
| skinning_transforms | The per-submesh skinning matrices. |
| lod | The level of detail to render. |
| callbacks | The vertex-pulling submit callbacks. |
| frustum | Optional view frustum for per-submesh culling on large meshes. |
| view | Optional camera enabling per-submesh LOD selection. Same semantics as submit. |