NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches

Provides data structures and functions for managing essential components of a 3D model. More...

Classes

struct  nnl::SVertex
 Represents a simple vertex with a fixed set of attributes. More...
struct  nnl::STriangle
 Represents a triangle defined by three vertices. More...
struct  nnl::SMesh
 Represents a simple mesh. More...
struct  nnl::SBone
 Represents a bone/joint in a skeletal hierarchy of a 3D model. More...
struct  nnl::SSkeleton
 Represents the skeleton of a 3D model. More...
struct  nnl::SMaterial
 Represents a simple material with various properties for 3D rendering. More...
struct  nnl::SAttachment
 Represents a node attached to a bone. More...
struct  nnl::SModel
 Represents a simple model. More...

Enumerations

enum class  nnl::SBlendMode : u8 {
  nnl::SBlendMode::kOpaque = 0b00000 , nnl::SBlendMode::kAlpha = 0b00001 , nnl::SBlendMode::kClip = 0b00010 , nnl::SBlendMode::kAdd = 0b00100 ,
  nnl::SBlendMode::kSub = 0b01000
}
 Enumeration of blending modes for materials. More...
enum class  nnl::STextureProjection { nnl::STextureProjection::kUV = 0 , nnl::STextureProjection::kMatrix = 1 , nnl::STextureProjection::kEnvironment = 2 }
 Enumeration of projection modes for textures. More...

Variables

constexpr std::size_t nnl::kMaxNumBoneWeight = 8
 Maximum number of bone weights and indices in SVertex.

Detailed Description

Provides data structures and functions for managing essential components of a 3D model.

This file defines structures for the essential components of 3D models. These structures facilitate the conversion of 3D model data between various common exchange formats (such as FBX and glTF) and in-game formats.

See also
nnl::SModel
nnl::model::Model

Class Documentation

◆ nnl::SVertex

struct nnl::SVertex

Represents a simple vertex with a fixed set of attributes.

This structure encapsulates the essential attributes of a vertex. It is used for exporting and importing vertex data to and from common exchange formats. It can also be utilized for converting vertex data to vertex buffers supported by the GE.

Note
A right-handed coordinate system is used where the X-axis points to the right, the Y-axis points up, and the Z-axis points out of the screen.
See also
nnl::vertexde::Encode
nnl::vertexde::Decode
nnl::SMesh
nnl::SModel
nnl::model::Export
nnl::model::Import

Public Member Functions

void Transform (const glm::mat4 &transform)
 Transforms the vertex using a transformation matrix.
bool HasAlpha () const
 Checks if the alpha component of the vertex color is less than ~1.0.
bool IsApproxEqual (const SVertex &rhs) const
 Compares this vertex with another one for approximate equality.
void NormalizeWeights ()
 Normalizes the weights of the vertex so they add up to 1.0.
void QuantWeights (unsigned int steps=128)
 Quantizes the weights to the specified number of steps.
void SortWeights ()
 Sorts vertex weights by influence, placing the highest values first.
void LimitWeights (unsigned int max_weights=3)
 Limits the number of bones a vertex refers to by removing the least influential weights.
void ResetWeights ()
 Resets the vertex bone indices and weights to their default value.
void ResetNormals ()
 Resets the vertex normal to its default value.
void ResetUVs ()
 Resets the texture coordinates to the default value.
void ResetColors ()
 Resets the vertex color to its default value.

Public Attributes

glm::vec3 position {0.0f}
 The position of the vertex in 3D space.
glm::vec3 normal {0.0f, 1.0f, 0.0f}
 A vertex normal.
glm::vec2 uv {0.0f}
 Texture coordinates.
glm::vec4 color {1.0f, 1.0f, 1.0f, 1.0f}
 Vertex color (RGBA)
std::array< u16, kMaxNumBoneWeightbones {0}
 Bone indices.
std::array< float, kMaxNumBoneWeightweights {1.0f}

Friends

SVertex operator* (const glm::mat4 &transform, SVertex vertex)
 Multiplication operator for transforming the vertex by a matrix.

Member Function Documentation

◆ HasAlpha()

bool nnl::SVertex::HasAlpha ( ) const

Checks if the alpha component of the vertex color is less than ~1.0.

Returns
True if the vertex is transparent, false otherwise.

◆ IsApproxEqual()

bool nnl::SVertex::IsApproxEqual ( const SVertex & rhs) const

Compares this vertex with another one for approximate equality.

Parameters
rhsThe vertex to compare against.
Returns
True if the vertices are approximately equal, false otherwise.

◆ LimitWeights()

void nnl::SVertex::LimitWeights ( unsigned int max_weights = 3)

Limits the number of bones a vertex refers to by removing the least influential weights.

Parameters
max_weightsThe maximum number of weights to retain.

◆ NormalizeWeights()

