Project Alice
Loading...
Searching...
No Matches
xac.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <stddef.h>
5#include <string>
6#include <vector>
7#include "parsers.hpp"
8
9namespace emfx {
11 unknown_0 = 0,
12 mesh = 1,
13 skinning = 2,
14 material_3 = 3,
15 unknown_4 = 4,
16 material = 5,
17 metadata = 7,
18 node_hierachy = 11,
19 material_block = 13,
20 count
21};
22
24 float x = 0.f;
25 float y = 0.f;
26};
28 float x = 0.f;
29 float y = 0.f;
30 float z = 0.f;
31};
33 float x = 0.f;
34 float y = 0.f;
35 float z = 0.f;
36 float w = 0.f;
37};
39 float r = 0.f;
40 float g = 0.f;
41 float b = 0.f;
42 float a = 0.f;
43};
45 float r = 0.f;
46 float g = 0.f;
47 float b = 0.f;
48};
49struct xac_mat4x4 {
50 float m[16] = { 0.f };
51};
52
53//post-parse data
55 std::vector<uint32_t> indices;
56 std::vector<uint32_t> bone_ids;
57 int32_t material_id = -1;
60};
62 float weight = 0.f;
63 int32_t bone_id = -1;
64};
66 std::vector<xac_vector4f> weights;
67 std::vector<xac_vector3f> vertices;
68 std::vector<xac_vector3f> normals;
69 std::vector<xac_vector2f> texcoords;
70 std::vector<xac_pp_bone_influence> influences;
71 std::vector<xac_pp_actor_submesh> submeshes;
72 std::vector<uint32_t> influence_indices;
73 std::vector<uint32_t> influence_starts;
74 std::vector<uint32_t> influence_counts;
75};
77 std::string name;
78 std::vector<xac_pp_actor_mesh> meshes;
84 int32_t parent_id = -1;
85 int32_t collision_mesh = -1;
86 int32_t visual_mesh = -1;
87};
89 none = 0,
90 diffuse = 2,
91 specular = 3
92};
94 std::string texture;
95 float amount = 0.f;
96 float u_offset = 0.f;
97 float v_offset = 0.f;
98 float u_tiling = 0.f;
99 float v_tiling = 0.f;
100 float rotation = 0.f; //radians?
101 int16_t material_id = -1;
103};
105 std::string name;
106 std::vector<xac_pp_actor_material_layer> layers;
111 float shine = 1.f;
112 float shine_strength = 1.f;
113 float opacity = 1.f;
114 float ior = 1.f;
115 bool double_sided = false;
116 bool wireframe = false;
117};
119 std::vector<xac_pp_actor_node> root_nodes;
120 std::vector<xac_pp_actor_node> nodes;
121 std::vector<xac_pp_actor_material> materials;
122 uint32_t max_standard_materials = 0; // Normal standard materials (diffuse, ambient, normal, etc)
123 uint32_t max_fx_materials = 0; // Especial effect materials (smoke, fire, glow, etc)
124 bool ignore_length = false; // Length of chunks sometimes doesn't align with their true size
125};
126
127template<typename T>
128T parse_xac_any_binary(const char** start, const char* end, parsers::error_handler& err) {
129 if(*start + sizeof(T) >= end) {
130 err.accumulated_errors += "buffer overflow access! (" + err.file_name + ")\n";
131 return T{};
132 }
133 T obj = *reinterpret_cast<const T*>(*start);
134 *start += sizeof(T);
135 return obj;
136}
137
138const char* parse_xac_cstring(const char* start, const char* end, parsers::error_handler& err);
139const char* parse_xac_cstring_nodiscard(std::string& out, const char* start, const char* end, parsers::error_handler& err);
140
143 int32_t reposition_node = 0;
146 uint8_t unused[2] = { 0 };
148};
149
154};
155
161 float shine = 1.f;
162 float shine_strength = 1.f;
163 float opacity = 1.f;
164 float ior = 1.f;
165 bool double_sided = false;
166 bool wireframe = false;
169};
171 float amount = 1.f;
172 float u_offset = 0.f;
173 float v_offset = 0.f;
174 float u_tiling = 0.f;
175 float v_tiling = 0.f;
176 float rotation = 0.f; //radians?
177 int16_t material_id = -1;
180};
181
185};
191 float unused[3] = { 0 };
192 uint32_t unknown[2] = { 0 };
193 int32_t parent_id = -1;
197 float importance_factor = 0.f;
198};
199
201 int32_t node_id = -1;
208 uint8_t unused[3] = { 0 };
209 // vertex blocks[vertex_block_count]
210};
216 uint8_t unused[2] = { 0, 0 };
217 // data[size * count];
218};
220 vertex = 0,
221 normal = 1,
222 weight = 2,
223 texcoord = 3,
224 color32 = 4,
226 color128 = 6,
227 count
228};
232 int32_t material_id = -1;
234};
235
237 int32_t node_id = -1;
241 uint8_t unused[3] = { 0, 0, 0 };
242 // vertex blocks[vertex_block_count]
243};
245 float weight = 0.f;
246 int16_t bone_id = -1;
247 uint8_t unused[2] = { 0 };
248};
252};
253
255 uint8_t ident[4] = { 'X', 'A', 'C', ' ' };
260};
265 // data[len]
266};
267
268void parse_xac(xac_context& context, const char* start, const char* end, parsers::error_handler& err);
269void finish(xac_context& context);
270}
std::string accumulated_errors
Definition: parsers.hpp:62
std::string file_name
Definition: parsers.hpp:61
Definition: xac.cpp:264
T parse_xac_any_binary(const char **start, const char *end, parsers::error_handler &err)
Definition: xac.hpp:128
void parse_xac(xac_context &context, const char *start, const char *end, parsers::error_handler &err)
Definition: xac.cpp:579
const char * parse_xac_cstring(const char *start, const char *end, parsers::error_handler &err)
Definition: xac.cpp:265
void finish(xac_context &context)
Definition: xac.cpp:670
xac_chunk_type
Definition: xac.hpp:10
xac_pp_material_map_type
Definition: xac.hpp:88
const char * parse_xac_cstring_nodiscard(std::string &out, const char *start, const char *end, parsers::error_handler &err)
Definition: xac.cpp:270
xac_vertex_block_v1_type
Definition: xac.hpp:219
uint uint32_t
uchar uint8_t
uint32_t version
Definition: xac.hpp:264
uint32_t max_standard_materials
Definition: xac.hpp:122
std::vector< xac_pp_actor_material > materials
Definition: xac.hpp:121
std::vector< xac_pp_actor_node > root_nodes
Definition: xac.hpp:119
uint32_t max_fx_materials
Definition: xac.hpp:123
std::vector< xac_pp_actor_node > nodes
Definition: xac.hpp:120
bool ignore_length
Definition: xac.hpp:124
uint8_t major_version
Definition: xac.hpp:256
uint8_t multiply_order
Definition: xac.hpp:259
uint8_t big_endian
Definition: xac.hpp:258
uint8_t minor_version
Definition: xac.hpp:257
uint8_t ident[4]
Definition: xac.hpp:255
float m[16]
Definition: xac.hpp:50
xac_color_rgba emissive_color
Definition: xac.hpp:160
xac_color_rgba ambient_color
Definition: xac.hpp:157
xac_color_rgba diffuse_color
Definition: xac.hpp:158
xac_color_rgba specular_color
Definition: xac.hpp:159
xac_pp_material_map_type map_type
Definition: xac.hpp:102
std::vector< xac_pp_actor_material_layer > layers
Definition: xac.hpp:106
xac_color_rgba emissive_color
Definition: xac.hpp:110
xac_color_rgba specular_color
Definition: xac.hpp:109
xac_color_rgba ambient_color
Definition: xac.hpp:107
xac_color_rgba diffuse_color
Definition: xac.hpp:108
std::vector< uint32_t > influence_starts
Definition: xac.hpp:73
std::vector< xac_pp_actor_submesh > submeshes
Definition: xac.hpp:71
std::vector< xac_vector3f > vertices
Definition: xac.hpp:67
std::vector< xac_vector4f > weights
Definition: xac.hpp:66
std::vector< xac_vector2f > texcoords
Definition: xac.hpp:69
std::vector< uint32_t > influence_counts
Definition: xac.hpp:74
std::vector< xac_vector3f > normals
Definition: xac.hpp:68
std::vector< uint32_t > influence_indices
Definition: xac.hpp:72
std::vector< xac_pp_bone_influence > influences
Definition: xac.hpp:70
std::vector< xac_pp_actor_mesh > meshes
Definition: xac.hpp:78
std::string name
Definition: xac.hpp:77
xac_vector3f scale
Definition: xac.hpp:82
xac_vector3f position
Definition: xac.hpp:81
xac_vector4f rotation
Definition: xac.hpp:79
xac_vector4f scale_rotation
Definition: xac.hpp:80
xac_mat4x4 transform
Definition: xac.hpp:83
int32_t visual_mesh
Definition: xac.hpp:86
int32_t collision_mesh
Definition: xac.hpp:85
std::vector< uint32_t > indices
Definition: xac.hpp:55
uint32_t vertex_offset
Definition: xac.hpp:59
std::vector< uint32_t > bone_ids
Definition: xac.hpp:56
Definition: xac.hpp:244
float weight
Definition: xac.hpp:245
uint8_t unused[2]
Definition: xac.hpp:247
int16_t bone_id
Definition: xac.hpp:246