NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
Simple 3D Asset

Provides data structures for representing essential components of a 3D asset. More...

Topics

 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.

Classes

struct  nnl::SPosition
 Represents an empty node with a transform. More...
struct  nnl::SLight
 Represents a light source in a 3D scene. More...
struct  nnl::SAsset3D
 Represents a 3D asset composed of various components. More...

Detailed Description

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

Class Documentation

◆ nnl::SPosition

struct 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.

Member Function Documentation

◆ 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
transformThe local transformation matrix.
Note
The matrix must be decomposable and invertible.

Member Data Documentation

◆ extras

SValue nnl::SPosition::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}

Rotation transformation.

◆ scale

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

Scale transformation.

◆ translation

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

Translation transformation.

◆ nnl::SLight

struct 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.

Member Function Documentation

◆ 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
baseThe 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
transformThe transformation matrix to apply to the base.
baseThe default direction of the light (may differ between formats).

Member Data Documentation

◆ color

glm::vec3 nnl::SLight::color = {1.0f, 1.0f, 1.0f}

Color of the light.

◆ direction

glm::vec3 nnl::SLight::direction = {0.0f, -1.0f, 0.0f}

Light direction from the source.

◆ extras

SValue nnl::SLight::extras

Any additional data for custom use.

◆ name

std::string nnl::SLight::name

An optional name for the light.

◆ nnl::SAsset3D

struct 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< STexturetextures
 Textures used by the materials of the model.
std::vector< SAnimationanimations
 Skeletal animations.
std::vector< SVisibilityAnimationvisibility_animations
 Visibility animations for mesh groups of the model.
std::vector< SLightlights
 Light sources.
std::vector< SPositionpositions
 Spawn positions.
SValue extras
 Any additional data for custom use.

Member Function Documentation

◆ 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
flipIndicates 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
pathThe file path where the glTF asset will be exported.
flipIndicates whether to vertically flip textures during export.
pack_texturesIf 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
bufferThe buffer containing a glTF asset.
base_pathThe path for loading external data buffers or images.
flipIndicates whether to vertically flip textures during loading.
decode_imagesIf 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
pathThe file path to the glTF asset.
flipIndicates whether to vertically flip textures during loading.
decode_imagesIf 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
scaleThe 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_pointThe 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

Member Data Documentation

◆ animations

std::vector<SAnimation> nnl::SAsset3D::animations

Skeletal animations.

◆ extras

SValue nnl::SAsset3D::extras

Any additional data for custom use.

◆ lights

std::vector<SLight> nnl::SAsset3D::lights

Light sources.

◆ model

SModel nnl::SAsset3D::model

The 3D model.

◆ name

std::string nnl::SAsset3D::name

An optional name for the asset.

◆ positions

std::vector<SPosition> nnl::SAsset3D::positions

Spawn positions.

◆ textures

std::vector<STexture> nnl::SAsset3D::textures

Textures used by the materials of the model.

◆ visibility_animations

std::vector<SVisibilityAnimation> nnl::SAsset3D::visibility_animations

Visibility animations for mesh groups of the model.