I'm having trouble putting the data inside a wavefront .obj file together.
These are the vec3 and vec2 definitions
template <typename T>
struct vec3 {
T x;
T y;
T z;
};
template <typename T>
struct vec2 {
T x;
T y;
};
Used in a vector:
+-----------------------------------+--------------+--------------+-------+
| std::vector<vec3<uint32_t>> f_vec | 0 | 1 | (...) |
+-----------------------------------+--------------+--------------+-------+
| | v_vec_index | v_vec_index | (...) |
| +--------------+--------------+-------+
| | vt_vec_index | vt_vec_index | (...) |
| +--------------+--------------+-------+
| | vn_vec_index | vn_vec_index | (...) |
+-----------------------------------+--------------+--------------+-------+
Where:
v_vec_indexis an index ofstd::vector<vec3<float>> v_vecwith its fields containing vertex x, y and z coordinatesvt_vec_indexis an index ofstd::vector<vec2<float>> vt_veccontaining texture u and v coordinatesvn_vec_indexis an index ofstd::vector<vec3<float>> vn_vecwith normal x, y and z coordinates
Every f_vec field is used to create a sequence of vert_x, vert_y, vert_z, tex_u, tex_v, norm_x, norm_y, norm_z float values inside std::vector<float> vertex_array.
Also, every index of f_vec's field is by default a value of std::vector<uint32_t>> element_array - that is it contains the range of integers from 0 to f_vec.size() - 1.
The problem is vec3 fields inside f_vec may repeat. So in order to assemble only the unique sequences mentioned above I planned to turn something like this:
+-----------------+---+---+---+---+---+
| f_vec | 0 | 1 | 2 | 3 | 4 |
+-----------------+---+---+---+---+---+
| | 1 | 3 | 1 | 3 | 4 |
| +---+---+---+---+---+
| | 2 | 2 | 2 | 2 | 5 |
| +---+---+---+---+---+
| | 2 | 4 | 2 | 4 | 5 |
+-----------------+---+---+---+---+---+
Into this:
+------------------------+-----------------+---+---+---+---+---+
| whatever that would be | index | 0 | 1 | 2 | 3 | 4 |
+------------------------+-----------------+---+---+---+---+---+
| | key | 0 | 1 | 0 | 1 | 2 |
| +-----------------+---+---+---+---+---+
| | | 1 | 3 | 1 | 3 | 4 |
| | +---+---+---+---+---+
| | vec3 of indices | 2 | 2 | 2 | 2 | 5 |
| | +---+---+---+---+---+
| | | 2 | 4 | 2 | 4 | 5 |
+------------------------+-----------------+---+---+---+---+---+
Where every time an element of f_vec would be put into the "whatever container"
It would be checked if it is unique
If it is then it would be pushed to the end of the
containerwith its key being the next natural number after the biggest key - the key's value would be pushed to theelement_arrayand new vertex would be created insidevertex_array- If it isn't then it would be pushed to the end of the
containerwith its key being the same as the key of its duplicate - the key's value would be pushed to theelement_arraybutvertex_arraywould remain unchanged
How am I supposed to do it?