Provides data structures for representing essential components of a 3D asset.
More...
|
| | Simple Animation |
| | Provides data structures for representing various animation types and their essential components.
|
| | Simple Model |
| | Provides data structures and functions for managing essential components of a 3D model.
|
Provides data structures for representing essential components of a 3D asset.
This file provides data structures and functions for managing essential parts of 3D assets. These structures enable importing and exporting data between common exchange formats (such as glTF or FBX) and in-game formats.
- See also
- nnl::SAsset3D
-
nnl::SModel
-
nnl::STexture
-
nnl::SAnimation
-
nnl::SVisibilityAnimation
◆ nnl::SPosition
Represents an empty node with a transform.
- See also
- nnl::posd::Position
-
nnl::minimap::Convert
-
nnl::SAsset3D
Public Member Functions |
| glm::mat4 | GetTransform () const |
| | Calculates the local transformation matrix from the SRT properties.
|
| void | SetTransform (const glm::mat4 &transform) |
| | Sets the local SRT properties.
|
Public Attributes |
| std::string | name |
| | An optional name for the struct.
|
| std::size_t | id = 0 |
| | Unique identifier for the node.
|
| 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.
|
| SValue | extras |
| | Any additional data for custom use.
|
◆ GetTransform()
| glm::mat4 nnl::SPosition::GetTransform |
( |
| ) |
const |
Calculates the local transformation matrix from the SRT properties.
- Returns
- The local transformation matrix.
◆ SetTransform()
| void nnl::SPosition::SetTransform |
( |
const glm::mat4 & | transform | ) |
|
Sets the local SRT properties.
This method decomposes the matrix and sets the local SRT properties.
- Parameters
-
| transform | The local transformation matrix. |
- Note
- The matrix must be decomposable and invertible.
◆ extras
Any additional data for custom use.
◆ id
| std::size_t nnl::SPosition::id = 0 |
Unique identifier for the node.
◆ name
| std::string nnl::SPosition::name |
An optional name for the struct.
◆ rotation
| glm::quat nnl::SPosition::rotation {1.0f, 0.0f, 0.0f, 0.0f} |
◆ scale
| glm::vec3 nnl::SPosition::scale {1.0f, 1.0f, 1.0f} |
◆ translation
| glm::vec3 nnl::SPosition::translation {0.0f, 0.0f, 0.0f} |
Translation transformation.
◆ nnl::SLight
Represents a light source in a 3D scene.
- See also
- nnl::lit::Light
-
nnl::lit::Convert
-
nnl::SAsset3D
Public Member Functions |
| glm::mat4 | GetTransform (glm::vec3 base=glm::vec3(0, 0, -1.0f)) const |
| | Computes the transformation matrix for the light.
|
| void | SetDirection (const glm::mat4 &transform, glm::vec3 base=glm::vec3(0, 0, -1.0f)) |
| | Sets the direction of the light based on a transformation matrix.
|
Public Attributes |
| std::string | name |
| | An optional name for the light.
|
| glm::vec3 | direction = {0.0f, -1.0f, 0.0f} |
| | Light direction from the source.
|
| glm::vec3 | color = {1.0f, 1.0f, 1.0f} |
| | Color of the light.
|
| SValue | extras |
| | Any additional data for custom use.
|
◆ GetTransform()
| glm::mat4 nnl::SLight::GetTransform |
( |
glm::vec3 | base = glm::vec3(0, 0, -1.0f) | ) |
const |
Computes the transformation matrix for the light.
Computes the matrix that transforms the base light direction to the direction specified in this struct.
- Parameters
-
| base | The default direction of the light (may differ between formats). |
- Returns
- The transformation matrix for the light.
◆ SetDirection()
| void nnl::SLight::SetDirection |
( |
const glm::mat4 & | transform, |
|
|
glm::vec3 | base = glm::vec3(0, 0, -1.0f) ) |
Sets the direction of the light based on a transformation matrix.
- Parameters
-
| transform | The transformation matrix to apply to the base. |
| base | The default direction of the light (may differ between formats). |
◆ color
| glm::vec3 nnl::SLight::color = {1.0f, 1.0f, 1.0f} |
◆ direction
| glm::vec3 nnl::SLight::direction = {0.0f, -1.0f, 0.0f} |
Light direction from the source.
◆ extras
Any additional data for custom use.
◆ name
| std::string nnl::SLight::name |
An optional name for the light.
◆ nnl::SAsset3D
Represents a 3D asset composed of various components.
This structure serves as the primary container for various components of a 3D asset, acting as an intermediary representation for conversion between common exchange formats (such as glTF and FBX) and in-game formats.
- See also
- nnl::SAsset3D::Import
-
nnl::SAsset3D::ExportGLB
-
nnl::asset::Asset3D
Public Member Functions |
| void | ExportGLB (const std::filesystem::path &path, bool flip=true, bool pack_textures=true) const |
| | Exports the asset data to a GLB file.
|
| Buffer | ExportGLB (bool flip=true) const |
| | Exports the asset data to a GLB file.
|
| void | Scale (float scale=1.0f) |
| | Scales the asset by a specified factor.
|
| bool | TrySimplifySkeleton () |
| | Simplifies the skeleton by retaining only translation transformations.
|
| void | SortForBlending (glm::vec3 reference_point) |
| | Sorts meshes for proper blending and improved performance.
|
Static Public Member Functions |
| static SAsset3D | Import (const std::filesystem::path &path, bool flip=true, bool decode_images=true) |
| | Constructs an asset from a glTF file located at the specified path.
|
| static SAsset3D | Import (BufferView buffer, const std::filesystem::path &base_path={}, bool flip=true, bool decode_images=true) |
| | Constructs an asset from a glTF file located in the buffer.
|
Public Attributes |
| std::string | name |
| | An optional name for the asset.
|
| SModel | model |
| | The 3D model.
|
| std::vector< STexture > | textures |
| | Textures used by the materials of the model.
|
| std::vector< SAnimation > | animations |
| | Skeletal animations.
|
| std::vector< SVisibilityAnimation > | visibility_animations |
| | Visibility animations for mesh groups of the model.
|
| std::vector< SLight > | lights |
| | Light sources.
|
| std::vector< SPosition > | positions |
| | Spawn positions.
|
| SValue | extras |
| | Any additional data for custom use.
|
◆ ExportGLB() [1/2]
| Buffer nnl::SAsset3D::ExportGLB |
( |
bool | flip = true | ) |
const |
|
nodiscard |
Exports the asset data to a GLB file.
This method saves the asset data in the glTF format to a buffer.
- Parameters
-
| flip | Indicates whether to vertically flip textures during export. |
◆ ExportGLB() [2/2]
| void nnl::SAsset3D::ExportGLB |
( |
const std::filesystem::path & | path, |
|
|
bool | flip = true, |
|
|
bool | pack_textures = true ) const |
Exports the asset data to a GLB file.
This method saves the asset data to the specified file path in the glTF format.
- Parameters
-
| path | The file path where the glTF asset will be exported. |
| flip | Indicates whether to vertically flip textures during export. |
| pack_textures | If true, the textures will be packed into the exported file. |
◆ Import() [1/2]
| SAsset3D nnl::SAsset3D::Import |
( |
BufferView | buffer, |
|
|
const std::filesystem::path & | base_path = {}, |
|
|
bool | flip = true, |
|
|
bool | decode_images = true ) |
|
staticnodiscard |
Constructs an asset from a glTF file located in the buffer.
This method loads data from a glTF asset found in the given buffer.
- Parameters
-
| buffer | The buffer containing a glTF asset. |
| base_path | The path for loading external data buffers or images. |
| flip | Indicates whether to vertically flip textures during loading. |
| decode_images | If false, STexture objects will retain the original image files, with the height property indicating the size of these files. |
◆ Import() [2/2]
| SAsset3D nnl::SAsset3D::Import |
( |
const std::filesystem::path & | path, |
|
|
bool | flip = true, |
|
|
bool | decode_images = true ) |
|
staticnodiscard |
Constructs an asset from a glTF file located at the specified path.
This method loads data from a glTF asset found at the given path.
- Parameters
-
| path | The file path to the glTF asset. |
| flip | Indicates whether to vertically flip textures during loading. |
| decode_images | If false, STexture objects will retain the original image files, with the height property indicating the size of these files. |
◆ Scale()
| void nnl::SAsset3D::Scale |
( |
float | scale = 1.0f | ) |
|
Scales the asset by a specified factor.
This method applies a uniform scale transformation to all components of the asset, including the model and its skeleton, spawn positions, and animations.
- Parameters
-
| scale | The scaling factor to apply. |
- Note
- The root bone is not transformed by this method so objects attached to the asset (effects, hitboxes) are not affected.
◆ SortForBlending()
| void nnl::SAsset3D::SortForBlending |
( |
glm::vec3 | reference_point | ) |
|
Sorts meshes for proper blending and improved performance.
Re-orders meshes by distance from the reference point, aiming to achieve correct alpha blending and to minimize overdraw.
- Parameters
-
| reference_point | The position in the world used to calculate the distance. |
- See also
- nnl::SModel::CalculateCenter
◆ TrySimplifySkeleton()
| bool nnl::SAsset3D::TrySimplifySkeleton |
( |
| ) |
|
Simplifies the skeleton by retaining only translation transformations.
Modifies bones and animations to preserve bone positions while resetting rotation and scale to default values.
- Returns
- true on success
◆ animations
◆ extras
Any additional data for custom use.
◆ lights
| std::vector<SLight> nnl::SAsset3D::lights |
◆ model
◆ name
| std::string nnl::SAsset3D::name |
An optional name for the asset.
◆ positions
| std::vector<SPosition> nnl::SAsset3D::positions |
◆ textures
| std::vector<STexture> nnl::SAsset3D::textures |
Textures used by the materials of the model.
◆ visibility_animations
Visibility animations for mesh groups of the model.