diff options
Diffstat (limited to 'source/blender/collada/DocumentImporter.cpp')
-rw-r--r-- | source/blender/collada/DocumentImporter.cpp | 211 |
1 files changed, 65 insertions, 146 deletions
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 67fd9d648c7..eea51d1560f 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -57,12 +57,12 @@ extern "C" { #include "BLI_fileops.h" #include "BKE_camera.h" +#include "BKE_collection.h" #include "BKE_main.h" +#include "BKE_layer.h" #include "BKE_lamp.h" #include "BKE_library.h" -#include "BKE_texture.h" #include "BKE_fcurve.h" -#include "BKE_depsgraph.h" #include "BKE_scene.h" #include "BKE_global.h" #include "BKE_material.h" @@ -82,6 +82,9 @@ extern "C" { } +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_build.h" + #include "ExtraHandler.h" #include "ErrorHandler.h" #include "DocumentImporter.h" @@ -104,8 +107,9 @@ DocumentImporter::DocumentImporter(bContext *C, const ImportSettings *import_set import_settings(import_settings), mImportStage(General), mContext(C), - armature_importer(&unit_converter, &mesh_importer, CTX_data_main(C), CTX_data_scene(C), import_settings), - mesh_importer(&unit_converter, &armature_importer, CTX_data_main(C), CTX_data_scene(C)), + view_layer(CTX_data_view_layer(mContext)), + armature_importer(&unit_converter, &mesh_importer, CTX_data_main(C), CTX_data_scene(C), view_layer, import_settings), + mesh_importer(&unit_converter, &armature_importer, CTX_data_main(C), CTX_data_scene(C), view_layer), anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C)) { } @@ -130,7 +134,7 @@ bool DocumentImporter::import() loader.registerExtraDataCallbackHandler(ehandler); // deselect all to select new objects - BKE_scene_base_deselect_all(CTX_data_scene(mContext)); + BKE_view_layer_base_deselect_all(view_layer); std::string mFilename = std::string(this->import_settings->filepath); const std::string encodedFilename = bc_url_encode(mFilename); @@ -228,11 +232,6 @@ void DocumentImporter::finish() objects_to_scale->insert(objects_to_scale->end(), objects_done->begin(), objects_done->end()); delete objects_done; } - - // update scene - DAG_relations_tag_update(bmain); - WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, NULL); - } @@ -241,7 +240,6 @@ void DocumentImporter::finish() armature_importer.set_tags_map(this->uid_tags_map); armature_importer.make_armatures(mContext, *objects_to_scale); armature_importer.make_shape_keys(mContext); - DAG_relations_tag_update(bmain); #if 0 armature_importer.fix_animation(); @@ -259,27 +257,22 @@ void DocumentImporter::finish() fprintf(stderr, "got %d library nodes to free\n", (int)libnode_ob.size()); // free all library_nodes - std::vector<Object *>::iterator lit; - for (lit = libnode_ob.begin(); lit != libnode_ob.end(); lit++) { - Object *ob = *lit; - - Base *base = BKE_scene_base_find(sce, ob); - if (base) { - BLI_remlink(&sce->base, base); - BKE_libblock_free_us(bmain, base->object); - if (sce->basact == base) - sce->basact = NULL; - MEM_freeN(base); - } + std::vector<Object *>::iterator it; + for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) { + Object *ob = *it; + BKE_scene_collections_object_remove(bmain, sce, ob, true); } libnode_ob.clear(); - - DAG_relations_tag_update(bmain); } bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units); delete objects_to_scale; + + // update scene + DEG_id_tag_update(&sce->id, DEG_TAG_COPY_ON_WRITE); + DEG_relations_tag_update(bmain); + WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, NULL); } @@ -384,7 +377,7 @@ Object *DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera } Main *bmain = CTX_data_main(mContext); - Object *ob = bc_add_object(bmain, sce, OB_CAMERA, NULL); + Object *ob = bc_add_object(bmain, sce, view_layer, OB_CAMERA, NULL); Camera *cam = uid_camera_map[cam_uid]; Camera *old_cam = (Camera *)ob->data; ob->data = cam; @@ -396,12 +389,12 @@ Object *DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Sce { const COLLADAFW::UniqueId& lamp_uid = lamp->getInstanciatedObjectId(); if (uid_lamp_map.find(lamp_uid) == uid_lamp_map.end()) { - fprintf(stderr, "Couldn't find lamp by UID.\n"); + fprintf(stderr, "Couldn't find light by UID.\n"); return NULL; } Main *bmain = CTX_data_main(mContext); - Object *ob = bc_add_object(bmain, sce, OB_LAMP, NULL); + Object *ob = bc_add_object(bmain, sce, view_layer, OB_LAMP, NULL); Lamp *la = uid_lamp_map[lamp_uid]; Lamp *old_lamp = (Lamp *)ob->data; ob->data = la; @@ -415,8 +408,8 @@ Object *DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Nod Main *bmain = CTX_data_main(mContext); Object *obn = BKE_object_copy(bmain, source_ob); - DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); - BKE_scene_base_add(sce, obn); + DEG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); + BKE_collection_object_add_from(bmain, sce, source_ob, obn); if (instance_node) { anim_importer.read_node_transform(instance_node, obn); @@ -519,7 +512,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA if (parent_node == NULL && !is_library_node) { // A Joint on root level is a skeleton without root node. // Here we add the armature "on the fly": - par = bc_add_object(bmain, sce, OB_ARMATURE, std::string("Armature").c_str()); + par = bc_add_object(bmain, sce, view_layer, OB_ARMATURE, std::string("Armature").c_str()); objects_done->push_back(par); root_objects->push_back(par); object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), par)); @@ -551,8 +544,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA // maybe join multiple <instance_...> meshes into 1, and link object with it? not sure... // <instance_geometry> while (geom_done < geom.getCount()) { - ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map, - material_texture_mapping_map); + ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map); if (ob == NULL) { report_unknown_reference(*node, "instance_mesh"); } @@ -592,7 +584,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA } while (controller_done < controller.getCount()) { COLLADAFW::InstanceGeometry *geometry = (COLLADAFW::InstanceGeometry *)controller[controller_done]; - ob = mesh_importer.create_mesh_object(node, geometry, true, uid_material_map, material_texture_mapping_map); + ob = mesh_importer.create_mesh_object(node, geometry, true, uid_material_map); if (ob == NULL) { report_unknown_reference(*node, "instance_controller"); } @@ -633,10 +625,10 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA if ( (geom_done + camera_done + lamp_done + controller_done + inst_done) < 1) { //Check if Object is armature, by checking if immediate child is a JOINT node. if (is_armature(node)) { - ob = bc_add_object(bmain, sce, OB_ARMATURE, name.c_str()); + ob = bc_add_object(bmain, sce, view_layer, OB_ARMATURE, name.c_str()); } else { - ob = bc_add_object(bmain, sce, OB_EMPTY, NULL); + ob = bc_add_object(bmain, sce, view_layer, OB_EMPTY, NULL); } objects_done->push_back(ob); if (parent_node == NULL) { @@ -775,103 +767,74 @@ bool DocumentImporter::writeMaterial(const COLLADAFW::Material *cmat) return true; } -// create mtex, create texture, set texture image -MTex *DocumentImporter::create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::Texture &ctex, Material *ma, - int i, TexIndexTextureArrayMap &texindex_texarray_map) -{ - COLLADAFW::SamplerPointerArray& samp_array = ef->getSamplerPointerArray(); - COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()]; - - const COLLADAFW::UniqueId& ima_uid = sampler->getSourceImage(); - - if (uid_image_map.find(ima_uid) == uid_image_map.end()) { - fprintf(stderr, "Couldn't find an image by UID.\n"); - return NULL; - } - - Main *bmain = CTX_data_main(mContext); - ma->mtex[i] = BKE_texture_mtex_add(); - ma->mtex[i]->texco = TEXCO_UV; - ma->mtex[i]->tex = BKE_texture_add(bmain, "Texture"); - ma->mtex[i]->tex->type = TEX_IMAGE; - ma->mtex[i]->tex->ima = uid_image_map[ima_uid]; - - texindex_texarray_map[ctex.getTextureMapId()].push_back(ma->mtex[i]); - - return ma->mtex[i]; -} - void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Material *ma) { COLLADAFW::EffectCommon::ShaderType shader = ef->getShaderType(); + // TODO: add back texture and extended material parameter support + // blinn if (shader == COLLADAFW::EffectCommon::SHADER_BLINN) { +#if 0 ma->spec_shader = MA_SPEC_BLINN; ma->spec = ef->getShininess().getFloatValue(); +#endif } // phong else if (shader == COLLADAFW::EffectCommon::SHADER_PHONG) { +#if 0 ma->spec_shader = MA_SPEC_PHONG; ma->har = ef->getShininess().getFloatValue(); +#endif } // lambert else if (shader == COLLADAFW::EffectCommon::SHADER_LAMBERT) { +#if 0 ma->diff_shader = MA_DIFF_LAMBERT; +#endif } // default - lambert else { +#if 0 ma->diff_shader = MA_DIFF_LAMBERT; fprintf(stderr, "Current shader type is not supported, default to lambert.\n"); +#endif } // reflectivity - ma->ray_mirror = ef->getReflectivity().getFloatValue(); + ma->metallic = ef->getReflectivity().getFloatValue(); // index of refraction +#if 0 ma->ang = ef->getIndexOfRefraction().getFloatValue(); +#endif - int i = 0; COLLADAFW::Color col; - MTex *mtex = NULL; - TexIndexTextureArrayMap texindex_texarray_map; // DIFFUSE // color if (ef->getDiffuse().isColor()) { - /* too high intensity can create artefacts (fireflies) - So here we take care that intensity is set to 0.8 wherever possible - */ col = ef->getDiffuse().getColor(); - ma->ref = max_ffff(col.getRed(), col.getGreen(), col.getBlue(), 0.8); - ma->r = col.getRed() / ma->ref; - ma->g = col.getGreen() / ma->ref; - ma->b = col.getBlue() / ma->ref; + ma->r = col.getRed(); + ma->g = col.getGreen(); + ma->b = col.getBlue(); } // texture else if (ef->getDiffuse().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getDiffuse().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_COL; - ma->texact = (int)i; - i++; - } +#endif } // AMBIENT // color if (ef->getAmbient().isColor()) { +#if 0 col = ef->getAmbient().getColor(); - ma->ambr = col.getRed(); - ma->ambg = col.getGreen(); - ma->ambb = col.getBlue(); +#endif } // texture else if (ef->getAmbient().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getAmbient().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_AMB; - i++; - } +#endif } // SPECULAR // color @@ -883,29 +846,22 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia } // texture else if (ef->getSpecular().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getSpecular().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_SPEC; - i++; - } +#endif } // REFLECTIVE // color if (ef->getReflective().isColor()) { +#if 0 col = ef->getReflective().getColor(); - ma->mirr = col.getRed(); - ma->mirg = col.getGreen(); - ma->mirb = col.getBlue(); +#endif } // texture else if (ef->getReflective().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getReflective().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_REF; - i++; - } +#endif } // EMISSION @@ -916,40 +872,31 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia } // texture else if (ef->getEmission().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getEmission().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_EMIT; - i++; - } +#endif } // TRANSPARENT // color if (ef->getOpacity().isColor()) { +#if 0 col = ef->getTransparent().getColor(); float alpha = ef->getTransparency().getFloatValue(); if (col.isValid()) { alpha *= col.getAlpha(); // Assuming A_ONE opaque mode } if (col.isValid() || alpha < 1.0) { - ma->alpha = alpha; - ma->mode |= MA_ZTRANSP | MA_TRANSP; + ... } +#endif } // texture else if (ef->getOpacity().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getOpacity().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_ALPHA; - i++; - ma->spectra = ma->alpha = 0; - ma->mode |= MA_ZTRANSP | MA_TRANSP; - } +#endif } - - material_texture_mapping_map[ma] = texindex_texarray_map; } /** When this method is called, the writer must write the effect. @@ -1177,7 +1124,7 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light) else lamp = (Lamp *)BKE_lamp_add(bmain, (char *)la_id.c_str()); if (!lamp) { - fprintf(stderr, "Cannot create lamp.\n"); + fprintf(stderr, "Cannot create light.\n"); return true; } @@ -1198,7 +1145,6 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light) et->setData("spotsize", &(lamp->spotsize)); lamp->spotsize = DEG2RADF(lamp->spotsize); et->setData("spotblend", &(lamp->spotblend)); - et->setData("halo_intensity", &(lamp->haint)); et->setData("att1", &(lamp->att1)); et->setData("att2", &(lamp->att2)); et->setData("falloff_type", &(lamp->falloff_type)); @@ -1206,38 +1152,12 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light) et->setData("clipend", &(lamp->clipend)); et->setData("bias", &(lamp->bias)); et->setData("soft", &(lamp->soft)); - et->setData("compressthresh", &(lamp->compressthresh)); et->setData("bufsize", &(lamp->bufsize)); - et->setData("samp", &(lamp->samp)); et->setData("buffers", &(lamp->buffers)); - et->setData("filtertype", &(lamp->filtertype)); - et->setData("bufflag", &(lamp->bufflag)); - et->setData("buftype", &(lamp->buftype)); - et->setData("ray_samp", &(lamp->ray_samp)); - et->setData("ray_sampy", &(lamp->ray_sampy)); - et->setData("ray_sampz", &(lamp->ray_sampz)); - et->setData("ray_samp_type", &(lamp->ray_samp_type)); et->setData("area_shape", &(lamp->area_shape)); et->setData("area_size", &(lamp->area_size)); et->setData("area_sizey", &(lamp->area_sizey)); et->setData("area_sizez", &(lamp->area_sizez)); - et->setData("adapt_thresh", &(lamp->adapt_thresh)); - et->setData("ray_samp_method", &(lamp->ray_samp_method)); - et->setData("shadhalostep", &(lamp->shadhalostep)); - et->setData("sun_effect_type", &(lamp->shadhalostep)); - et->setData("skyblendtype", &(lamp->skyblendtype)); - et->setData("horizon_brightness", &(lamp->horizon_brightness)); - et->setData("spread", &(lamp->spread)); - et->setData("sun_brightness", &(lamp->sun_brightness)); - et->setData("sun_size", &(lamp->sun_size)); - et->setData("backscattered_light", &(lamp->backscattered_light)); - et->setData("sun_intensity", &(lamp->sun_intensity)); - et->setData("atm_turbidity", &(lamp->atm_turbidity)); - et->setData("atm_extinction_factor", &(lamp->atm_extinction_factor)); - et->setData("atm_distance_factor", &(lamp->atm_distance_factor)); - et->setData("skyblendfac", &(lamp->skyblendfac)); - et->setData("sky_exposure", &(lamp->sky_exposure)); - et->setData("sky_colorspace", &(lamp->sky_colorspace)); } else { float constatt = light->getConstantAttenuation().getValue(); @@ -1301,7 +1221,6 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light) { /* our sun is very strong, so pick a smaller energy level */ lamp->type = LA_SUN; - lamp->mode |= LA_NO_SPEC; } break; case COLLADAFW::Light::POINT_LIGHT: @@ -1317,7 +1236,7 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light) break; case COLLADAFW::Light::UNDEFINED: { - fprintf(stderr, "Current lamp type is not supported.\n"); + fprintf(stderr, "Current light type is not supported.\n"); lamp->type = LA_LOCAL; } break; |