45#define NNL_UVANIM_MAX_DUR 1000
227 i16 original_texture_id = 0;
228 i16 new_texture_id = 0;
575Model Convert(
SModel&& smodel,
const std::vector<ConvertParam>& mesh_params,
bool move_with_root =
false);
615bool IsOfType(
const std::filesystem::path& path);
704 kRightShoulder = 0xA,
736 "Root",
"Hips",
"Spine",
"Spine1",
"Neck",
"Head",
737 "LeftShoulder",
"LeftArm",
"LeftForeArm",
"LeftHand",
"RightShoulder",
"RightArm",
738 "RightForeArm",
"RightHand",
"LeftUpLeg",
"LeftLeg",
"LeftFoot",
"RightUpLeg",
739 "RightLeg",
"RightFoot",
"BodyPart20",
"BodyPart21",
"BodyPart22",
"BodyPart23",
740 "BodyPart24",
"BodyPart25",
"BodyPart26",
"BodyPart27",
"BodyPart28",
"BodyPart29"};
782std::vector<TriangleGroup>
GroupTrianglesByBones(
const std::vector<u32>& indices,
const std::vector<SVertex>& vertices,
783 u32 max_num_triangles = std::numeric_limits<u16>::max() / 3,
784 bool join_bone_sets =
true);
877 bool is_character =
true);
984 u32 offset_bones = 0;
985 u32 offset_inverse_matrices = 0;
986 u32 offset_inverse_matrix_bone_table = 0;
987 u32 offset_mesh_groups = 0;
989 u16 num_mesh_groups = 0;
990 u16 num_inverse_matrices = 0;
991 u16 num_vfx_groups = 0;
992 u32 header_size =
sizeof(RHeader);
993 u16 move_with_root = 0;
994 u16 num_bone_target_tables = 0;
995 u32 offset_bone_target_tables = 0;
996 u16 num_attachment_matrices = 0;
997 u16 num_uv_animations = 0;
998 u32 offset_attachment_matrices = 0;
999 u32 offset_uv_animations = 0;
1001 u16 num_textures = 0;
1002 u16 num_texture_swaps = 0;
1003 u32 offset_texture_swaps = 0;
1007static_assert(
sizeof(RHeader) == 0x40);
1011 i16 parent_index = 0;
1013 Vec3<f32> translation{0.0f};
1016static_assert(
sizeof(RBone) == 0x20);
1020 u8 padding[0xE] = {0};
1021 Vec4<f32> vertices[8] = {0.0f};
1032static_assert(
sizeof(RBBox) == 0x90);
1036 u16 attachment_id = 0;
1039static_assert(
sizeof(RAttachment) == 0x4);
1042 u16 animation_mode = 0;
1049static_assert(
sizeof(RUVAnimation) == 0x10);
1053 i16 original_texture_id = 0;
1054 i16 new_texture_id = 0;
1057static_assert(
sizeof(RTextureSwap) == 0x8);
1061 u32 num_entries = 0;
1064static_assert(
sizeof(RBoneTargetHeader) == 0x8);
1071static_assert(
sizeof(RBoneTargetEntry) == 0x4);
1073struct RBoneTargetTables {
1074 std::vector<RBoneTargetHeader> header;
1075 std::vector<std::vector<RBoneTargetEntry>> entries;
1079 u32 offset_meshes = 0;
1084 f32 u_offset = 0.0f;
1085 f32 v_offset = 0.0f;
1088static_assert(
sizeof(RMeshGroup) == 0x18);
1091 u32 offset_submeshes = 0;
1092 u16 num_submeshes = 0;
1093 u16 material_features = 0;
1098 f32 specular_power = 0.0f;
1100 u16 use_bbox =
false;
1101 u32 offset_bbox = 0;
1102 u16 material_id = 0;
1105 u8 vfx_group_id = 0;
1106 u8 uv_animation_id = 0;
1109static_assert(
sizeof(RMesh) == 0x28);
1113 u16 num_primitives = 0;
1115 u32 vertex_format = 0;
1116 u32 offset_indexed_vertex_buffer = 0;
1117 u32 offset_primitives = 0;
1119 u32 offset_display_list = 0;
1122static_assert(
sizeof(RSubMesh) == 0x24);
1125 u16 primitive_type = 0;
1126 u16 num_elements = 0;
1127 u32 offset_buffer = 0;
1128 u32 buffer_size = 0;
1129 u32 ptr_vram_vertex_buffer = 0;
1132static_assert(
sizeof(RPrimitive) == 0x10);
1137 std::vector<RBone> bones;
1139 std::vector<Mat4<f32>> inverse_matrices;
1140 std::vector<RTextureSwap> texture_swaps;
1141 std::vector<u16> inverse_matrix_bone_table;
1143 RBoneTargetTables bone_target_tables;
1145 std::vector<Mat4<f32>> attachment_matrices;
1146 std::vector<RAttachment> attachments;
1148 std::vector<RUVAnimation> uv_animations;
1150 std::vector<RMeshGroup> mesh_groups;
1152 std::map<u32, std::vector<RMesh>> meshes;
1153 std::map<u32, RBBox> bboxes;
1154 std::map<u32, std::vector<RSubMesh>> submeshes;
1155 std::map<u32, std::vector<RPrimitive>> primitives;
1156 std::map<u32, std::vector<u32>> display_lists;
1157 std::map<u32, Buffer> vertex_buffers;
1159 std::map<u32, Buffer> indexed_vertex_buffers;
1163std::vector<Bone> Convert(
const std::vector<raw::RBone>& rbones);
1165Model Convert(RModel&& rmodel);
1167RModel Parse(Reader& f);
1169std::vector<raw::RBone> Convert(
const std::vector<Bone>& bones);
Contains macros for defining flag enums.
Contains macros and definitions for fixed-width types.
3D vector template with packed storage
Definition fixed_type.hpp:163
std::uint16_t u16
16-bit unsigned integer
Definition fixed_type.hpp:62
std::int16_t i16
16-bit signed integer
Definition fixed_type.hpp:63
float f32
32-bit floating point
Definition fixed_type.hpp:59
std::uint32_t u32
32-bit unsigned integer
Definition fixed_type.hpp:60
std::uint8_t u8
8-bit unsigned integer
Definition fixed_type.hpp:64
#define NNL_PACK(...)
A structure packing directive.
Definition fixed_type.hpp:41
#define NNL_DEFINE_ENUM_OPERATORS(ENUMTYPE)
Macro to define bitwise operators for enum types.
Definition enum_flag.hpp:36
#define NNL_FLAG_ENUM
An attribute for defining flag enums.
Definition enum_flag.hpp:28
utl::StaticSet< BoneIndex, kMaxNumBonePerPrim > bones
Unique bones.
Definition model.hpp:763
std::vector< u32 > indices
Triangles associated with the bones.
Definition model.hpp:764
Represents a group of triangles associated with specific bones.
Definition model.hpp:762
constexpr std::array< std::string_view, 30 > bone_target_names
An array that associates a generic bone id with a name.
Definition model.hpp:735
std::vector< std::map< BoneTarget, BoneIndex > > GenerateBoneTargetTables(const SSkeleton &skeleton)
Generates bone target tables from bone names of the skeleton.
void SetBoneNames(SSkeleton &skeleton, const std::vector< std::map< BoneTarget, BoneIndex > > &bone_target_tables, bool is_character=true)
Assigns meaningful names to bones in a skeleton.
ConvertParam GenerateConvertParam(const Mesh &mesh)
Generates a conversion parameter for SMesh to get a similar in-game Mesh when converting back to it.
std::map< BoneIndex, glm::mat4 > GenerateInverseMatrixBoneTable(const SModel &smodel)
Generates a map of bone indices and inverse matrices.
GeCmd
Enumeration of essential rendering commands for the library.
Definition model.hpp:666
std::vector< STriangle > ExtractTriangles(const SubMesh &submesh, bool skip_degenerate=true)
Extracts triangles from a given submesh.
BBox GenerateBBox(const SMesh &mesh, glm::mat4 transform=glm::mat4(1.0f))
Generates an axis-aligned bounding box (AABB) for the given mesh.
HumanoidRigTarget
Enum representing parts of a generic humanoid rig.
Definition model.hpp:693
std::vector< TriangleGroup > GroupTrianglesByBones(const std::vector< u32 > &indices, const std::vector< SVertex > &vertices, u32 max_num_triangles=std::numeric_limits< u16 >::max()/3, bool join_bone_sets=true)
Groups triangles by their associated bones.
@ kDrawPrimitives
Definition model.hpp:676
@ kSetBaseAddress
Definition model.hpp:670
@ kSetVertexType
Definition model.hpp:668
@ kSetVramAddress
Definition model.hpp:673
@ kReturn
Marks the end of the display list.
Definition model.hpp:667
bool move_with_root
Definition model.hpp:482
u32 diffuse
Definition model.hpp:443
f32 u_scale
Scale factor for the U texture coordinate.
Definition model.hpp:418
glm::vec3 min
The min coordinate.
Definition model.hpp:301
f32 v_offset
Offset for the V texture coordinate.
Definition model.hpp:421
u32 ambient
Definition model.hpp:445
Buffer indexed_vertex_buffer
Definition model.hpp:359
bool indexed
Definition model.hpp:549
u8 uv_animation_id
Definition model.hpp:451
f32 v_shift
Same as u_shift but for the v coordinate.
Definition model.hpp:260
u16 num_elements
Definition model.hpp:318
f32 u_shift
Definition model.hpp:255
bool use_strips
Specifies whether to use triangles or triangle strips.
Definition model.hpp:555
std::vector< MeshGroup > mesh_groups
Definition model.hpp:513
u32 emissive
Definition model.hpp:447
glm::vec3 rotation
Definition model.hpp:209
std::vector< UVAnimation > uv_animations
Definition model.hpp:510
glm::mat4 transform
Definition model.hpp:278
u32 vertex_format
Definition model.hpp:357
BoneIndex bone_index
Definition model.hpp:299
bool stitch_strips
Definition model.hpp:556
std::vector< std::map< BoneTarget, BoneIndex > > bone_target_tables
Definition model.hpp:492
u8 vfx_group_id
Definition model.hpp:453
bool optimize_weights
Definition model.hpp:553
i16 parent_index
An index into the array of bones; -1 means a bone has no parent.
Definition model.hpp:207
BoneIndex bone_id
Definition model.hpp:274
UVAnimationMode animation_mode
Defines how shifting occurs.
Definition model.hpp:247
std::array< BoneIndex, kMaxNumBonePerPrim > bone_indices
Definition model.hpp:365
BBox bbox
The bounding box of the mesh.
Definition model.hpp:397
std::vector< Material > materials
Definition model.hpp:516
std::map< BoneIndex, glm::mat4 > inverse_matrix_bone_table
Definition model.hpp:485
PrimitiveType primitive_type
Type of the primitive.
Definition model.hpp:317
std::vector< u32 > display_list
Definition model.hpp:370
std::vector< Mesh > meshes
Collection of meshes that belong to this group.
Definition model.hpp:417
std::vector< SubMesh > submeshes
Definition model.hpp:388
glm::vec3 scale
The scale transform.
Definition model.hpp:208
std::vector< Bone > skeleton
Definition model.hpp:479
f32 v_scale
Scale factor for the V texture coordinate.
Definition model.hpp:419
u32 force_vertex_format
Definition model.hpp:546
Buffer vertex_index_buffer
Definition model.hpp:320
f32 specular_power
Power of the specular highlight.
Definition model.hpp:449
bool use_bbox
Definition model.hpp:551
u16 num_frames
Definition model.hpp:249
glm::vec3 translation
The translation transform.
Definition model.hpp:211
u32 specular
Definition model.hpp:441
i16 texture_id
Index of the texture; -1 indicates no texture.
Definition model.hpp:450
std::vector< Primitive > primitives
List of primitives that make up this submesh.
Definition model.hpp:363
bool use_skinning
Definition model.hpp:390
f32 u_offset
Offset for the U texture coordinate.
Definition model.hpp:420
bool join_submeshes
Definition model.hpp:558
glm::vec3 max
The max coordinate.
Definition model.hpp:302
std::vector< TextureSwap > texture_swaps
Definition model.hpp:504
u16 material_id
The index of the material associated with this mesh.
Definition model.hpp:398
std::vector< Attachment > attachments
Definition model.hpp:507
u16 attachment_id
Definition model.hpp:276
MaterialFeatures features
Render settings for the material.
Definition model.hpp:457
CompLvl compress_lvl
Definition model.hpp:543
bool use_bbox
Flag indicating whether to use the bounding box.
Definition model.hpp:395
u16 num_bones
Definition model.hpp:353
Represents a UV animation configuration.
Definition model.hpp:246
This struct defines various properties of a mesh.
Definition model.hpp:387
Represents a 3D model with various components.
Definition model.hpp:478
Represents the properties of a material.
Definition model.hpp:440
Represents a configuration for texture swapping.
Definition model.hpp:226
Represents a group of meshes.
Definition model.hpp:416
Represents a bone/joint in a skeleton.
Definition model.hpp:206
Parameters for converting a simplified mesh to the in-game format.
Definition model.hpp:542
Represents a smaller part of a mesh.
Definition model.hpp:352
Represents a configuration for attaching an external object to a model.
Definition model.hpp:273
Represents the smallest unit of geometry in the hierarchy.
Definition model.hpp:316
Represents a bounding box for objects.
Definition model.hpp:298
UVAnimationMode
Specifies the different modes of UV animation for textures.
Definition model.hpp:85
Model Import(BufferView buffer)
Parses a binary file and converts it to a structured model.
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.
CompLvl
Enum representing compression levels for mesh conversion.
Definition model.hpp:529
Buffer Export(const Model &model)
Converts a model to its binary file representation.
MaterialFeatures
Enumeration of material features used in rendering.
Definition model.hpp:146
bool IsOfType(BufferView buffer)
Tests if the provided file is a model.
constexpr std::size_t kMaxNumBonePerPrim
Maximum number of bones that can influence a single primitive and a single vertex.
Definition model.hpp:76
PrimitiveType
Enumeration of supported primitive types.
Definition model.hpp:126
@ kContinuousShift
Definition model.hpp:89
@ kNone
Definition model.hpp:86
@ kFramedShift
Definition model.hpp:103
@ kRangedShift
Definition model.hpp:95
@ kMedium
Uses shorts and bytes for attributes, RGBA4444 for color.
Definition model.hpp:531
@ kMax
Definition model.hpp:532
@ kLit
Definition model.hpp:156
@ kSkinning
Definition model.hpp:182
@ kEnvironmentMapping
Definition model.hpp:185
@ kNoDepthWriteDefer
Definition model.hpp:176
@ kAlphaClip
Definition model.hpp:180
@ kAdditiveBlending
Definition model.hpp:169
@ kSubtractiveBlending
Definition model.hpp:173
@ kProjectionMapping
Definition model.hpp:164
@ kVertexColors
Definition model.hpp:150
constexpr u32 kMagicBytes
Magic bytes used to identify the model format.
Definition model.hpp:980
u16 BoneIndex
Represents a concrete bone index in a skeleton/bone array.
Definition model_common.hpp:34
u16 BoneTarget
Represents a generic bone identifier.
Definition model_common.hpp:51
A single animation track for UV coordinates.
Definition sanimation.hpp:158
Represents a simple material with various properties for 3D rendering.
Definition smodel.hpp:578
Represents a simple mesh.
Definition smodel.hpp:212
Represents a simple model.
Definition smodel.hpp:654
Represents the skeleton of a 3D model.
Definition smodel.hpp:485
Fixed-size sorted set implementation.
Definition static_set.hpp:28
Provides classes for reading and writing binary data to and from various sources.
Contains model-related definitions that are shared across different parts of the library.
Contains structures and functions for working with in-game 3D models.
Definition model.hpp:59
Definition exception.hpp:56
Provides data structures and functions for managing essential components of a 3D model.
Defines a set that is sorted and has a fixed capacity.