void nnl::SVertex::NormalizeWeights ( )

Normalizes the weights of the vertex so they add up to 1.0.

◆ QuantWeights()

void nnl::SVertex::QuantWeights ( unsigned int steps = 128)

Quantizes the weights to the specified number of steps.

Parameters
stepsThe number of quantization steps (default is 128).

◆ ResetColors()

void nnl::SVertex::ResetColors ( )

Resets the vertex color to its default value.

◆ ResetNormals()

void nnl::SVertex::ResetNormals ( )

Resets the vertex normal to its default value.

◆ ResetUVs()

void nnl::SVertex::ResetUVs ( )

Resets the texture coordinates to the default value.

◆ ResetWeights()

void nnl::SVertex::ResetWeights ( )

Resets the vertex bone indices and weights to their default value.

◆ SortWeights()

void nnl::SVertex::SortWeights ( )

Sorts vertex weights by influence, placing the highest values first.

◆ Transform()

void nnl::SVertex::Transform ( const glm::mat4 & transform)

Transforms the vertex using a transformation matrix.

This method applies the specified transformation matrix to positions and normals.

Parameters
transformThe transformation matrix to apply to the vertex.

◆ operator*

SVertex operator* ( const glm::mat4 & transform,
SVertex vertex )
friend

Multiplication operator for transforming the vertex by a matrix.

This operator allows for the correct transformation of a vertex's position and normal vector using a 4x4 SRT matrix.

Parameters
transformThe transformation matrix.
vertexThe vertex to transform.
Returns
The transformed vertex.

Member Data Documentation

◆ bones

std::array<u16, kMaxNumBoneWeight> nnl::SVertex::bones {0}

Bone indices.

◆ color

glm::vec4 nnl::SVertex::color {1.0f, 1.0f, 1.0f, 1.0f}

Vertex color (RGBA)

◆ normal

glm::vec3 nnl::SVertex::normal {0.0f, 1.0f, 0.0f}

A vertex normal.

◆ position

glm::vec3 nnl::SVertex::position {0.0f}

The position of the vertex in 3D space.

◆ uv

glm::vec2 nnl::SVertex::uv {0.0f}

Texture coordinates.

◆ weights

std::array<float, kMaxNumBoneWeight> nnl::SVertex::weights {1.0f}

Bone weights. This array must contain at least 1 positive weight.

◆ nnl::STriangle

struct nnl::STriangle

Represents a triangle defined by three vertices.

This structure represents a basic triangle defined by three vertices. Its purpose is to simplify the conversion process between various triangle formats such as triangle lists, strips, or fans.

Public Member Functions

const SVertexoperator[] (std::size_t index) const
 Accesses a vertex of the triangle by index.
SVertexoperator[] (std::size_t index)
 Accesses a vertex of the triangle by index.
bool IsDegenerate () const
 Checks if the triangle has no area.
void ReverseWindingOrder ()
 Changes the winding order of the triangle.

Public Attributes

std::array< SVertex, 3 > vertices
 The vertices that define the triangle.

Member Function Documentation

◆ IsDegenerate()

bool nnl::STriangle::IsDegenerate ( ) const

Checks if the triangle has no area.

A triangle is considered degenerate by this function if its area is equal to 0.

Returns
True if the area of the triangle is zero.

◆ operator[]() [1/2]

SVertex & nnl::STriangle::operator[] ( std::size_t index)

Accesses a vertex of the triangle by index.

Parameters
indexThe index of the vertex to access (0, 1, or 2).
Returns
A reference to the specified vertex.

◆ operator[]() [2/2]

const SVertex & nnl::STriangle::operator[] ( std::size_t index) const

Accesses a vertex of the triangle by index.

Parameters
indexThe index of the vertex to access (0, 1, or 2).
Returns
A constant reference to the specified vertex.

◆ ReverseWindingOrder()

void nnl::STriangle::ReverseWindingOrder ( )

Changes the winding order of the triangle.

Member Data Documentation

◆ vertices

std::array<SVertex, 3> nnl::STriangle::vertices

The vertices that define the triangle.

◆ nnl::SMesh

struct nnl::SMesh

Represents a simple mesh.

This structure defines a simple mesh representation. It acts as an intermediary between common exchange formats (such as glTF and FBX), and in-game formats.

Note
All vertices must include at least 1 weight since it's essentially required by the game's model format.
See also
nnl::model::Mesh
nnl::model::Convert

Public Member Functions

void Join (const SMesh &smesh)
 Joins another mesh into this mesh.
glm::vec3 CalculateCenter () const
 Finds the center of the mesh.
void ReverseWindingOrder ()
 Reverses the winding order of the mesh's triangles.
void Transform (const glm::mat4 &transform)
 Transforms the mesh using a transformation matrix.
void TransformUV (const glm::mat3 &transform)
 Transforms the UV coordinates of the mesh using a transformation matrix.
