From 15543a7b91359333e204cbff6641b01f0d24e9fe Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Sat, 4 Nov 2023 22:13:43 +0000 Subject: [PATCH] Add texture support to models --- assets/cube.bin | Bin 876 -> 1020 bytes model-conv.py | 40 ++++++++++++++++++++++++++++++++++++---- model.cpp | 9 ++++++++- model.hpp | 3 ++- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/assets/cube.bin b/assets/cube.bin index 2a90295f77f79f5f5134bcadc00692bfd27a5310..3ac7bcf1f8e7bbdd2f291acd8a41e91fabea93a2 100644 GIT binary patch literal 1020 zcmaiy%MpVx3`9*Oxuk;>z)U8`^x#sU6H1|!l%i<$v1AC&!2`@=S1ZZS_v1B{Qto_8 zA@W0bEz`>1A6mfhm-56mWv-j}kEENS8?lk6v(9rP@jNoFvQT2+t`k;Ocg&(Xq&(-$ zO#QAs&-H$JVw&u_$%tewp)*#4X;#d$>2}fcfJbcP3C51$SxG!qp0={dA^&OJ$#$>uHAi^wKK3m z!Lyl5-~4pculUMGy!uq`DGnq8=Vo2;TKA6ceD3`<9nL28GiN5`{Ex4Ez~M6bP%Ex( zGY|F2rPrJ}P0bQ-{E>QmXWc8WdTLQWR@~KiU%xnOT=grSd6d59PaeIXpIDLP#IyG0 Q4#DUAQ11E8Cv(c@3%K1? + + # convert data pos = np.floor(pos * (1 << 16)).astype(int) nor = np.floor(nor * 0x7FFF).astype(int) col = np.floor(colour_data[i] * 0xFF).astype(int) + tex_coord = np.floor(tex_coord * 0xFFFF).astype(int) - packed_vertex = struct.pack('<3i4B3hxx', + packed_vertex = struct.pack('<3i4B3h2Hxx', pos[0], pos[1], pos[2], - col[0], col[1], col[2], col[3], - nor[0], nor[1], nor[2]) + col[0], col[1], col[2], tex_id, + nor[0], nor[1], nor[2], + tex_coord[0], tex_coord[1]) out_vertices.append(packed_vertex) diff --git a/model.cpp b/model.cpp index d64d96e..ceeb927 100644 --- a/model.cpp +++ b/model.cpp @@ -44,7 +44,14 @@ void model_lit_shader(const uint8_t *in, Render3D::VertexOutData *out, const Ren out->g = int32_t(dot * vertex->g); out->b = int32_t(dot * vertex->b); - out->tex_index = 0; + out->tex_index = vertex->tex_index; + + if(vertex->tex_index) + { + // close enough (should be / 65535) + out->u = Fixed16<12>(Fixed32<>::from_raw(vertex->u)); + out->v = Fixed16<12>(Fixed32<>::from_raw(vertex->v)); + } } Model::Model(const uint8_t *asset_data) diff --git a/model.hpp b/model.hpp index 928d7bb..4346c8f 100644 --- a/model.hpp +++ b/model.hpp @@ -11,8 +11,9 @@ class Model final struct Vertex { uint32_t x, y, z; - uint8_t r, g, b, a; + uint8_t r, g, b, tex_index; int16_t nx, ny, nz; + uint16_t u, v; uint16_t pad; };