summaryrefslogtreecommitdiff
path: root/src/import/import.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/import/import.c')
-rw-r--r--src/import/import.c54
1 files changed, 37 insertions, 17 deletions
diff --git a/src/import/import.c b/src/import/import.c
index 8852c81..306601e 100644
--- a/src/import/import.c
+++ b/src/import/import.c
@@ -33,6 +33,8 @@ static void push_aistring(lua_State *L, struct aiString str)
}
+#ifndef TEST_IMPORT_SCENE
+
/* mesh components:
* DONE:
* mBitangents
@@ -57,13 +59,13 @@ static void push_aistring(lua_State *L, struct aiString str)
* mPrimitiveTypes
* mTextureCoordsNames
*/
-static void push_mesh(lua_State *L, struct aiMesh mesh)
+static void push_mesh(lua_State *L, struct aiMesh *mesh)
{
/* --=== create mesh table ===-- */
lua_createtable(L, 0, 1);
int meshtbl = lua_gettop(L);
- int count = mesh.mNumVertices;
+ int count = mesh->mNumVertices;
int pop_count = 0;
/* --=== create tables ===-- */
@@ -75,7 +77,7 @@ static void push_mesh(lua_State *L, struct aiMesh mesh)
/* normals */
int normals = 0;
- if (mesh.mNormals != NULL) {
+ if (mesh->mNormals != NULL) {
lua_createtable(L, count, 0);
normals = lua_gettop(L);
pop_count += 1;
@@ -84,7 +86,7 @@ static void push_mesh(lua_State *L, struct aiMesh mesh)
/* tangents & bitangents */
int tangents = 0;
int bitangents = 0;
- if (mesh.mTangents != NULL) {
+ if (mesh->mTangents != NULL) {
lua_createtable(L, count, 0);
tangents = lua_gettop(L);
lua_createtable(L, count, 0);
@@ -97,7 +99,7 @@ static void push_mesh(lua_State *L, struct aiMesh mesh)
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 (mesh->mTextureCoords[i] != NULL) {
if (!uvs) {
/* ensure uv table is created */
lua_createtable(L, 1, 0);
@@ -114,7 +116,7 @@ static void push_mesh(lua_State *L, struct aiMesh mesh)
lua_pushvalue(L, uv_channels[i]);
lua_rawseti(L, uvs, i+1);
/* store dimensionality */
- lua_pushinteger(L, mesh.mNumUVComponents[i]);
+ lua_pushinteger(L, mesh->mNumUVComponents[i]);
lua_rawseti(L, uv_components, i+1);
}
}
@@ -123,20 +125,20 @@ static void push_mesh(lua_State *L, struct aiMesh mesh)
for (int i=0; i<count; i++) {
/* positions */
- push_vector(L, mesh.mVertices[i]);
+ push_vector(L, mesh->mVertices[i]);
lua_rawseti(L, vertices, i+1);
/* normals */
if (normals) {
- push_vector(L, mesh.mNormals[i]);
+ push_vector(L, mesh->mNormals[i]);
lua_rawseti(L, normals, i+1);
}
/* tangents */
if (tangents) {
- push_vector(L, mesh.mTangents[i]);
+ push_vector(L, mesh->mTangents[i]);
lua_rawseti(L, tangents, i+1);
- push_vector(L, mesh.mBitangents[i]);
+ push_vector(L, mesh->mBitangents[i]);
lua_rawseti(L, bitangents, i+1);
}
@@ -144,7 +146,7 @@ static void push_mesh(lua_State *L, struct aiMesh mesh)
if (uvs) {
for (int j=0; j<AI_MAX_NUMBER_OF_TEXTURECOORDS; j++) {
if (uv_channels[j]) {
- push_vector(L, mesh.mTextureCoords[j][i]);
+ push_vector(L, mesh->mTextureCoords[j][i]);
lua_rawseti(L, uv_channels[j], i+1);
}
}
@@ -154,12 +156,12 @@ static void push_mesh(lua_State *L, struct aiMesh mesh)
/* --=== populate faces ===-- */
int faces = 0;
- if (mesh.mNumFaces != 0) {
- lua_createtable(L, mesh.mNumFaces, 0);
+ if (mesh->mNumFaces != 0) {
+ lua_createtable(L, mesh->mNumFaces, 0);
faces = lua_gettop(L);
pop_count += 1;
- for (int i=0; i<mesh.mNumFaces; i++) {
- push_face(L, mesh.mFaces[i]);
+ for (int i=0; i<mesh->mNumFaces; i++) {
+ push_face(L, mesh->mFaces[i]);
lua_rawseti(L, faces, i+1);
}
}
@@ -226,8 +228,26 @@ static void push_node(lua_State *L, struct aiNode *node)
}
}
+#endif
+
-static void push_scene(lua_State *L, struct aiNode *node)
+static void push_scene(lua_State *L, struct aiScene *scene)
{
-
+ /* meshes */
+ lua_createtable(L, scene->mNumMeshes, 0);
+ int meshtbl = lua_gettop(L);
+ for (int i=0; i<scene->mNumMeshes; i++) {
+ push_mesh(L, scene->mMeshes[i]);
+ lua_rawseti(L, meshtbl, i+1);
+ }
+
+ /* nodes */
+ push_node(L, scene->mRootNode);
+ int nodetbl = lua_gettop(L);
+
+ /* scene */
+ hs_create_table(L,
+ hs_str_tbl("rootNode", nodetbl),
+ hs_str_tbl("meshes", meshtbl),
+ );
}