void RemoveDuplicateVertices ()
 Removes duplicate vertices from the mesh.
void GenerateSmoothNormals ()
 Generates smooth normals for the mesh.
void GenerateFlatNormals ()
 Generates flat normals for the mesh.
std::pair< glm::vec3, glm::vec3 > FindMinMax () const
 Finds the minimum and maximum points of the mesh.
std::pair< glm::vec2, glm::vec2 > FindMinMaxUV () const
 Finds the minimum and maximum UV coordinates of the mesh.
bool IsAffectedByFewBones () const
 Checks if the mesh is influenced by at least 2 bones.
bool HasAlphaVertex () const
 Checks if the mesh has any transparent vertex colors.
void NormalizeWeights ()
 Normalizes the weights of the vertices.
void NormalizeNormals ()
 Normalizes the normals of the vertices.
void QuantWeights (unsigned int steps=128)
 Quantizes the vertex weights to a specified number of steps.
void SortWeights ()
 Sorts vertex weights by influence, placing the highest values first.
void LimitWeightsPerVertex (unsigned int max_weights=3)
 Limits the number of weights per vertex.
void LimitWeightsPerTriangle (unsigned int max_weights=8)
 Limits the number of unique bone influences per triangle.
void ResetWeights ()
 Removes all weights.
void ResetNormals ()
 Resets all vertex normals to the default value.
void ResetUVs ()
 Resets all texture coordinates to the default value.
void ResetColors ()
 Resets all vertex colors to the default value.

Static Public Member Functions

static SMesh FromTriangles (const std::vector< STriangle > &triangles)
 Creates a mesh from a triangle list.
static std::pair< std::vector< u32 >, std::vector< SVertex > > RemoveDuplicateVertices (const std::vector< u32 > &indices, const std::vector< SVertex > &vertices)
 Removes duplicate or unused vertices from the vertex data.

Public Attributes

std::string name
 An optional name for the mesh.
std::vector< u32indices
 The vertex indices that define the triangles.
std::vector< SVertexvertices
 The vertex data for the mesh.
std::size_t material_id = 0
 The ID of the material associated with the mesh.
std::map< std::size_t, std::vector< std::size_t > > material_variants
std::size_t mesh_group = 0
bool uses_uv = false
 Indicates whether the mesh uses texture coordinates.
bool uses_normal = false
 Indicates whether the mesh uses vertex normals.
bool uses_color = false
 Indicates whether the mesh uses vertex colors.
SValue extras
 Any additional data for custom use.

Member Function Documentation

◆ CalculateCenter()

glm::vec3 nnl::SMesh::CalculateCenter ( ) const

Finds the center of the mesh.

This method calculates the center point of the mesh by averaging the positions of all vertices.

Returns
A glm::vec3 representing the center of the mesh.

◆ FindMinMax()

std::pair< glm::vec3, glm::vec3 > nnl::SMesh::FindMinMax ( ) const

Finds the minimum and maximum points of the mesh.

This method calculates the minimum and maximum xyz coordinates of the vertices in the mesh.

Returns
A pair of glm::vec3 representing the minimum and maximum xyz points.

◆ FindMinMaxUV()

std::pair< glm::vec2, glm::vec2 > nnl::SMesh::FindMinMaxUV ( ) const

Finds the minimum and maximum UV coordinates of the mesh.

This method calculates the minimum and maximum UV coordinates of the vertices in the mesh.

Returns
A pair of glm::vec2 representing the minimum and maximum UV coordinates of the mesh.

◆ FromTriangles()

SMesh nnl::SMesh::FromTriangles ( const std::vector< STriangle > & triangles)
staticnodiscard

Creates a mesh from a triangle list.

Parameters
trianglesThe triangles to construct the mesh from.

◆ GenerateFlatNormals()

void nnl::SMesh::GenerateFlatNormals ( )

Generates flat normals for the mesh.

This method calculates flat normals and duplicates vertex data to achieve faceted appearance. It also sets uses_normal to true.

◆ GenerateSmoothNormals()

void nnl::SMesh::GenerateSmoothNormals ( )

Generates smooth normals for the mesh.

This method calculates smooth normals for smooth shading. It also sets uses_normal to true.

◆ HasAlphaVertex()

bool nnl::SMesh::HasAlphaVertex ( ) const

Checks if the mesh has any transparent vertex colors.

Returns
True if the mesh is transparent.

◆ IsAffectedByFewBones()

bool nnl::SMesh::IsAffectedByFewBones ( ) const

Checks if the mesh is influenced by at least 2 bones.

Returns
True if the mesh is affected by at least 2 bones.

◆ Join()

void nnl::SMesh::Join ( const SMesh & smesh)

Joins another mesh into this mesh.

This method combines the vertex and index data of the provided mesh with this mesh.

