NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
sasset3d.hpp
Go to the documentation of this file.
1
16#pragma once
17
18#include <filesystem>
19#include <string>
20#include <vector>
21
25
26namespace nnl {
27
41struct SPosition {
42 std::string name;
43
44 std::size_t id = 0;
45
46 glm::vec3 scale{1.0f, 1.0f, 1.0f};
47 glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f};
48 glm::vec3 translation{0.0f, 0.0f, 0.0f};
49
51
58 glm::mat4 GetTransform() const;
59
69 void SetTransform(const glm::mat4& transform);
70};
71
78struct SLight {
79 std::string name;
80 glm::vec3 direction = {0.0f, -1.0f, 0.0f};
81 glm::vec3 color = {1.0f, 1.0f, 1.0f};
82
84
94 glm::mat4 GetTransform(glm::vec3 base = glm::vec3(0, 0, -1.0f)) const;
95
102 void SetDirection(const glm::mat4& transform, glm::vec3 base = glm::vec3(0, 0, -1.0f));
103};
104
116struct SAsset3D {
117 std::string name;
119 std::vector<STexture> textures;
120 std::vector<SAnimation> animations;
121 std::vector<SVisibilityAnimation> visibility_animations;
122 std::vector<SLight> lights;
123 std::vector<SPosition> positions;
135 [[nodiscard]] static SAsset3D Import(const std::filesystem::path& path, bool flip = true, bool decode_images = true);
147 [[nodiscard]] static SAsset3D Import(BufferView buffer, const std::filesystem::path& base_path = {}, bool flip = true,
148 bool decode_images = true);
160 void ExportGLB(const std::filesystem::path& path, bool flip = true, bool pack_textures = true) const;
161
170 [[nodiscard]] Buffer ExportGLB(bool flip = true) const;
183 void Scale(float scale = 1.0f);
184
194
206 void SortForBlending(glm::vec3 reference_point);
207};
208
209
210} // namespace nnl
Reader implementation for read-only memory buffers.
Definition io.hpp:598
std::vector< u8 > Buffer
A type alias for std::vector<u8> that denotes a raw, contiguous memory region that may be interpreted...
Definition io.hpp:40
Represents a simple model.
Definition smodel.hpp:654
std::vector< SPosition > positions
Spawn positions.
Definition sasset3d.hpp:123
std::vector< SAnimation > animations
Skeletal animations.
Definition sasset3d.hpp:120
std::string name
An optional name for the light.
Definition sasset3d.hpp:79
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.
void SortForBlending(glm::vec3 reference_point)
Sorts meshes for proper blending and improved performance.
glm::quat rotation
Rotation transformation.
Definition sasset3d.hpp:47
Buffer ExportGLB(bool flip=true) const
Exports the asset data to a GLB file.
SValue extras
Any additional data for custom use.
Definition sasset3d.hpp:83
bool TrySimplifySkeleton()
Simplifies the skeleton by retaining only translation transformations.
glm::mat4 GetTransform() const
Calculates the local transformation matrix from the SRT properties.
std::string name
An optional name for the asset.
Definition sasset3d.hpp:117
SValue extras
Any additional data for custom use.
Definition sasset3d.hpp:50
std::vector< SVisibilityAnimation > visibility_animations
Visibility animations for mesh groups of the model.
Definition sasset3d.hpp:121
glm::vec3 translation
Translation transformation.
Definition sasset3d.hpp:48
std::vector< STexture > textures
Textures used by the materials of the model.
Definition sasset3d.hpp:119
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.
glm::vec3 color
Color of the light.
Definition sasset3d.hpp:81
void SetTransform(const glm::mat4 &transform)
Sets the local SRT properties.
SModel model
The 3D model.
Definition sasset3d.hpp:118
SValue extras
Any additional data for custom use.
Definition sasset3d.hpp:124
void Scale(float scale=1.0f)
Scales the asset by a specified factor.
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.
void ExportGLB(const std::filesystem::path &path, bool flip=true, bool pack_textures=true) const
Exports the asset data to a GLB file.
glm::vec3 direction
Light direction from the source.
Definition sasset3d.hpp:80
glm::vec3 scale
Scale transformation.
Definition sasset3d.hpp:46
std::string name
An optional name for the struct.
Definition sasset3d.hpp:42
std::vector< SLight > lights
Light sources.
Definition sasset3d.hpp:122
Represents a light source in a 3D scene.
Definition sasset3d.hpp:78
Represents an empty node with a transform.
Definition sasset3d.hpp:41
Represents a 3D asset composed of various components.
Definition sasset3d.hpp:116
A class representing JSON-like values (null, bool, numbers, strings, arrays, or objects)
Definition svalue.hpp:41
Definition exception.hpp:56
Provides data structures for representing various animation types and their essential components.
Provides data structures and functions for managing essential components of a 3D model.
Provides data structures for representing essential components of a texture.