Merge branch 'master' into blender2.8
[blender.git] / source / blender / collada / DocumentImporter.cpp
index ce0d296843bcad58a7f68a40f44a83af4e9ac8aa..97b11f72509b398f376ad52db702b60e9bb6a824 100644 (file)
@@ -57,12 +57,13 @@ 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 +83,9 @@ extern "C" {
 
 }
 
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
 #include "ExtraHandler.h"
 #include "ErrorHandler.h"
 #include "DocumentImporter.h"
@@ -104,8 +108,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_scene(C), import_settings),
-       mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C)),
+       view_layer(CTX_data_view_layer(mContext)),
+       armature_importer(&unit_converter, &mesh_importer, CTX_data_scene(C), view_layer, import_settings),
+       mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C), view_layer),
        anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C))
 {
 }
@@ -130,7 +135,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);
@@ -230,7 +235,7 @@ void DocumentImporter::finish()
                }
 
                // update scene
-               DAG_relations_tag_update(bmain);
+               DEG_relations_tag_update(bmain);
                WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, NULL);
 
        }
@@ -241,7 +246,7 @@ 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();
-       DAG_relations_tag_update(bmain);
+       DEG_relations_tag_update(bmain);
 
 #if 0
        armature_importer.fix_animation();
@@ -259,22 +264,14 @@ 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(G.main, 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_collections_object_remove(G.main, &sce->id, ob, true);
                }
                libnode_ob.clear();
 
-               DAG_relations_tag_update(bmain);
+               DEG_relations_tag_update(bmain);
        }
        
        bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units);
@@ -383,7 +380,7 @@ Object *DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera
                return NULL;
        }
 
-       Object *ob = bc_add_object(sce, OB_CAMERA, NULL);
+       Object *ob = bc_add_object(sce, view_layer, OB_CAMERA, NULL);
        Camera *cam = uid_camera_map[cam_uid];
        Camera *old_cam = (Camera *)ob->data;
        ob->data = cam;
@@ -399,7 +396,7 @@ Object *DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Sce
                return NULL;
        }
 
-       Object *ob = bc_add_object(sce, OB_LAMP, NULL);
+       Object *ob = bc_add_object(sce, view_layer, OB_LAMP, NULL);
        Lamp *la = uid_lamp_map[lamp_uid];
        Lamp *old_lamp = (Lamp *)ob->data;
        ob->data = la;
@@ -412,8 +409,8 @@ Object *DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Nod
        fprintf(stderr, "create <instance_node> under node id=%s from node id=%s\n", instance_node ? instance_node->getOriginalId().c_str() : NULL, source_node ? source_node->getOriginalId().c_str() : NULL);
 
        Object *obn = BKE_object_copy(G.main, 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(sce, source_ob, obn);
 
        if (instance_node) {
                anim_importer.read_node_transform(instance_node, obn);
@@ -515,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(sce, OB_ARMATURE, std::string("Armature").c_str());
+                       par = bc_add_object(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));
@@ -629,10 +626,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(sce, OB_ARMATURE, name.c_str());
+                               ob = bc_add_object(sce, view_layer, OB_ARMATURE, name.c_str());
                        }
                        else {
-                               ob = bc_add_object(sce, OB_EMPTY, NULL);
+                               ob = bc_add_object(sce, view_layer, OB_EMPTY, NULL);
                        }
                        objects_done->push_back(ob);
                        if (parent_node == NULL) {