Parameters
smeshThe mesh to join with this mesh.

◆ LimitWeightsPerTriangle()

void nnl::SMesh::LimitWeightsPerTriangle ( unsigned int max_weights = 8)

Limits the number of unique bone influences per triangle.

This method restricts the number of unique bones that influence vertices of a triangle to a specified maximum. This may be useful for further conversion of vertices to vertex buffers used by the GE.

Parameters
max_weightsThe maximum number of weights per triangle.
See also
nnl::model::kMaxNumBonePerPrim

◆ LimitWeightsPerVertex()

void nnl::SMesh::LimitWeightsPerVertex ( unsigned int max_weights = 3)

Limits the number of weights per vertex.

This method restricts the number of bone weights that can influence each vertex to a specified maximum. This may be useful for further conversion of vertices to vertex buffers used by the GE.

Parameters
max_weightsThe maximum number of weights per vertex.
See also
nnl::model::kMaxNumBonePerPrim

◆ NormalizeNormals()

void nnl::SMesh::NormalizeNormals ( )

Normalizes the normals of the vertices.

This method adjusts the vertex normals so that their length is 1.0f.

◆ NormalizeWeights()

void nnl::SMesh::NormalizeWeights ( )

Normalizes the weights of the vertices.

This method adjusts the vertex weights so that they sum to 1.0f.

◆ QuantWeights()

void nnl::SMesh::QuantWeights ( unsigned int steps = 128)

Quantizes the vertex weights to a specified number of steps.

This method reduces the precision of the vertex weights by quantizing them to a specified number of discrete steps, making sure they still add up to 1.0. This may be used for further conversion of weights to fixed-point integers.

Parameters
stepsThe number of quantization steps.

◆ RemoveDuplicateVertices() [1/2]

void nnl::SMesh::RemoveDuplicateVertices ( )

Removes duplicate vertices from the mesh.

This method removes duplicate vertices and updates the indices.

Note
Vertices are considered duplicates if their attributes are nearly identical.

◆ RemoveDuplicateVertices() [2/2]

std::pair< std::vector< u32 >, std::vector< SVertex > > nnl::SMesh::RemoveDuplicateVertices ( const std::vector< u32 > & indices,
const std::vector< SVertex > & vertices )
static

Removes duplicate or unused vertices from the vertex data.

Parameters
indicesA vector of indices referencing the vertices.
verticesA vector of vertices.
Returns
A pair containing the unique vertices and updated indices.
Note
Vertices are considered duplicates if their attributes are nearly identical.

◆ ResetColors()

void nnl::SMesh::ResetColors ( )

Resets all vertex colors to the default value.

◆ ResetNormals()

void nnl::SMesh::ResetNormals ( )

Resets all vertex normals to the default value.

◆ ResetUVs()

void nnl::SMesh::ResetUVs ( )

Resets all texture coordinates to the default value.

◆ ResetWeights()

void nnl::SMesh::ResetWeights ( )

Removes all weights.

◆ ReverseWindingOrder()

void nnl::SMesh::ReverseWindingOrder ( )

Reverses the winding order of the mesh's triangles.

This method changes the order of the vertices in each triangle, which affects the front-facing direction for rendering.

◆ SortWeights()

void nnl::SMesh::SortWeights ( )

Sorts vertex weights by influence, placing the highest values first.

◆ Transform()

void nnl::SMesh::Transform ( const glm::mat4 & transform)

Transforms the mesh using a transformation matrix.

This method applies the specified transformation matrix to all vertices in the mesh, modifying their positions and normals.

Parameters
transformThe transformation matrix to apply to the mesh.

◆ TransformUV()

void nnl::SMesh::TransformUV ( const glm::mat3 & transform)

Transforms the UV coordinates of the mesh using a transformation matrix.

This method applies the specified SRT matrix to the UV coordinates of all vertices in the mesh.

Parameters
transformThe transformation matrix to apply.

Member Data Documentation

◆ extras

SValue nnl::SMesh::extras

Any additional data for custom use.

◆ indices

std::vector<u32> nnl::SMesh::indices

The vertex indices that define the triangles.

◆ material_id

std::size_t nnl::SMesh::material_id = 0

The ID of the material associated with the mesh.

◆ material_variants

std::map<std::size_t, std::vector<std::size_t> > nnl::SMesh::material_variants

This map associates replacement material IDs with the variants they are used in.

See also
nnl::SModel::material_variants
nnl::model::TextureSwap

◆ mesh_group

std::size_t nnl::SMesh::mesh_group = 0

Indicates the group to which this mesh belongs. It may be used for organizing meshes or animating their visibility.

◆ name

std::string nnl::SMesh::name

An optional name for the mesh.

◆ uses_color

bool nnl::SMesh::uses_color = false

Indicates whether the mesh uses vertex colors.

◆ uses_normal

