|
NSUNI/NSLAR Library a250670
|
Classes | |
| struct | nnl::model::Bone |
| Represents a bone/joint in a skeleton. More... | |
| struct | nnl::model::TextureSwap |
| Represents a configuration for texture swapping. More... | |
| struct | nnl::model::UVAnimation |
| Represents a UV animation configuration. More... | |
| struct | nnl::model::Attachment |
| Represents a configuration for attaching an external object to a model. More... | |
| struct | nnl::model::BBox |
| Represents a bounding box for objects. More... | |
| struct | nnl::model::Primitive |
| Represents the smallest unit of geometry in the hierarchy. More... | |
| struct | nnl::model::SubMesh |
| Represents a smaller part of a mesh. More... | |
| struct | nnl::model::Mesh |
| This struct defines various properties of a mesh. More... | |
| struct | nnl::model::MeshGroup |
| Represents a group of meshes. More... | |
| struct | nnl::model::Material |
| Represents the properties of a material. More... | |
| struct | nnl::model::Model |
| Represents a 3D model with various components. More... | |
| struct | nnl::model::ConvertParam |
| Parameters for converting a simplified mesh to the in-game format. More... | |
Functions | |
| Model | nnl::model::Convert (SModel &&smodel, const std::vector< ConvertParam > &mesh_params, bool move_with_root=false) |
| Converts a simplified model representation to the in-game format. | |
| Model | nnl::model::Convert (SModel &&smodel, const ConvertParam &mesh_params={}, bool move_with_root=false) |
| Converts a simplified model representation to the in-game format. | |
| SModel | nnl::model::Convert (const Model &model) |
| Converts a game model to a simplified model representation. | |
| bool | nnl::model::IsOfType (BufferView buffer) |
| Tests if the provided file is a model. | |
| Model | nnl::model::Import (BufferView buffer) |
| Parses a binary file and converts it to a structured model. | |
| Buffer | nnl::model::Export (const Model &model) |
| Converts a model to its binary file representation. | |
Variables | |
| constexpr std::size_t | nnl::model::kMaxNumBonePerPrim = 8 |
| Maximum number of bones that can influence a single primitive and a single vertex. | |
| struct nnl::model::Bone |
Represents a bone/joint in a skeleton.
This struct defines the properties of a bone, as well as its relation to its parent bone in the hierarchy. The transformation properties are relative to the bone's parent. A complete skeleton is represented as an array of such Bone structures (which can be created by performing a preorder traversal of a tree that defines the skeletal hierarchy.)
Public Attributes | |
| i16 | parent_index = -1 |
| An index into the array of bones; -1 means a bone has no parent. | |
| glm::vec3 | scale {1.0f} |
| The scale transform. | |
| glm::vec3 | rotation {0.0f} |
| glm::vec3 | translation {0.0f} |
| The translation transform. | |
| i16 nnl::model::Bone::parent_index = -1 |
An index into the array of bones; -1 means a bone has no parent.
| glm::vec3 nnl::model::Bone::rotation {0.0f} |
Pitch, Yaw, Roll. Euler angles in degrees. Each value must be in the range [-180, +180]
| glm::vec3 nnl::model::Bone::scale {1.0f} |
The scale transform.
| glm::vec3 nnl::model::Bone::translation {0.0f} |
The translation transform.
| struct nnl::model::TextureSwap |
Represents a configuration for texture swapping.
This struct defines a texture swap configuration that specifies the original texture index and a new texture index that the original texture can be swapped with.
A texture swap can be activated by an action configuration or from the game's code. Texture swaps are primarily used to imitate facial animations.
| struct nnl::model::UVAnimation |
Represents a UV animation configuration.
This struct defines the properties for UV animation, allowing for various types of texture shifting effects. The behavior of the animation is determined by the specified animation mode, which affects the exact interpretation of num_frames, u_shift, and v_shift.
Public Attributes | |
| UVAnimationMode | animation_mode = UVAnimationMode::kNone |
| Defines how shifting occurs. | |
| u16 | num_frames = 0 |
| f32 | u_shift = 0 |
| f32 | v_shift = 0 |
| Same as u_shift but for the v coordinate. | |
| UVAnimationMode nnl::model::UVAnimation::animation_mode = UVAnimationMode::kNone |
Defines how shifting occurs.
| u16 nnl::model::UVAnimation::num_frames = 0 |
The number of frames for the animation. When animation_mode is kRangedShift, this denotes the total duration of a cycle. When animation_mode is kFramedShift, shifting occurs every num_frames. Ignored otherwise.
| f32 nnl::model::UVAnimation::u_shift = 0 |
When animation_mode is kRangedShift, this denotes the radius of the shape (v_shift should be the same for a circle). In other modes, this value is simply added to texture coordinates as is. This value usually should be in the range (-1.0, 1.0)
| f32 nnl::model::UVAnimation::v_shift = 0 |
Same as u_shift but for the v coordinate.
| struct nnl::model::Attachment |
Represents a configuration for attaching an external object to a model.
This structure is used to define the transformation properties of a separate 3D asset attached to a bone. The feature is sometimes used in NSLAR cutscenes.
Public Attributes | |
| BoneIndex | bone_id = 0 |
| u16 | attachment_id = 0 |
| glm::mat4 | transform {1.0f} |
| u16 nnl::model::Attachment::attachment_id = 0 |
A number that serves as the identifier for this struct. The game looks for this id.
| BoneIndex nnl::model::Attachment::bone_id = 0 |
The index of the bone to which the attachment should be connected.
| glm::mat4 nnl::model::Attachment::transform {1.0f} |
A transformation matrix for the attachment (relative to the parent bone)
| struct nnl::model::BBox |
Represents a bounding box for objects.
This structure defines a bounding box that is used for frustum culling of map objects (it has no effect on characters)
The bounding box is defined by two vertices, which represent the corners of the box in 3D space.
Public Attributes | |
| BoneIndex | bone_index = 0 |
| glm::vec3 | min {0.0f} |
| The min coordinate. | |
| glm::vec3 | max {0.0f} |
| The max coordinate. | |
| BoneIndex nnl::model::BBox::bone_index = 0 |
Index of the bone the BBox is attached to (usually the root bone).
| glm::vec3 nnl::model::BBox::max {0.0f} |
The max coordinate.
| glm::vec3 nnl::model::BBox::min {0.0f} |
The min coordinate.
| struct nnl::model::Primitive |
Represents the smallest unit of geometry in the hierarchy.
The Primitive struct encapsulates details about the primitive type used, the number of elements contained, and the associated data buffer. For instance, when using PrimitiveType::kTriangles, the buffer may contain 3 or more vertices to represent one or multiple triangles.
Public Attributes | |
| PrimitiveType | primitive_type = PrimitiveType::kTriangles |
| Type of the primitive. | |
| u16 | num_elements = 0 |
| Buffer | vertex_index_buffer |
| u16 nnl::model::Primitive::num_elements = 0 |
Represents the number of vertices or indices stored in the vertex_index_buffer.
| PrimitiveType nnl::model::Primitive::primitive_type = PrimitiveType::kTriangles |
Type of the primitive.
| struct nnl::model::SubMesh |
Represents a smaller part of a mesh.
This struct represents a smaller part of a mesh. It exists mainly due to the fact that the PSP's Graphics Engine can hold only 8 skin matrices at a time when rendering a Primitive. Therefore, primitives that share bones need to be grouped into these structs to be drawn. There is usually only 1 such struct if a mesh does not use skinning. If a mesh is too big to fit into 1 submesh, it can also be sliced into multiple parts.
Public Attributes | |
| u16 | num_bones = 1 |
| u32 | vertex_format = 0 |
| Buffer | indexed_vertex_buffer |
| std::vector< Primitive > | primitives |
| List of primitives that make up this submesh. | |
| std::array< BoneIndex, kMaxNumBonePerPrim > | bone_indices {0} |
| std::vector< u32 > | display_list |
| std::array<BoneIndex, kMaxNumBonePerPrim> nnl::model::SubMesh::bone_indices {0} |
Indices of the bones influencing this submesh. Every bone used by submeshes must have a corresponding entry in the inverse_matrix_bone_table
| std::vector<u32> nnl::model::SubMesh::display_list |
A list of rendering commands for drawing the primitives in this submesh. It must contain at least 4 basic commands per each primitive. Additional commands may also be inserted, in which case they must be located right before the draw command or after it (otherwise, the games may alter the list).
| Buffer nnl::model::SubMesh::indexed_vertex_buffer |
If vertex_format is set to use indices, this buffer must store unique vertices. In that case, buffers in primitives store indices that refer to this buffer. It's empty otherwise.
| u16 nnl::model::SubMesh::num_bones = 1 |
The number of bones this submesh refers to. Typically, this value must be within the range of 1 to 8 (0 is allowed in a specific edge case)
| std::vector<Primitive> nnl::model::SubMesh::primitives |
List of primitives that make up this submesh.
| u32 nnl::model::SubMesh::vertex_format = 0 |
The format of the vertex data. It matches what the GE expects
| struct nnl::model::Mesh |
This struct defines various properties of a mesh.
Public Attributes | |
| std::vector< SubMesh > | submeshes |
| bool | use_skinning = false |
| bool | use_bbox = false |
| Flag indicating whether to use the bounding box. | |
| BBox | bbox |
| The bounding box of the mesh. | |
| u16 | material_id = 0 |
| The index of the material associated with this mesh. | |
| BBox nnl::model::Mesh::bbox |
The bounding box of the mesh.
| u16 nnl::model::Mesh::material_id = 0 |
The index of the material associated with this mesh.
| std::vector<SubMesh> nnl::model::Mesh::submeshes |
A collection of submeshes that make up the mesh (1 or more)
| bool nnl::model::Mesh::use_bbox = false |
Flag indicating whether to use the bounding box.
| bool nnl::model::Mesh::use_skinning = false |
Flag indicating whether skinning is applied to the mesh. It should be active for meshes that include weights into their vertex data and are influenced by multiple bones. In other cases, it should be set to false.
| struct nnl::model::MeshGroup |
Represents a group of meshes.
This struct groups multiple meshes together. The visibility of these groups may be animated. This struct also enables texture coordinate adjustments, which are used to restore the origianl UV coordinates when they are stored as normalized integers.
Public Attributes | |
| std::vector< Mesh > | meshes |
| Collection of meshes that belong to this group. | |
| f32 | u_scale = 1.0f |
| Scale factor for the U texture coordinate. | |
| f32 | v_scale = 1.0f |
| Scale factor for the V texture coordinate. | |
| f32 | u_offset = 0.0f |
| Offset for the U texture coordinate. | |
| f32 | v_offset = 0.0f |
| Offset for the V texture coordinate. | |
| std::vector<Mesh> nnl::model::MeshGroup::meshes |
Collection of meshes that belong to this group.
| f32 nnl::model::MeshGroup::u_offset = 0.0f |
Offset for the U texture coordinate.
| f32 nnl::model::MeshGroup::u_scale = 1.0f |
Scale factor for the U texture coordinate.
| f32 nnl::model::MeshGroup::v_offset = 0.0f |
Offset for the V texture coordinate.
| f32 nnl::model::MeshGroup::v_scale = 1.0f |
Scale factor for the V texture coordinate.
| struct nnl::model::Material |
Represents the properties of a material.
This struct defines various attributes of a material that determine the look of the mesh that uses it.
By default, the material does not interact with lights and only the ambient component, vertex colors, and a texture are used. To change that the kLit flag may be activated, which enables the use of the Phong reflection model.
The alpha component of the ambient color can be utilized for setting transparency. The specular component is often unused and invisible unless the light source configuration is changed.
Public Attributes | |
| u32 | specular = 0xFF000000 |
| u32 | diffuse = 0xFFFFFFFF |
| u32 | ambient = 0xFF808080 |
| u32 | emissive = 0xFF000000 |
| f32 | specular_power = 50.0f |
| Power of the specular highlight. | |
| i16 | texture_id = -1 |
| Index of the texture; -1 indicates no texture. | |
| u8 | uv_animation_id = 0 |
| u8 | vfx_group_id = 0 |
| MaterialFeatures | features {} |
| Render settings for the material. | |
| u32 nnl::model::Material::ambient = 0xFF808080 |
Ambient/constant color of the material in the ABGR format (alpha is used).
| u32 nnl::model::Material::diffuse = 0xFFFFFFFF |
Diffuse color of the material in the ABGR format (alpha is ignored).
| u32 nnl::model::Material::emissive = 0xFF000000 |
Emissive color of the material in the ABGR format (alpha is ignored).
| MaterialFeatures nnl::model::Material::features {} |
Render settings for the material.
| u32 nnl::model::Material::specular = 0xFF000000 |
Specular color of the material in the ABGR format (alpha is ignored).
| f32 nnl::model::Material::specular_power = 50.0f |
Power of the specular highlight.
| i16 nnl::model::Material::texture_id = -1 |
Index of the texture; -1 indicates no texture.
| u8 nnl::model::Material::uv_animation_id = 0 |
Index of UV animation; 0 indicates no animation.
| u8 nnl::model::Material::vfx_group_id = 0 |
Identifier for the material's visual effects group. Various effects can be applied to meshes of that group by the game. For instance, in NSUNI, in character assets, a value of 1 is used to make "outline" meshes black and "silhouette" meshes (when a character runs) semi-transparent.
| struct nnl::model::Model |
Represents a 3D model with various components.
Public Attributes | |
| std::vector< Bone > | skeleton |
| bool | move_with_root = false |
| std::map< BoneIndex, glm::mat4 > | inverse_matrix_bone_table |
| std::vector< std::map< BoneTarget, BoneIndex > > | bone_target_tables |
| std::vector< TextureSwap > | texture_swaps |
| std::vector< Attachment > | attachments |
| std::vector< UVAnimation > | uv_animations |
| std::vector< MeshGroup > | mesh_groups |
| std::vector< Material > | materials |
| std::vector<Attachment> nnl::model::Model::attachments |
A collection of attachment configs for external objects.
| std::vector<std::map<BoneTarget, BoneIndex> > nnl::model::Model::bone_target_tables |
An optional collection of bone target tables. Each table maps generic numeric IDs to concrete bone indices, enabling the game to target specific bones. For example, this allows the game to identify which bone corresponds to the right hand for attaching effects. There are at most 2 such tables present in game assets. 1 table is usually present in character assets. 2 tables are sometimes used in effect assets.
| std::map<BoneIndex, glm::mat4> nnl::model::Model::inverse_matrix_bone_table |
A table that maps bone indices to their inverse bind matrices. An entry is required only if a mesh is attached to that bone. The matrix may be a simple inverse or combined with scaling and other transformations - this is often the case when positions are stored as normalized integers.
| std::vector<Material> nnl::model::Model::materials |
A collection of materials used by the model. This vector must contain at least one material.
| std::vector<MeshGroup> nnl::model::Model::mesh_groups |
A collection of mesh groups with meshes that make up the model. Typically, there is at least one mesh group.
| bool nnl::model::Model::move_with_root = false |
Indicates whether the model should be repositioned in the world when the root bone is moved by an animation.
| std::vector<Bone> nnl::model::Model::skeleton |
Array of bones that define the skeleton. It must contain at least one bone. This array may be derived from a preorder traversal of a skeletal tree hierarchy.
| std::vector<TextureSwap> nnl::model::Model::texture_swaps |
A collection of texture swaps that may be used in animations.
| std::vector<UVAnimation> nnl::model::Model::uv_animations |
A vector of UV animations for the model. This vector must contain at least one default entry.
| struct nnl::model::ConvertParam |
Parameters for converting a simplified mesh to the in-game format.
Public Attributes | |
| CompLvl | compress_lvl = CompLvl::kMedium |
| u32 | force_vertex_format = 0 |
| bool | indexed = true |
| bool | use_bbox = false |
| bool | optimize_weights = false |
| bool | use_strips = true |
| Specifies whether to use triangles or triangle strips. | |
| bool | stitch_strips = true |
| bool | join_submeshes = true |
| CompLvl nnl::model::ConvertParam::compress_lvl = CompLvl::kMedium |
The level of compression to apply to vertex data.
| u32 nnl::model::ConvertParam::force_vertex_format = 0 |
If not 0, this value forces the specified vertex format. Otherwise, the format is determined by compress_lvl and the attributes used by the source mesh.
| bool nnl::model::ConvertParam::indexed = true |
Indicates whether the converted mesh should use indexed rendering.
| bool nnl::model::ConvertParam::join_submeshes = true |
Specifies whether to reduce the number of SubMeshes by joining some of them. This may reduce the number of draw calls.
| bool nnl::model::ConvertParam::optimize_weights = false |
Only for NSUNI! Excludes weights from vertex data in a few cases
| bool nnl::model::ConvertParam::stitch_strips = true |
Indicates whether to stitch triangle strips using 0 area triangles.
| bool nnl::model::ConvertParam::use_bbox = false |
Specifies if a BBox should be generated and used for the mesh.
| bool nnl::model::ConvertParam::use_strips = true |
Specifies whether to use triangles or triangle strips.
|
strong |
Enum representing compression levels for mesh conversion.
This enum defines the levels of compression applied to vertex attributes when converting from a simplified mesh to the in-game Mesh format. The selected compression level affects the size and quality of the resulting mesh.
|
strong |
Enumeration of material features used in rendering.
This enum defines various flags that activate certain features in the rendering system.
| Enumerator | |
|---|---|
| kNone | No material flags are set. |
| kVertexColors | To use vertex colors with kLit enabled, you should also enable this option. In other cases, vertex colors (if present) will be applied regardless of this flag. Vertex colors replace the ambient component of the material. |
| kLit | Enables diffuse, specular, and emissive components of the material. The first two depend on external lights. The ambient color also becomes dependent on the global ambient light. Without this flag, only a texture, vertex colors or the ambient component are used (an unshaded material). Normals must be present in the vertex data if this flag is set.
|
| kProjectionMapping | Changes the way a texture is projected onto the mesh. This mode rotates it towards the camera. Also, it disables depth writing (not depth testing). The way the projection looks depends on normals, which must be present in the vertex data if this flag is set. |
| kAdditiveBlending | The blend equation is set to add the source and destination pixel values together making the output pixels look brighter. |
| kSubtractiveBlending | The blend equation is set to subtract colors of the object being rendered from the previously drawn fragments making them look darker. |
| kNoDepthWriteDefer | Disables depth writing for this mesh. Note that depth testing is still performed. It also causes a mesh to be rendered later (sometimes after other models). This flag is used for proper alpha blending. |
| kAlphaClip | Discards rendering of any pixels that are less than 50% opaque and makes other pixels fully opaque. |
| kSkinning |
|
| kEnvironmentMapping | Changes the way a texture is projected onto the mesh. Makes it dependent on the cel_shadow_light_direction. Also, it disables depth writing. The way the projection looks depends on normals, which must be present in the vertex data if this flag is set.
|
|
strong |
Enumeration of supported primitive types.
This enum defines various primitive types that can be used in models. Each value in this enumeration maps directly to the corresponding values used by the GE. This library primarily works with triangles, making the kTriangles, kTriangleStrip types particularly relevant. The other types are included for completeness and potential use. However, they are ignored by functions that convert between a simple model representation and the in-game format.
|
strong |
Specifies the different modes of UV animation for textures.
Each mode can be used to create unique visual effects, such as flowing water or moving leaves.
| Enumerator | |
|---|---|
| kNone | No shifting occurs, but the animation can still be affected by an action config or the game. In that case, UVAnimation can serve as a placeholder to be targeted. |
| kContinuousShift | In this mode, the u_shift and v_shift values are added to UV coordinates every frame. The following formulas can be used to calculate the absolute u and v translation values: |
| kRangedShift | In this mode, the UV coordinates are shifted in a circular manner. The u_shift and v_shift define the radius of a shape, and a full shifting cycle takes num_frames (which must be > 0). This can be used to imitate leaf movement. |
| kFramedShift | In this mode, the u_shift and v_shift values are added to UV coordinates every nth frame (set with num_frames). This can be used to create short animations with sprite sheets. |
| Model nnl::model::Convert | ( | SModel && | smodel, |
| const ConvertParam & | mesh_params = {}, | ||
| bool | move_with_root = false ) |
Converts a simplified model representation to the in-game format.
This function transforms an SModel into a Model.
| smodel | The simplified model representation to be converted. |
| mesh_params | Parameters for mesh conversion. |
| move_with_root | A boolean flag indicating whether the model should move with the root bone. |
| Model nnl::model::Convert | ( | SModel && | smodel, |
| const std::vector< ConvertParam > & | mesh_params, | ||
| bool | move_with_root = false ) |
Converts a simplified model representation to the in-game format.
This function transforms an SModel into a Model.
| smodel | The simplified model representation to be converted. |
| mesh_params | Parameters for each individual mesh conversion. |
| move_with_root | A boolean flag indicating whether the model should move with the root bone. |
| Model nnl::model::Import | ( | BufferView | buffer | ) |
Parses a binary file and converts it to a structured model.
This function takes a binary representation of a model, parses its contents, and converts them into a Model struct for easier access and manipulation.
| buffer | The file buffer to be processed. |
| bool nnl::model::IsOfType | ( | BufferView | buffer | ) |
Tests if the provided file is a model.
This function takes data representing a file and checks whether it corresponds to the in-game model format.
| buffer | The file buffer to be tested. |
|
constexpr |
Maximum number of bones that can influence a single primitive and a single vertex.
This constant defines the upper limit of bone influences that can be applied to a single vertex and a single primitive. It is set to 8 because the GE can only hold 8 bone matrices in memory at a time when drawing primitives. As the result, a model must be split into submeshes to be drawn.