Unravel Engine C++ Reference
|
Main class representing a 3D mesh with support for different LODs, submeshes, and skinning. More...
#include <mesh.h>
Classes | |
struct | adjacent_edge_key |
struct | armature_node |
struct | bone_combination_key |
struct | face_influences |
struct | info |
struct | load_data |
Struct used for mesh construction. More... | |
struct | mesh_submesh_key |
struct | optimizer_triangle_info |
struct | optimizer_vertex_info |
struct | preparation_data |
struct | submesh |
Structure describing an individual "piece" of the mesh, often grouped by material, but can be any arbitrary collection of triangles. More... | |
struct | triangle |
Structure describing data for a single triangle in the mesh. More... | |
struct | weld_key |
Public Types | |
using | triangle_array_t = std::vector<triangle> |
using | submesh_array_t = std::vector<submesh*> |
using | bone_palette_array_t = std::vector<bone_palette> |
using | submesh_array_indices_t = std::vector<size_t> |
using | submesh_array_map_t = std::map<uint32_t, submesh_array_indices_t> |
using | data_group_submesh_map_t = std::map<uint32_t, submesh_array_t> |
using | byte_array_t = std::vector<uint8_t> |
Public Member Functions | |
mesh () | |
Constructs a mesh object. | |
~mesh () | |
Destructor. | |
void | dispose () |
Clears out all the mesh data. | |
void | bind_render_buffers_for_submesh (const submesh *submesh) |
Binds the mesh data for rendering the selected batch of primitives. | |
auto | prepare_mesh (const gfx::vertex_layout &vertex_format) -> bool |
Prepares the mesh with the specified vertex format. | |
auto | set_vertex_source (void *source, uint32_t vertex_count, const gfx::vertex_layout &source_format) -> bool |
Sets the source of the vertex buffer to pull data from while preparing the mesh. | |
auto | set_vertex_source (byte_array_t &&source, uint32_t vertex_count, const gfx::vertex_layout &source_format) -> bool |
auto | set_bounding_box (const math::bbox &box) -> bool |
auto | set_submeshes (const std::vector< submesh > &submeshes) -> bool |
auto | set_primitives (triangle_array_t &&triangles) -> bool |
Adds primitives (triangles) to the mesh. | |
auto | bind_skin (const skin_bind_data &bind_data) -> bool |
Binds the mesh as a skin with the specified skin binding data. | |
auto | bind_armature (std::unique_ptr< armature_node > &root) -> bool |
Binds the armature tree. | |
auto | load_mesh (load_data &&data) -> bool |
auto | create_plane (const gfx::vertex_layout &format, float width, float height, uint32_t width_segments, uint32_t height_segments, mesh_create_origin origin, bool hardware_copy=true) -> bool |
Creates a plane geometry. | |
auto | create_cube (const gfx::vertex_layout &format, float width, float height, float depth, uint32_t width_segments, uint32_t height_segments, uint32_t depth_segments, mesh_create_origin origin, bool hardware_copy=true) -> bool |
Creates a cube geometry. | |
auto | create_rounded_cube (const gfx::vertex_layout &format, float width, float height, float depth, uint32_t width_segments, uint32_t height_segments, uint32_t depth_segments, mesh_create_origin origin, bool hardware_copy=true) -> bool |
auto | create_sphere (const gfx::vertex_layout &format, float radius, uint32_t stacks, uint32_t slices, mesh_create_origin origin, bool hardware_copy=true) -> bool |
Creates a sphere geometry. | |
auto | create_cylinder (const gfx::vertex_layout &format, float radius, float height, uint32_t stacks, uint32_t slices, mesh_create_origin origin, bool hardware_copy=true) -> bool |
Creates a cylinder geometry. | |
auto | create_capsule (const gfx::vertex_layout &format, float radius, float height, uint32_t stacks, uint32_t slices, mesh_create_origin origin, bool hardware_copy=true) -> bool |
Creates a capsule geometry. | |
auto | create_cone (const gfx::vertex_layout &format, float radius, float radius_tip, float height, uint32_t stacks, uint32_t slices, mesh_create_origin origin, bool hardware_copy=true) -> bool |
Creates a cone geometry. | |
auto | create_torus (const gfx::vertex_layout &format, float outer_radius, float inner_radius, uint32_t bands, uint32_t sides, mesh_create_origin origin, bool hardware_copy=true) -> bool |
Creates a torus geometry. | |
auto | create_teapot (const gfx::vertex_layout &format, bool hardware_copy=true) -> bool |
Creates a teapot geometry. | |
auto | create_icosahedron (const gfx::vertex_layout &format, bool hardware_copy=true) -> bool |
Creates an icosahedron geometry. | |
auto | create_dodecahedron (const gfx::vertex_layout &format, bool hardware_copy=true) -> bool |
Creates a dodecahedron geometry. | |
auto | create_icosphere (const gfx::vertex_layout &format, int tesselation_level, bool hardware_copy=true) -> bool |
Creates an icosphere geometry. | |
auto | end_prepare (bool hardware_copy=true, bool build_buffers=true, bool weld=false, bool optimize=false) -> bool |
Ends the preparation of the mesh and builds the render data. | |
void | build_vb (bool hardware_copy=true) |
Builds the internal vertex buffer. | |
void | build_ib (bool hardware_copy=true) |
Builds the internal index buffer. | |
auto | generate_adjacency (std::vector< uint32_t > &adjacency) -> bool |
Generates edge-triangle adjacency information for the mesh data. | |
auto | get_face_count () const -> uint32_t |
Determines the number of faces stored in the mesh. | |
auto | get_vertex_count () const -> uint32_t |
Determines the number of vertices stored in the mesh. | |
auto | get_system_vb () -> uint8_t * |
Retrieves the underlying vertex data from the mesh. | |
auto | get_system_ib () -> uint32_t * |
Retrieves the underlying index data from the mesh. | |
auto | get_vertex_format () const -> const gfx::vertex_layout & |
Retrieves the format of the underlying mesh vertex data. | |
auto | get_skin_bind_data () const -> const skin_bind_data & |
Retrieves the skin bind data if this mesh has been bound as a skin. | |
auto | get_bone_palettes () const -> const bone_palette_array_t & |
Retrieves the compiled bone combination palette data if this mesh has been bound as a skin. | |
auto | get_armature () const -> const std::unique_ptr< armature_node > & |
Retrieves the armature tree of the mesh. | |
auto | calculate_screen_rect (const math::transform &world, const camera &cam) const -> irect32_t |
Calculates the screen rectangle of the mesh based on its world transform and the camera. | |
auto | get_submeshes () const -> const submesh_array_t & |
Retrieves information about the submesh of the mesh associated with the specified data group identifier. | |
auto | get_submesh (uint32_t submesh_index=0) const -> const mesh::submesh & |
auto | get_bounds () const -> const math::bbox & |
Gets the local bounding box for this mesh. | |
auto | get_status () const -> mesh_status |
Gets the preparation status for this mesh. | |
auto | get_data_groups_count () const -> size_t |
Gets the number of data groups(materials) for this mesh. | |
auto | get_submeshes_count () const -> size_t |
Gets the number of submeshes for this mesh. | |
auto | get_skinned_submeshes_count () const -> size_t |
auto | get_skinned_submeshes_indices (uint32_t data_group_id) const -> const submesh_array_indices_t & |
auto | get_non_skinned_submeshes_count () const -> size_t |
auto | get_non_skinned_submeshes_indices (uint32_t data_group_id) const -> const submesh_array_indices_t & |
auto | get_submesh_index (const submesh *s) const -> int |
Protected Types | |
using | submesh_key_map_t = std::map<mesh_submesh_key, submesh*> |
using | submesh_key_array_t = std::vector<mesh_submesh_key> |
using | bone_combination_map_t = std::map<bone_combination_key, std::vector<uint32_t>*> |
Protected Member Functions | |
void | check_for_degenerates () |
auto | generate_vertex_components (bool weld) -> bool |
Generates any vertex components that may be missing, such as normals, tangents, or binormals. | |
auto | generate_vertex_normals (uint32_t *adjacency_ptr, std::vector< uint32_t > *remap_array_ptr=nullptr) -> bool |
Generates vertex normals for the mesh. | |
auto | generate_vertex_barycentrics (uint32_t *adjacency) -> bool |
Generates vertex barycentric coordinates for the mesh. | |
auto | generate_vertex_tangents () -> bool |
Generates vertex tangents for the mesh. | |
auto | weld_vertices (float tolerance=0.000001f, std::vector< uint32_t > *vertex_remap_ptr=nullptr) -> bool |
Welds the vertices together that can be combined. | |
auto | sort_mesh_data () -> bool |
Sorts the data in the mesh into material and data group order. | |
Static Protected Member Functions | |
static void | build_optimized_index_buffer (const submesh *submesh, uint32_t *source_buffer_ptr, uint32_t *destination_buffer_ptr, uint32_t minimum_vertex, uint32_t maximum_vertex) |
Calculates the best order for triangle data, optimizing for efficient use of the hardware vertex cache. | |
static auto | find_vertex_optimizer_score (const optimizer_vertex_info *vertex_info_ptr) -> float |
Generates scores used to identify important vertices when ordering triangle data. | |
Protected Attributes | |
bool | force_tangent_generation_ = false |
< Whether to force the generation of tangent space vectors. | |
bool | force_normal_generation_ = false |
Whether to force the generation of vertex barycentric coordinates. | |
bool | force_barycentric_generation_ = false |
Whether to disable the automatic re-sort operation. | |
bool | disable_final_sort_ = false |
The vertex data during data insertion and system memory copy. | |
uint8_t * | system_vb_ = nullptr |
The vertex format used for the mesh internal vertex data. | |
gfx::vertex_layout | vertex_format_ |
The final system memory copy of the index buffer. | |
uint32_t * | system_ib_ = nullptr |
Material and data group information for each triangle. | |
submesh_key_array_t | triangle_data_ |
The actual hardware vertex buffer resource. | |
std::shared_ptr< void > | hardware_vb_ |
The actual hardware index buffer resource. | |
std::shared_ptr< void > | hardware_ib_ |
The actual list of submeshes maintained by this mesh. | |
submesh_array_t | mesh_submeshes_ |
Indices in the subset array which are skinned. | |
submesh_array_map_t | skinned_submesh_indices_ |
size_t | skinned_submesh_count_ {} |
Indices in the subset array which are not skinned. | |
submesh_array_map_t | non_skinned_submesh_indices_ |
size_t | non_skinned_submesh_count_ {} |
Lookup information mapping data groups to submeshes batched by material. | |
data_group_submesh_map_t | data_groups_ |
Whether the mesh uses a hardware vertex/index buffer. | |
bool | hardware_mesh_ = true |
Whether the mesh was optimized when it was prepared. | |
bool | optimize_mesh_ = false |
Axis aligned bounding box describing object dimensions in object space. | |
math::bbox | bbox_ |
Total number of faces in the prepared mesh. | |
uint32_t | face_count_ = 0 |
Total number of vertices in the prepared mesh. | |
uint32_t | vertex_count_ = 0 |
Preparation status of the mesh. | |
mesh_status | prepare_status_ = mesh_status::not_prepared |
Input data used for constructing the final mesh. | |
preparation_data | preparation_data_ |
Data describing how the mesh should be bound as a skin with supplied bone matrices. | |
skin_bind_data | skin_bind_data_ |
List of unique combinations of bones to use during rendering. | |
bone_palette_array_t | bone_palettes_ |
List of armature nodes. | |
std::unique_ptr< armature_node > | root_ = nullptr |
Friends | |
auto | operator< (const adjacent_edge_key &key1, const adjacent_edge_key &key2) -> bool |
auto | operator< (const mesh_submesh_key &key1, const mesh_submesh_key &key2) -> bool |
auto | operator< (const weld_key &key1, const weld_key &key2) -> bool |
auto | operator< (const bone_combination_key &key1, const bone_combination_key &key2) -> bool |
Main class representing a 3D mesh with support for different LODs, submeshes, and skinning.
|
protected |
using unravel::mesh::bone_palette_array_t = std::vector<bone_palette> |
using unravel::mesh::byte_array_t = std::vector<uint8_t> |
using unravel::mesh::data_group_submesh_map_t = std::map<uint32_t, submesh_array_t> |
using unravel::mesh::submesh_array_indices_t = std::vector<size_t> |
using unravel::mesh::submesh_array_map_t = std::map<uint32_t, submesh_array_indices_t> |
using unravel::mesh::submesh_array_t = std::vector<submesh*> |
|
protected |
|
protected |
using unravel::mesh::triangle_array_t = std::vector<triangle> |
auto unravel::mesh::bind_armature | ( | std::unique_ptr< armature_node > & | root | ) | -> bool |
void unravel::mesh::bind_render_buffers_for_submesh | ( | const submesh * | submesh | ) |
auto unravel::mesh::bind_skin | ( | const skin_bind_data & | bind_data | ) | -> bool |
void unravel::mesh::build_ib | ( | bool | hardware_copy = true | ) |
|
staticprotected |
Calculates the best order for triangle data, optimizing for efficient use of the hardware vertex cache.
submesh | The submesh to optimize. |
source_buffer_ptr | Pointer to the source index buffer. |
destination_buffer_ptr | Pointer to the destination index buffer. |
minimum_vertex | The minimum vertex index. |
maximum_vertex | The maximum vertex index. |
void unravel::mesh::build_vb | ( | bool | hardware_copy = true | ) |
auto unravel::mesh::calculate_screen_rect | ( | const math::transform & | world, |
const camera & | cam ) const -> irect32_t |
auto unravel::mesh::create_capsule | ( | const gfx::vertex_layout & | format, |
float | radius, | ||
float | height, | ||
uint32_t | stacks, | ||
uint32_t | slices, | ||
mesh_create_origin | origin, | ||
bool | hardware_copy = true ) -> bool |
Creates a capsule geometry.
format | The vertex format. |
radius | The radius of the capsule. |
height | The height of the capsule. |
stacks | The number of stacks. |
slices | The number of slices. |
origin | The origin of the capsule. |
hardware_copy | Whether to use hardware copy. |
auto unravel::mesh::create_cone | ( | const gfx::vertex_layout & | format, |
float | radius, | ||
float | radius_tip, | ||
float | height, | ||
uint32_t | stacks, | ||
uint32_t | slices, | ||
mesh_create_origin | origin, | ||
bool | hardware_copy = true ) -> bool |
Creates a cone geometry.
format | The vertex format. |
radius | The base radius of the cone. |
radius_tip | The tip radius of the cone. |
height | The height of the cone. |
stacks | The number of stacks. |
slices | The number of slices. |
origin | The origin of the cone. |
hardware_copy | Whether to use hardware copy. |
auto unravel::mesh::create_cube | ( | const gfx::vertex_layout & | format, |
float | width, | ||
float | height, | ||
float | depth, | ||
uint32_t | width_segments, | ||
uint32_t | height_segments, | ||
uint32_t | depth_segments, | ||
mesh_create_origin | origin, | ||
bool | hardware_copy = true ) -> bool |
Creates a cube geometry.
format | The vertex format. |
width | The width of the cube. |
height | The height of the cube. |
depth | The depth of the cube. |
width_segments | The number of segments along the width. |
height_segments | The number of segments along the height. |
depth_segments | The number of segments along the depth. |
origin | The origin of the cube. |
hardware_copy | Whether to use hardware copy. |
auto unravel::mesh::create_cylinder | ( | const gfx::vertex_layout & | format, |
float | radius, | ||
float | height, | ||
uint32_t | stacks, | ||
uint32_t | slices, | ||
mesh_create_origin | origin, | ||
bool | hardware_copy = true ) -> bool |
Creates a cylinder geometry.
format | The vertex format. |
radius | The radius of the cylinder. |
height | The height of the cylinder. |
stacks | The number of stacks. |
slices | The number of slices. |
origin | The origin of the cylinder. |
hardware_copy | Whether to use hardware copy. |
auto unravel::mesh::create_dodecahedron | ( | const gfx::vertex_layout & | format, |
bool | hardware_copy = true ) -> bool |
auto unravel::mesh::create_icosahedron | ( | const gfx::vertex_layout & | format, |
bool | hardware_copy = true ) -> bool |
auto unravel::mesh::create_icosphere | ( | const gfx::vertex_layout & | format, |
int | tesselation_level, | ||
bool | hardware_copy = true ) -> bool |
auto unravel::mesh::create_plane | ( | const gfx::vertex_layout & | format, |
float | width, | ||
float | height, | ||
uint32_t | width_segments, | ||
uint32_t | height_segments, | ||
mesh_create_origin | origin, | ||
bool | hardware_copy = true ) -> bool |
Creates a plane geometry.
format | The vertex format. |
width | The width of the plane. |
height | The height of the plane. |
width_segments | The number of segments along the width. |
height_segments | The number of segments along the height. |
origin | The origin of the plane. |
hardware_copy | Whether to use hardware copy. |
auto unravel::mesh::create_rounded_cube | ( | const gfx::vertex_layout & | format, |
float | width, | ||
float | height, | ||
float | depth, | ||
uint32_t | width_segments, | ||
uint32_t | height_segments, | ||
uint32_t | depth_segments, | ||
mesh_create_origin | origin, | ||
bool | hardware_copy = true ) -> bool |
auto unravel::mesh::create_sphere | ( | const gfx::vertex_layout & | format, |
float | radius, | ||
uint32_t | stacks, | ||
uint32_t | slices, | ||
mesh_create_origin | origin, | ||
bool | hardware_copy = true ) -> bool |
Creates a sphere geometry.
format | The vertex format. |
radius | The radius of the sphere. |
stacks | The number of stacks. |
slices | The number of slices. |
origin | The origin of the sphere. |
hardware_copy | Whether to use hardware copy. |
auto unravel::mesh::create_teapot | ( | const gfx::vertex_layout & | format, |
bool | hardware_copy = true ) -> bool |
auto unravel::mesh::create_torus | ( | const gfx::vertex_layout & | format, |
float | outer_radius, | ||
float | inner_radius, | ||
uint32_t | bands, | ||
uint32_t | sides, | ||
mesh_create_origin | origin, | ||
bool | hardware_copy = true ) -> bool |
Creates a torus geometry.
format | The vertex format. |
outer_radius | The outer radius of the torus. |
inner_radius | The inner radius of the torus. |
bands | The number of bands. |
sides | The number of sides. |
origin | The origin of the torus. |
hardware_copy | Whether to use hardware copy. |
void unravel::mesh::dispose | ( | ) |
auto unravel::mesh::end_prepare | ( | bool | hardware_copy = true, |
bool | build_buffers = true, | ||
bool | weld = false, | ||
bool | optimize = false ) -> bool |
Ends the preparation of the mesh and builds the render data.
hardware_copy | Whether to use hardware copy. |
weld | Whether to weld vertices. |
optimize | Whether to optimize the mesh. |
build_buffers | Whether to build the render buffers. |
|
staticprotected |
auto unravel::mesh::generate_adjacency | ( | std::vector< uint32_t > & | adjacency | ) | -> bool |
|
protected |
|
protected |
|
protected |
Generates vertex normals for the mesh.
adjacency_ptr | Pointer to the adjacency information. |
remap_array_ptr | Pointer to the vertex remap array. |
|
protected |
auto unravel::mesh::get_armature | ( | ) | const -> const std::unique_ptr<armature_node>& |
auto unravel::mesh::get_bone_palettes | ( | ) | const -> const bone_palette_array_t& |
auto unravel::mesh::get_bounds | ( | ) | const -> const math::bbox& |
Gets the local bounding box for this mesh.
auto unravel::mesh::get_data_groups_count | ( | ) | const -> size_t |
auto unravel::mesh::get_face_count | ( | ) | const -> uint32_t |
auto unravel::mesh::get_non_skinned_submeshes_count | ( | ) | const -> size_t |
auto unravel::mesh::get_non_skinned_submeshes_indices | ( | uint32_t | data_group_id | ) | const -> const submesh_array_indices_t& |
auto unravel::mesh::get_skin_bind_data | ( | ) | const -> const skin_bind_data& |
Retrieves the skin bind data if this mesh has been bound as a skin.
auto unravel::mesh::get_skinned_submeshes_count | ( | ) | const -> size_t |
auto unravel::mesh::get_skinned_submeshes_indices | ( | uint32_t | data_group_id | ) | const -> const submesh_array_indices_t& |
auto unravel::mesh::get_status | ( | ) | const -> mesh_status |
auto unravel::mesh::get_submesh | ( | uint32_t | submesh_index = 0 | ) | const -> const mesh::submesh& |
auto unravel::mesh::get_submesh_index | ( | const submesh * | s | ) | const -> int |
auto unravel::mesh::get_submeshes | ( | ) | const -> const submesh_array_t& |
auto unravel::mesh::get_submeshes_count | ( | ) | const -> size_t |
auto unravel::mesh::get_system_ib | ( | ) | -> uint32_t* |
auto unravel::mesh::get_system_vb | ( | ) | -> uint8_t* |
auto unravel::mesh::get_vertex_count | ( | ) | const -> uint32_t |
auto unravel::mesh::get_vertex_format | ( | ) | const -> const gfx::vertex_layout& |
Retrieves the format of the underlying mesh vertex data.
auto unravel::mesh::prepare_mesh | ( | const gfx::vertex_layout & | vertex_format | ) | -> bool |
auto unravel::mesh::set_bounding_box | ( | const math::bbox & | box | ) | -> bool |
auto unravel::mesh::set_primitives | ( | triangle_array_t && | triangles | ) | -> bool |
auto unravel::mesh::set_submeshes | ( | const std::vector< submesh > & | submeshes | ) | -> bool |
auto unravel::mesh::set_vertex_source | ( | byte_array_t && | source, |
uint32_t | vertex_count, | ||
const gfx::vertex_layout & | source_format ) -> bool |
auto unravel::mesh::set_vertex_source | ( | void * | source, |
uint32_t | vertex_count, | ||
const gfx::vertex_layout & | source_format ) -> bool |
Sets the source of the vertex buffer to pull data from while preparing the mesh.
source | The source vertex data. |
vertex_count | The number of vertices. |
source_format | The format of the source vertex data. |
|
protected |
|
protected |
|
friend |
|
friend |
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |