diff options
author | sanine <sanine.not@pm.me> | 2022-09-22 01:02:12 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-09-22 01:02:12 -0500 |
commit | db0bc36c52a223f96bf0b517ef1053ba6b6b16d9 (patch) | |
tree | 4ae5d7c4c76a4d2a08dde9fa8f3f0b8b533c89e8 /src/import/import.c | |
parent | 7f5d38aaf8cf7a067d1dce677b33f8b597f6a974 (diff) |
add uv loading
Diffstat (limited to 'src/import/import.c')
-rw-r--r-- | src/import/import.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/import/import.c b/src/import/import.c index 73075d4..d58de0f 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -42,6 +42,8 @@ void push_aistring(lua_State *L, struct aiString str) * mNumVertices * mTangents * mVertices + * mNumUVComponents + * mTextureCoords * * TODO: * mAnimMeshes @@ -52,9 +54,7 @@ void push_aistring(lua_State *L, struct aiString str) * mName * mNumAnimMeshes * mNumBones - * mNumUVComponents * mPrimitiveTypes - * mTextureCoords * mTextureCoordsNames */ void push_mesh(lua_State *L, struct aiMesh mesh) @@ -92,6 +92,33 @@ void push_mesh(lua_State *L, struct aiMesh mesh) pop_count += 2; } + /* uvs */ + int uvs = 0; + int uv_components = 0; + int uv_channels[AI_MAX_NUMBER_OF_TEXTURECOORDS]; + for (int i=0; i<AI_MAX_NUMBER_OF_TEXTURECOORDS; i++) { + if (mesh.mTextureCoords[i] != NULL) { + if (!uvs) { + /* ensure uv table is created */ + lua_createtable(L, 1, 0); + uvs = lua_gettop(L); + lua_createtable(L, 1, 0); + uv_components = lua_gettop(L); + pop_count += 2; + } + lua_createtable(L, count, 0); + uv_channels[i] = lua_gettop(L); + pop_count += 1; + + /* store table in uvs */ + lua_pushvalue(L, uv_channels[i]); + lua_rawseti(L, uvs, i+1); + /* store dimensionality */ + lua_pushinteger(L, mesh.mNumUVComponents[i]); + lua_rawseti(L, uv_components, i+1); + } + } + /* --=== populate vertices ===-- */ for (int i=0; i<count; i++) { @@ -112,6 +139,16 @@ void push_mesh(lua_State *L, struct aiMesh mesh) push_vector(L, mesh.mBitangents[i]); lua_rawseti(L, bitangents, i+1); } + + /* uvs */ + if (uvs) { + for (int j=0; j<AI_MAX_NUMBER_OF_TEXTURECOORDS; j++) { + if (uv_channels[j]) { + push_vector(L, mesh.mTextureCoords[j][i]); + lua_rawseti(L, uv_channels[j], i+1); + } + } + } } /* --=== populate faces ===-- */ @@ -149,6 +186,13 @@ void push_mesh(lua_State *L, struct aiMesh mesh) lua_setfield(L, meshtbl, "faces"); } + if (uvs) { + lua_pushvalue(L, uvs); + lua_setfield(L, meshtbl, "uvs"); + lua_pushvalue(L, uv_components); + lua_setfield(L, meshtbl, "numUvComponents"); + } + /* --=== clean up ===-- */ lua_pop(L, pop_count); } |