bool nnl::SMesh::uses_normal = false

Indicates whether the mesh uses vertex normals.

◆ uses_uv

bool nnl::SMesh::uses_uv = false

Indicates whether the mesh uses texture coordinates.

◆ vertices

std::vector<SVertex> nnl::SMesh::vertices

The vertex data for the mesh.

◆ nnl::SBone

struct nnl::SBone

Represents a bone/joint in a skeletal hierarchy of a 3D model.

This structure represents a bone and its children within a skeletal hierarchy, with their transformations defined in relation to their parent bones.

See also
nnl::SSkeleton

Public Member Functions

glm::mat4 GetTransform () const
 Calculates the local transformation matrix of the bone from the SRT properties.
void SetTransform (const glm::mat4 &transform)
 Sets the local SRT properties of the bone.

Public Attributes

std::string name
 An optional name for the bone.
glm::vec3 scale {1.0f, 1.0f, 1.0f}
 The local scale of the bone.
glm::quat rotation {1.0f, 0.0f, 0.0f, 0.0f}
 The local rotation of the bone.
glm::vec3 translation {0.0f, 0.0f, 0.0f}
 The local translation of the bone.
glm::mat4 inverse {1.0f}
 The inverse bind matrix of the bone.
std::vector< SBonechildren
 The children of this bone.

Member Function Documentation

◆ GetTransform()

glm::mat4 nnl::SBone::GetTransform ( ) const

Calculates the local transformation matrix of the bone from the SRT properties.

Returns
The local transformation matrix.

◆ SetTransform()

void nnl::SBone::SetTransform ( const glm::mat4 & transform)

Sets the local SRT properties of the bone.

This method decomposes the matrix and sets the local SRT properties.

Parameters
transformThe local transformation matrix.
Note
The matrix must be decomposable and invertible.

Member Data Documentation

◆ children

std::vector<SBone> nnl::SBone::children

The children of this bone.

◆ inverse

glm::mat4 nnl::SBone::inverse {1.0f}

The inverse bind matrix of the bone.

◆ name

std::string nnl::SBone::name

An optional name for the bone.

◆ rotation

glm::quat nnl::SBone::rotation {1.0f, 0.0f, 0.0f, 0.0f}

The local rotation of the bone.

◆ scale

glm::vec3 nnl::SBone::scale {1.0f, 1.0f, 1.0f}

The local scale of the bone.

◆ translation

glm::vec3 nnl::SBone::translation {0.0f, 0.0f, 0.0f}

The local translation of the bone.

◆ nnl::SSkeleton

struct nnl::SSkeleton

Represents the skeleton of a 3D model.

Note
The skeleton should contain at least 1 root bone.

Public Member Functions

std::vector< glm::mat4 > GetGlobalMatrices () const
 Retrieves the global matrices.
std::vector< glm::mat4 > GetSkinningMatrices () const
 Retrieves the skinning matrices for transforming vertices in model space.
void UpdateInverseMatrices ()
 Updates the inverse matrices from local bone transformations.
std::vector< std::reference_wrapper< const SBone > > GetBoneRefs () const
 Retrieves a flat array of references to the bones of the skeleton.
std::vector< std::reference_wrapper< SBone > > GetBoneRefs ()
 Retrieves a flat array of references to the bones of the skeleton.

Public Attributes

std::vector< SBoneroots

Member Function Documentation

◆ GetBoneRefs() [1/2]

std::vector< std::reference_wrapper< SBone > > nnl::SSkeleton::GetBoneRefs ( )

Retrieves a flat array of references to the bones of the skeleton.

This function traverses the bone hierarchy using pre-order traversal and collects references to each bone.

Returns
A vector of std::reference_wrapper<const SBone>.

◆ GetBoneRefs() [2/2]

std::vector< std::reference_wrapper< const SBone > > nnl::SSkeleton::GetBoneRefs ( ) const

Retrieves a flat array of references to the bones of the skeleton.

This function traverses the bone hierarchy using pre-order traversal and collects references to each bone.

Returns
A vector of std::reference_wrapper<const SBone>.

◆ GetGlobalMatrices()

std::vector< glm::mat4 > nnl::SSkeleton::GetGlobalMatrices ( ) const

Retrieves the global matrices.

This function computes accumulated transformations for each bone at their location in the hierarchy.

Returns
A vector of glm::mat4 representing the global transformations.

◆ GetSkinningMatrices()

std::vector< glm::mat4 > nnl::SSkeleton::GetSkinningMatrices ( ) const

Retrieves the skinning matrices for transforming vertices in model space.

This function calculates the global matrices and combines them with the inverse matrices to obtain the skinning transformations, which can be further weighted to determine the appropriate transformations for individual vertices in model space.

Returns
A vector of glm::mat4.

◆ UpdateInverseMatrices()

void nnl::SSkeleton::UpdateInverseMatrices ( )

