From 80ffa1d4b9436c6cd0a71089434f8c2acf738b16 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Wed, 25 Dec 2019 23:06:40 +0200 Subject: [PATCH] fixed the mesh loader --- tools/ropesim/src/main.c | 10 ++++++++-- tools/ropesim/src/meshload.c | 45 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/tools/ropesim/src/main.c b/tools/ropesim/src/main.c index bb5e5c5..bfd6424 100644 --- a/tools/ropesim/src/main.c +++ b/tools/ropesim/src/main.c @@ -108,7 +108,7 @@ void display(void) {0.5, 0.3, 0.2, 1}, {0.2, 0.3, 0.2, 1} }; - int i; + int i, count; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -123,7 +123,13 @@ void display(void) glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, lcol[i]); } - cmesh_draw(scn); + count = cmesh_submesh_count(scn); + for(i=0; imNumMeshes); for(i=0; i<(int)aiscn->mNumMeshes; i++) { - add_mesh(mesh, aiscn->mMeshes[i]); + if(aiscn->mRootNode->mNumChildren) { + ainode = find_node(aiscn->mRootNode, i); + } else { + ainode = 0; + } + add_mesh(mesh, aiscn->mMeshes[i], ainode); } aiReleaseImport(aiscn); return 0; } -static int add_mesh(struct cmesh *mesh, struct aiMesh *aim) +static int add_mesh(struct cmesh *mesh, struct aiMesh *aim, const struct aiNode *ainode) { int i, j, voffs, foffs; + const char *name; + + if(ainode && ainode->mName.length > 0) { + name = ainode->mName.data; + } else { + name = aim->mName.data; + } + printf("adding mesh: %s\n", name); voffs = cmesh_attrib_count(mesh, CMESH_ATTR_VERTEX); foffs = cmesh_poly_count(mesh); @@ -82,7 +98,26 @@ static int add_mesh(struct cmesh *mesh, struct aiMesh *aim) cmesh_push_index(mesh, aim->mFaces[i].mIndices[j] + voffs); } } - cmesh_submesh(mesh, aim->mName.data, foffs, aim->mNumFaces); + cmesh_submesh(mesh, name, foffs, aim->mNumFaces); + } + return 0; +} + +static struct aiNode *find_node(struct aiNode *node, unsigned int midx) +{ + unsigned int i; + struct aiNode *n; + + for(i=0; imNumMeshes; i++) { + if(node->mMeshes[i] == midx) { + return node; + } + } + + for(i=0; imNumChildren; i++) { + if((n = find_node(node->mChildren[i], midx))) { + return n; + } } return 0; } -- 1.7.10.4