You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 12, 2025. It is now read-only.
The face format is shared between triangles and quads. The `face_t` structure contains UV coordinates and vertex indices. Here’s how the data is laid out:
166
+
167
+
```c
168
+
typedef struct {
169
+
uint8_t au;
170
+
uint8_t av;
171
+
uint8_t bu;
172
+
uint8_t bv;
173
+
uint8_t cu;
174
+
uint8_t cv;
175
+
uint8_t du; // Unused for triangles
176
+
uint8_t dv; // Unused for triangles
177
+
uint32_t indices; // Encodes vertex indices and material information
178
+
} face_t;
179
+
```
180
+
181
+
#### Field Details:
182
+
183
+
-**UV Coordinates**: The first 8 bytes (au, av, bu, bv, cu, cv, du, dv) represent texture mapping coordinates. These UV values are 8-bit unsigned integers and reference pixels in a 256x256 texture space.
184
+
- For triangles, `du` and `dv` are unused.
185
+
- For quads, all UV values are used.
186
+
187
+
-**Vertex Indices**: The `indices` field contains vertex indices and material information:
188
+
-**Bits 0–6**: Vertex index for `a`.
189
+
-**Bits 7–13**: Vertex index for `b`.
190
+
-**Bits 14–20**: Vertex index for `c`.
191
+
-**Bits 21–27**: Vertex index for `d` (unused for triangles).
192
+
-**Bits 28–29**: Material information, which can have one of four values:
193
+
-`0b00`: Megaman’s body texture.
194
+
-`0b01`: Megaman’s body texture with a different palette.
195
+
-`0b10`: Megaman’s face texture.
196
+
-`0b11`: Megaman’s face texture with a different palette (used for special weapons).
197
+
198
+
#### UV Coordinate Conversion
199
+
200
+
The UV coordinates are stored as integers but need to be converted to floating-point values for rendering. The texture space is 256x256, so the following formula converts the UVs to normalized floating-point values:
201
+
202
+
```
203
+
u_float = (u_int * 1/256) + 0.001953125
204
+
v_float = (v_int * 1/256) + 0.001953125
205
+
```
206
+
207
+
#### Code Example
208
+
209
+
```c
210
+
#include<stdint.h>
211
+
#include<stdio.h>
212
+
213
+
#definePIXEL_TO_FLOAT_RATIO 0.00390625f
214
+
#define PIXEL_ADJUSTMENT 0.001953125f
215
+
#define FACE_MASK 0x7F
216
+
217
+
// Structure to hold decoded face data
218
+
typedefstruct {
219
+
float u, v; // UV coordinates
220
+
uint8_t index; // Vertex index
221
+
uint8_t materialIndex; // Material information
222
+
} Vertex;
223
+
224
+
typedefstruct {
225
+
Vertex a, b, c, d; // Vertices for a face
226
+
uint8_t isQuad; // 1 if quad, 0 if triangle
227
+
} Face;
228
+
229
+
// Function to decode UV coordinates and vertex indices from a face_t structure
0 commit comments