Updates the inverse matrices from local bone transformations.

This function recalculates the inverse matrices for all bones, ensuring they are consistent with the current local transformations.

Member Data Documentation

◆ roots

std::vector<SBone> nnl::SSkeleton::roots

This vector contains all the top-level bones that make up the skeleton's hierarchy.

◆ nnl::SMaterial

struct nnl::SMaterial

Represents a simple material with various properties for 3D rendering.

This structure contains properties defining the appearance of a material that is typical for the Phong reflection model.

See also
nnl::model::Material
Note
Color components must be in the range [0.0, 1.0]

Public Member Functions

bool operator== (const SMaterial &rhs) const
 Compares two materials for equality.

Public Attributes

std::string name
 An optional name for the material.
glm::vec3 specular {0.0f}
 The specular color of the material.
glm::vec3 diffuse {1.0f}
 The diffuse color of the material.
glm::vec3 ambient {0.5f}
 The ambient color of the material.
glm::vec3 emissive {0.0f}
 The emissive color of the material.
float opacity = 1.0f
 The opacity of the material. [0.0, 1.0].
float specular_power = 50.0f
int texture_id = -1
bool lit = false
u16 vfx_group_id = 0
 The visual effects group of the material.
SBlendMode alpha_mode = SBlendMode::kOpaque
STextureProjection projection_mode = STextureProjection::kUV
SValue extras

Member Function Documentation

◆ operator==()

bool nnl::SMaterial::operator== ( const SMaterial & rhs) const

Compares two materials for equality.

Parameters
rhsThe other SMaterial instance to compare against.
Returns
True if both materials are equal.

Member Data Documentation

◆ alpha_mode

SBlendMode nnl::SMaterial::alpha_mode = SBlendMode::kOpaque

Controls how the material is blended with previously drawn fragments

◆ ambient

glm::vec3 nnl::SMaterial::ambient {0.5f}

The ambient color of the material.

◆ diffuse

glm::vec3 nnl::SMaterial::diffuse {1.0f}

The diffuse color of the material.

◆ emissive

glm::vec3 nnl::SMaterial::emissive {0.0f}

The emissive color of the material.

◆ extras

SValue nnl::SMaterial::extras

Custom additional properties for the material.

◆ lit

bool nnl::SMaterial::lit = false

Indicates whether the material also uses the diffuse, specular, and emissive components in addition to the static ambient color, a texture, and vertex colors.

◆ name

std::string nnl::SMaterial::name

An optional name for the material.

◆ opacity

float nnl::SMaterial::opacity = 1.0f

The opacity of the material. [0.0, 1.0].

◆ projection_mode

STextureProjection nnl::SMaterial::projection_mode = STextureProjection::kUV

Controls how textures are projected onto meshes.

◆ specular

glm::vec3 nnl::SMaterial::specular {0.0f}

The specular color of the material.

◆ specular_power

float nnl::SMaterial::specular_power = 50.0f

This value determines the intensity and size of specular highlights.

Note
In the games this component is typically invisible
See also
nnl::lit::Lit

◆ texture_id

int nnl::SMaterial::texture_id = -1

The ID of the texture associated with the material. -1 indicates no texture.

See also
SAsset3D::textures

◆ vfx_group_id

u16 nnl::SMaterial::vfx_group_id = 0

The visual effects group of the material.

◆ nnl::SAttachment

struct nnl::SAttachment

Represents a node attached to a bone.

See also
nnl::model::Attachment

Public Attributes

std::string name = ""
 An optional name for the attachment.
std::size_t id = 0
 The id of the struct.
std::size_t bone = 0
 The parent bone.
glm::vec3 scale {1.0f, 1.0f, 1.0f}
 Scale transformation.
glm::quat rotation {1.0f, 0.0f, 0.0f, 0.0f}
 Rotation transformation.
glm::vec3 translation {0.0f, 0.0f, 0.0f}
 Translation transformation.

Member Data Documentation

◆ bone

std::size_t nnl::SAttachment::bone = 0

The parent bone.

◆ id

std::size_t nnl::SAttachment::id = 0

The id of the struct.

◆ name

std::string nnl::SAttachment::name = ""

An optional name for the attachment.

◆ rotation

glm::quat nnl::SAttachment::rotation {1.0f, 0.0f, 0.0f, 0.0f}

Rotation transformation.

◆ scale

glm::vec3 nnl::SAttachment::scale {1.0f, 1.0f, 1.0f}

Scale transformation.

◆ translation

glm::vec3 nnl::SAttachment::translation {0.0f, 0.0f, 0.0f}

Translation transformation.

◆ nnl::SModel

struct nnl::SModel

Represents a simple model.

This structure defines essential components of a 3D model. It acts as an intermediary between common exchange formats (such as glTF and FBX) and game-specific formats, supporting features that exist (in one way or another) in different formats.

