diff options
Diffstat (limited to 'source/blender/collada/MeshImporter.cpp')
-rw-r--r-- | source/blender/collada/MeshImporter.cpp | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index 6ca53c64299..f8cd487c355 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -207,7 +207,11 @@ void VCOLDataWrapper::get_vcol(int v_index, MLoopCol *mloopcol) } -MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce) : unitconverter(unitconv), scene(sce), armature_importer(arm) { +MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce, ViewLayer *view_layer): + unitconverter(unitconv), + scene(sce), + view_layer(view_layer), + armature_importer(arm) { } bool MeshImporter::set_poly_indices(MPoly *mpoly, MLoop *mloop, int loop_index, unsigned int *indices, int loop_count) @@ -472,11 +476,9 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *me) COLLADAFW::MeshVertexData::InputInfos *info = collada_mesh->getUVCoords().getInputInfosArray()[i]; COLLADAFW::String &uvname = info->mName; // Allocate space for UV_data - CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, uvname.c_str()); CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DEFAULT, NULL, me->totloop, uvname.c_str()); } // activate the first uv map - me->mtpoly = (MTexPoly *)CustomData_get_layer_n(&me->pdata, CD_MTEXPOLY, 0); me->mloopuv = (MLoopUV *) CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, 0); } @@ -1051,11 +1053,11 @@ void MeshImporter::optimize_material_assignements() * which materials shall be moved to the created geometries. Also see * optimize_material_assignements() above. */ -MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial, - std::map<COLLADAFW::UniqueId, Material *>& uid_material_map, - Object *ob, const COLLADAFW::UniqueId *geom_uid, - char *layername, MTFace *texture_face, - std::map<Material *, TexIndexTextureArrayMap>& material_texture_mapping_map, short mat_index) +void MeshImporter::assign_material_to_geom( + COLLADAFW::MaterialBinding cmaterial, + std::map<COLLADAFW::UniqueId, Material *>& uid_material_map, + Object *ob, const COLLADAFW::UniqueId *geom_uid, + std::map<Material *, TexIndexTextureArrayMap>& material_texture_mapping_map, short mat_index) { MTex *color_texture = NULL; Mesh *me = (Mesh *)ob->data; @@ -1065,7 +1067,7 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri if (uid_material_map.find(ma_uid) == uid_material_map.end()) { fprintf(stderr, "Cannot find material by UID.\n"); - return NULL; + return; } // first time we get geom_uid, ma_uid pair. Save for later check. @@ -1089,15 +1091,6 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri color_texture); } - // set texture face - if (color_texture && - strlen((color_texture)->uvname) && - !STREQ(layername, color_texture->uvname)) { - texture_face = (MTFace *)CustomData_get_layer_named(&me->fdata, CD_MTFACE, - color_texture->uvname); - strcpy(layername, color_texture->uvname); - } - MaterialIdPrimitiveArrayMap& mat_prim_map = geom_uid_mat_mapping_map[*geom_uid]; COLLADAFW::MaterialId mat_id = cmaterial.getMaterialId(); @@ -1114,15 +1107,9 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri for (i = 0; i < prim.totpoly; i++, mpoly++) { mpoly->mat_nr = mat_index; - // bind texture images to faces - if (texture_face && color_texture) { - texture_face->tpage = (Image *)color_texture->tex->ima; - texture_face++; - } } } } - return texture_face; } Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom, @@ -1158,7 +1145,7 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta const char *name = (id.length()) ? id.c_str() : NULL; // add object - Object *ob = bc_add_object(scene, OB_MESH, name); + Object *ob = bc_add_object(scene, view_layer, OB_MESH, name); bc_set_mark(ob); // used later for material assignement optimization @@ -1176,10 +1163,6 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta id_us_plus(&old_mesh->id); /* Because BKE_mesh_assign_object would have already decreased it... */ BKE_libblock_free_us(G.main, old_mesh); - char layername[100]; - layername[0] = '\0'; - MTFace *texture_face = NULL; - COLLADAFW::MaterialBindingArray& mat_array = geom->getMaterialBindings(); @@ -1187,9 +1170,9 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta for (unsigned int i = 0; i < mat_array.getCount(); i++) { if (mat_array[i].getReferencedMaterial().isValid()) { - texture_face = assign_material_to_geom(mat_array[i], uid_material_map, ob, geom_uid, - layername, texture_face, - material_texture_mapping_map, i); + assign_material_to_geom( + mat_array[i], uid_material_map, ob, geom_uid, + material_texture_mapping_map, i); } else { fprintf(stderr, "invalid referenced material for %s\n", mat_array[i].getName().c_str()); |