diff options
Diffstat (limited to 'src/import/import.c')
-rw-r--r-- | src/import/import.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/import/import.c b/src/import/import.c index cbd8d45..a4fc552 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -14,7 +14,46 @@ void push_vector(lua_State *L, struct aiVector3D vec) } +void push_face(lua_State *L, struct aiFace face) +{ + lua_createtable(L, face.mNumIndices, 0); + int tbl = lua_gettop(L); + + for (int i=0; i<face.mNumIndices; i++) { + lua_pushinteger(L, face.mIndices[i]); + lua_rawseti(L, tbl, i+1); + } +} + + void push_aistring(lua_State *L, struct aiString str) { lua_pushstring(L, str.data); } + + +void push_mesh(lua_State *L, struct aiMesh mesh) +{ + int count = mesh.mNumVertices; + + /* create tables */ + lua_createtable(L, count, 0); + int vertices = lua_gettop(L); + + /* populate */ + for (int i=0; i<count; i++) { + /* positions */ + push_vector(L, mesh.mVertices[i]); + lua_rawseti(L, vertices, i+1); + } + + /* create mesh table */ + lua_createtable(L, 0, 1); + int meshtbl = lua_gettop(L); + + lua_pushvalue(L, vertices); + lua_setfield(L, meshtbl, "vertices"); + + /* clean up */ + lua_remove(L, vertices); +} |