Note
This struct represents a part of a complete 3D asset.
See also
nnl::model::Model
nnl::model::Convert
nnl::SAsset3D

Public Member Functions

glm::vec3 CalculateCenter () const
 Finds the center of the model.
bool TryBakeBindShape ()
 Bakes bind shape transforms from the inverse matrices into the model.
void Transform (const glm::mat4 &matrix)
 Transforms the model using a transformation matrix.
void TransformUV (const glm::mat3 &matrix)
 Transforms the UV coordinates of the model using a transformation matrix.
void RemoveDuplicateMaterials ()
 Removes duplicate materials from the model.
void GenerateSmoothNormals ()
 Generates smooth normals for the meshes.
void GenerateFlatNormals ()
 Generates flat normals for the meshes.
std::pair< glm::vec3, glm::vec3 > FindMinMax () const
 Finds the minimum and maximum points of the model.
glm::mat4 Normalize ()
 Normalizes the model to fit within the range of -1.0 to 1.0.
std::vector< std::pair< glm::vec2, glm::vec2 > > NormalizeUV ()
 Normalizes the UV coordinates of the model.
void NormalizeWeights ()
 Normalizes the weights of the vertices.
void NormalizeNormals ()
 Normalizes the normals of the vertices.
void QuantWeights (unsigned int steps=128)
 Quantizes the vertex weights to a specified number of steps.
void SortWeights ()
 Sorts vertex weights by influence, placing the highest values first.
void LimitWeightsPerVertex (unsigned int max_weights=3)
 Limits the number of weights per vertex.
void LimitWeightsPerTriangle (unsigned int max_weights=8)
 Limits the number of weights per triangle.
void ResetWeights ()
 Removes all weights.
void ResetNormals ()
 Resets all vertex normals to the default value.
void ResetUVs ()
 Resets all texture coordinates to the default value.
void ResetColors ()
 Resets all vertex colors to the default value.

Public Attributes

SSkeleton skeleton
std::vector< SAttachmentattachments
 A vector of attachments associated with the model.
std::vector< SMeshmeshes
 A vector of meshes that make up the model.
std::vector< SMaterialmaterials
 A vector of materials used by the meshes.
std::vector< std::string > material_variants
std::vector< SUVAnimationuv_animations

Member Function Documentation

◆ CalculateCenter()

glm::vec3 nnl::SModel::CalculateCenter ( ) const

Finds the center of the model.

This method calculates the center point of the mesh by averaging the positions of all mesh vertices.

Returns
A glm::vec3 representing the center of the model.

◆ FindMinMax()

std::pair< glm::vec3, glm::vec3 > nnl::SModel::FindMinMax ( ) const

Finds the minimum and maximum points of the model.

This method finds the minimum and maximum xyz coordinates of the vertices in the model.

Returns
A pair of glm::vec3 representing the minimum and maximum xyz points.

◆ GenerateFlatNormals()

void nnl::SModel::GenerateFlatNormals ( )

Generates flat normals for the meshes.

This method calculates face normals and duplicates vertex data to achive faceted appearance.

◆ GenerateSmoothNormals()

void nnl::SModel::GenerateSmoothNormals ( )

Generates smooth normals for the meshes.

This method calculates smooth normals for smooth shading.

◆ LimitWeightsPerTriangle()

void nnl::SModel::LimitWeightsPerTriangle ( unsigned int max_weights = 8)

Limits the number of weights per triangle.

This method restricts the number of bone weights that can influence vertices of a triangle to a specified maximum. This may be useful for further conversion of vertices to vertex buffers used by the GE.

Parameters
max_weightsThe maximum number of weights per triangle.
See also
nnl::model::kMaxNumBonePerPrim

◆ LimitWeightsPerVertex()

void nnl::SModel::LimitWeightsPerVertex ( unsigned int max_weights = 3)

Limits the number of weights per vertex.

This method restricts the number of bone weights that can influence each vertex to a specified maximum. This may be useful for further conversion of vertices to vertex buffers used by the GE.

Parameters
max_weightsThe maximum number of weights per vertex.
See also
nnl::model::kMaxNumBonePerPrim

◆ Normalize()

glm::mat4 nnl::SModel::Normalize ( )

Normalizes the model to fit within the range of -1.0 to 1.0.

This function changes the model's vertices to ensure they fit within the range of -1.0 to 1.0. It also modifies the inverse matrices so they undo the scaling. This normalization may be useful for converting positions to fixed-point integers.

Returns
glm::mat4 The scale matrix that was applied to the inverse matrices.

◆ NormalizeNormals()

void nnl::SModel::NormalizeNormals ( )

Normalizes the normals of the vertices.

This method adjusts the vertex normals so that their length is 1.0f.

◆ NormalizeUV()

