diff --git a/qglengine/formats/loader_assimp.cpp b/qglengine/formats/loader_assimp.cpp index 1544280..13d3ed6 100644 --- a/qglengine/formats/loader_assimp.cpp +++ b/qglengine/formats/loader_assimp.cpp @@ -143,33 +143,36 @@ Light * assimpLight(const aiLight * l) { } -ObjectBase * assimpObject(const aiNode * n, const QVector & meshes, aiMesh ** ai_meshes, +ObjectBaseList assimpObject(const aiNode * n, const QVector & meshes, aiMesh ** ai_meshes, const QVector & materials, const QMap & light_by_name, QVector & out_lights) { - if (!n) return 0; - ObjectBase * ret = 0; + if (!n) return ObjectBaseList(); + ObjectBaseList ret; + ObjectBase * obj = 0; QString name = n->mName.C_Str(); Light * light = light_by_name.value(name, 0); if (light) { - ret = light->clone(); - out_lights << (Light*)ret; + obj = light->clone(); + out_lights << (Light*)obj; } else - ret = new ObjectBase(); - ret->setName(name); - ret->setMatrix(fromAiMatrix4D(n->mTransformation)); + obj = new ObjectBase(); + obj->setName(name); + obj->setMatrix(fromAiMatrix4D(n->mTransformation)); + ret << obj; //qDebug() << "add object" << ret << ret->name(); if (!light) { //qDebug() << name << "has" << n->mNumMeshes << "meshes"; for (uint i = 0; i < n->mNumMeshes; ++i) { int mi = n->mMeshes[i]; if (meshes[mi]) { - if (!ret->mesh()) { - ret->setMesh(new Mesh()); - int mati = ai_meshes[mi]->mMaterialIndex; - if (mati >= 0 || mati < materials.size()) - ret->setMaterial(materials[mati]); + if (obj->mesh()) { + obj = obj->clone(false); + ret << obj; } - ret->mesh()->append(meshes[mi]); + obj->setMesh(meshes[mi]); + int mati = ai_meshes[mi]->mMaterialIndex; + if (mati >= 0 || mati < materials.size()) + obj->setMaterial(materials[mati]); //ret->setMesh(meshes[mi]); //qDebug() << "set mesh" << mi << ret->mesh(); //break; @@ -177,8 +180,9 @@ ObjectBase * assimpObject(const aiNode * n, const QVector & meshes, aiM } } for (uint i = 0; i < n->mNumChildren; ++i) { - ObjectBase * co = assimpObject(n->mChildren[i], meshes, ai_meshes, materials, light_by_name, out_lights); - if (co) ret->addChild(co); + ObjectBaseList cl = assimpObject(n->mChildren[i], meshes, ai_meshes, materials, light_by_name, out_lights); + foreach (ObjectBase * c, cl) + obj->addChild(c); } return ret; @@ -212,8 +216,9 @@ Scene * loadScene(const QString & filepath) { light_by_name[l->name()] = l; QVector out_lights; - ObjectBase * root = assimpObject(ais->mRootNode, meshes, ais->mMeshes, materials, light_by_name, out_lights); - if (!root) return 0; + ObjectBaseList rootl = assimpObject(ais->mRootNode, meshes, ais->mMeshes, materials, light_by_name, out_lights); + if (rootl.isEmpty()) return 0; + ObjectBase * root = rootl[0]; ObjectBaseList rcl = root->children(true); foreach (ObjectBase * c, rcl) {