std::vector< std::pair< glm::vec2, glm::vec2 > > nnl::SModel::NormalizeUV ( )

Normalizes the UV coordinates of the model.

This function rescales the UV coordinates to ensure they fit within the range of 0.0 to 1.0. Each mesh group is normalized independently. This normalization may be useful for converting texture coordinates to fixed-point integers.

Returns
A collection of pairs for each mesh group, containing the scale and offset transformations needed to restore UV coordinates to their original values.
See also
nnl::model::MeshGroup

◆ NormalizeWeights()

void nnl::SModel::NormalizeWeights ( )

Normalizes the weights of the vertices.

This method adjusts the vertex weights so that they sum to 1.0f.

◆ QuantWeights()

void nnl::SModel::QuantWeights ( unsigned int steps = 128)

Quantizes the vertex weights to a specified number of steps.

This method reduces the precision of the vertex weights by quantizing them to a specified number of discrete steps, making sure they still add up to 1.0. This may be used for further conversion of weights to fixed-point integers.

Parameters
stepsThe number of quantization steps.

◆ RemoveDuplicateMaterials()

void nnl::SModel::RemoveDuplicateMaterials ( )

Removes duplicate materials from the model.

This function removes any materials that are identical, which may improve the performance.

◆ ResetColors()

void nnl::SModel::ResetColors ( )

Resets all vertex colors to the default value.

◆ ResetNormals()

void nnl::SModel::ResetNormals ( )

Resets all vertex normals to the default value.

◆ ResetUVs()

void nnl::SModel::ResetUVs ( )

Resets all texture coordinates to the default value.

◆ ResetWeights()

void nnl::SModel::ResetWeights ( )

Removes all weights.

◆ SortWeights()

void nnl::SModel::SortWeights ( )

Sorts vertex weights by influence, placing the highest values first.

◆ Transform()

void nnl::SModel::Transform ( const glm::mat4 & matrix)

Transforms the model using a transformation matrix.

This method applies the specified transformation matrix to all vertices in the model, modifying their positions and normals.

Parameters
matrixThe transformation matrix to apply.

◆ TransformUV()

void nnl::SModel::TransformUV ( const glm::mat3 & matrix)

Transforms the UV coordinates of the model using a transformation matrix.

This method applies the specified SRT matrix to the UV coordinates of all vertices in the model.

Parameters
matrixThe transformation matrix to apply.

◆ TryBakeBindShape()

bool nnl::SModel::TryBakeBindShape ( )

Bakes bind shape transforms from the inverse matrices into the model.

This method applies "bind shape matrices" that may be contained in inverse bind matrices to mesh vertices. If some matrices are non-invertible, it returns false.

Inverse matrices often include a scaling matrix to revert the model to its original proportions after normalization to the range of [-1.0, 1.0].

Returns
bool true on success
Note
This method assumes that local bone transforms represent the bind pose.

Member Data Documentation

◆ attachments

std::vector<SAttachment> nnl::SModel::attachments

A vector of attachments associated with the model.

◆ material_variants

std::vector<std::string> nnl::SModel::material_variants

Represents material variants similar to those found in the glTF format. When a specific variant is active, the material of a mesh changes to the corresponding material specified in the mesh's variant mapping.

See also
nnl::SMesh

◆ materials

std::vector<SMaterial> nnl::SModel::materials

A vector of materials used by the meshes.

◆ meshes

std::vector<SMesh> nnl::SModel::meshes

A vector of meshes that make up the model.

◆ skeleton

SSkeleton nnl::SModel::skeleton

The skeleton associated with the model. It must contain at least 1 bone.

◆ uv_animations

std::vector<SUVAnimation> nnl::SModel::uv_animations

A vector of texture coordinate animations for textured materials

Enumeration Type Documentation

◆ SBlendMode

enum class nnl::SBlendMode : u8
strong

Enumeration of blending modes for materials.

See also
nnl::SMaterial
Enumerator
kOpaque 

Completely opaque.

kAlpha 

Standard alpha blending.

Note
The alpha blending is always performed in the games. When converted to an in-game Material, this flag additionally disables depth writing and defers rendering to ensure proper blending.
kClip 

Alpha clipping mode; fragments below a fixed threshold of 0.5 are discarded.

kAdd 

Additive blending; colors are added to the background.

kSub 

Subtractive blending; colors are subtracted from the background.

◆ STextureProjection

enum class nnl::STextureProjection
strong

Enumeration of projection modes for textures.

See also
nnl::SMaterial
Enumerator
kUV 

Standard UV mapping.

kMatrix 

Matrix-based projection.

kEnvironment 

Environment mapping projection.

Variable Documentation

◆ kMaxNumBoneWeight

std::size_t nnl::kMaxNumBoneWeight = 8
constexpr

Maximum number of bone weights and indices in SVertex.

See also
nnl::SVertex