[Bf-blender-cvs] [b5fded66ccc] usd-importer-T81257-merge: USD Import: remove instancing functionality.

makowalski noreply at git.blender.org
Sat Apr 17 04:01:59 CEST 2021


Commit: b5fded66ccc14c9e147386c7613c3ff26361cd4f
Author: makowalski
Date:   Fri Apr 16 21:53:40 2021 -0400
Branches: usd-importer-T81257-merge
https://developer.blender.org/rBb5fded66ccc14c9e147386c7613c3ff26361cd4f

USD Import: remove instancing functionality.

Temporarily removing collection-based instancing
experimental feature to simplify the review of
the current patch (differential D10700).
Instancing can be added back in a future patch.

===================================================================

M	source/blender/editors/io/io_usd.c
M	source/blender/io/usd/CMakeLists.txt
M	source/blender/io/usd/intern/usd_capi_import.cc
M	source/blender/io/usd/intern/usd_reader_stage.cc
M	source/blender/io/usd/intern/usd_reader_stage.h

===================================================================

diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 32fca807c1d..353953ee091 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -310,8 +310,6 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
   const bool import_proxy = RNA_boolean_get(op->ptr, "import_proxy");
   const bool import_render = RNA_boolean_get(op->ptr, "import_render");
 
-  const bool use_instancing = RNA_boolean_get(op->ptr, "use_instancing");
-
   const bool import_usd_preview = RNA_boolean_get(op->ptr, "import_usd_preview");
   const bool set_material_blend = RNA_boolean_get(op->ptr, "set_material_blend");
 
@@ -331,6 +329,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
   }
 
   const bool validate_meshes = false;
+  const bool use_instancing = false;
 
   struct USDImportParams params = {scale,
                                    is_sequence,
@@ -438,7 +437,6 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op)
 
   box = uiLayoutBox(layout);
   uiItemL(box, IFACE_("Experimental"), ICON_NONE);
-  uiItemR(box, ptr, "use_instancing", 0, NULL, ICON_NONE);
   uiItemR(box, ptr, "import_usd_preview", 0, NULL, ICON_NONE);
   uiItemR(box, ptr, "set_material_blend", 0, NULL, ICON_NONE);
 }
@@ -513,8 +511,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot)
                   true,
                   "Import Instance Proxies",
                   "If enabled, USD instances will be traversed with instance proxies, "
-                  "creating a unique Blender object for each instance. Note that "
-                  "this option is ignored if the Instancing option is also checked");
+                  "creating a unique Blender object for each instance");
 
   RNA_def_boolean(ot->srna,
                   "import_visible_only",
@@ -555,14 +552,6 @@ void WM_OT_usd_import(struct wmOperatorType *ot)
   RNA_def_boolean(
       ot->srna, "import_render", true, "Render", "When checked, import final render geometry");
 
-  RNA_def_boolean(
-      ot->srna,
-      "use_instancing",
-      false,
-      "Instancing",
-      "When checked, USD scenegraph instances are imported as collection instances in Blender. "
-      "Note that point instancers are not yet handled by this option");
-
   RNA_def_boolean(
       ot->srna,
       "import_usd_preview",
diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt
index 1c1bacd3fa7..5499fe36898 100644
--- a/source/blender/io/usd/CMakeLists.txt
+++ b/source/blender/io/usd/CMakeLists.txt
@@ -71,7 +71,6 @@ set(SRC
   intern/usd_reader_camera.cc
   intern/usd_reader_curve.cc
   intern/usd_reader_geom.cc
-  intern/usd_reader_instance.cc
   intern/usd_reader_light.cc
   intern/usd_reader_material.cc
   intern/usd_reader_mesh.cc
@@ -97,7 +96,6 @@ set(SRC
   intern/usd_reader_camera.h
   intern/usd_reader_curve.h
   intern/usd_reader_geom.h
-  intern/usd_reader_instance.h
   intern/usd_reader_light.h
   intern/usd_reader_material.h
   intern/usd_reader_mesh.h
diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc
index fb587cd59c5..d59ce81a791 100644
--- a/source/blender/io/usd/intern/usd_capi_import.cc
+++ b/source/blender/io/usd/intern/usd_capi_import.cc
@@ -127,110 +127,6 @@ static Collection *create_collection(Main *bmain, Collection *parent, const char
   return coll;
 }
 
-/* Set the instance collection on the given instance reader.
- *  The collection is assigned from the given map based on
- *  the prototype (maser) prim path. */
-static void set_instance_collection(
-    USDInstanceReader *instance_reader,
-    const std::map<pxr::SdfPath, Collection *> &proto_collection_map)
-{
-  if (!instance_reader) {
-    return;
-  }
-
-  pxr::SdfPath proto_path = instance_reader->proto_path();
-
-  std::map<pxr::SdfPath, Collection *>::const_iterator it = proto_collection_map.find(proto_path);
-
-  if (it != proto_collection_map.end()) {
-    instance_reader->set_instance_collection(it->second);
-  }
-  else {
-    std::cerr << "WARNING: Couldn't find prototype collection for " << instance_reader->prim_path()
-              << std::endl;
-  }
-}
-
-/* Create instance collections for the USD instance readers. */
-static void create_proto_collections(Main *bmain,
-                                     ViewLayer *view_layer,
-                                     Collection *parent_collection,
-                                     const ProtoReaderMap &proto_readers,
-                                     const std::vector<USDPrimReader *> &readers)
-{
-  Collection *all_protos_collection = create_collection(bmain, parent_collection, "prototypes");
-
-  std::map<pxr::SdfPath, Collection *> proto_collection_map;
-
-  for (const auto &pair : proto_readers) {
-
-    std::string proto_collection_name = pair.first.GetString();
-
-    // TODO(makowalski): Is it acceptable to have slashes in the collection names? Or should we
-    // replace them with another character, like an underscore, as in the following?
-    // std::replace(proto_collection_name.begin(), proto_collection_name.end(), '/', '_');
-
-    Collection *proto_collection = create_collection(
-        bmain, all_protos_collection, proto_collection_name.c_str());
-
-    LayerCollection *proto_lc = BKE_layer_collection_first_from_scene_collection(view_layer,
-                                                                                 proto_collection);
-    if (proto_lc) {
-      proto_lc->flag |= LAYER_COLLECTION_HIDE;
-    }
-
-    proto_collection_map.insert(std::make_pair(pair.first, proto_collection));
-  }
-
-  // Set the instance collections on the readers, including the prototype
-  // readers, as instancing may be recursive.
-
-  for (const auto &pair : proto_readers) {
-    for (USDPrimReader *reader : pair.second) {
-      if (USDInstanceReader *instance_reader = dynamic_cast<USDInstanceReader *>(reader)) {
-        set_instance_collection(instance_reader, proto_collection_map);
-      }
-    }
-  }
-
-  for (USDPrimReader *reader : readers) {
-    if (USDInstanceReader *instance_reader = dynamic_cast<USDInstanceReader *>(reader)) {
-      set_instance_collection(instance_reader, proto_collection_map);
-    }
-  }
-
-  // Add the prototype objects to the collections.
-  for (const auto &pair : proto_readers) {
-
-    std::map<pxr::SdfPath, Collection *>::const_iterator it = proto_collection_map.find(
-        pair.first);
-
-    if (it == proto_collection_map.end()) {
-      std::cerr << "WARNING: Couldn't find collection when adding objects for prototype "
-                << pair.first << std::endl;
-      continue;
-    }
-
-    for (USDPrimReader *reader : pair.second) {
-      Object *ob = reader->object();
-
-      if (!ob) {
-        continue;
-      }
-
-      Collection *coll = it->second;
-
-      BKE_collection_object_add(bmain, coll, ob);
-
-      DEG_id_tag_update(&coll->id, ID_RECALC_COPY_ON_WRITE);
-      DEG_id_tag_update_ex(bmain,
-                           &ob->id,
-                           ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION |
-                               ID_RECALC_BASE_FLAGS);
-    }
-  }
-}
-
 // Update the given import settings with the global rotation matrix to orient
 // imported objects with Z-up, if necessary
 static void set_global_rotation(pxr::UsdStageRefPtr stage, ImportSettings &r_settings)
@@ -373,34 +269,6 @@ static void import_startjob(void *customdata, short *stop, short *do_update, flo
 
   /* Setup parenthood */
 
-  /* Handle instance prototypes.
-  /* TODO(makowalski): Move this logic inside USDReaderStage? */
-  for (const auto &pair : archive->proto_readers()) {
-
-    for (USDPrimReader *reader : pair.second) {
-
-      if (!reader) {
-        continue;
-      }
-
-      /* TODO(makowalski): Here and below, should we call
-       * read_object_data() with the actual time? */
-      reader->read_object_data(data->bmain, 0.0);
-
-      Object *ob = reader->object();
-
-      if (!ob) {
-        continue;
-      }
-
-      const USDPrimReader *parent_reader = reader->parent();
-
-      ob->parent = parent_reader ? parent_reader->object() : nullptr;
-
-      // TODO(makowalski): Handle progress update.
-    }
-  }
-
   for (USDPrimReader *reader : archive->readers()) {
 
     if (!reader) {
@@ -454,17 +322,6 @@ static void import_endjob(void *customdata)
         BKE_id_free_us(data->bmain, ob);
       }
     }
-
-    for (const auto &pair : data->archive->proto_readers()) {
-      for (USDPrimReader *reader : pair.second) {
-
-        /* It's possible that cancellation occurred between the creation of
-         * the reader and the creation of the Blender object. */
-        if (Object *ob = reader->object()) {
-          BKE_id_free_us(data->bmain, ob);
-        }
-      }
-    }
   }
   else if (data->archive) {
     /* Add object to scene. */
@@ -476,14 +333,6 @@ static void import_endjob(void *customdata)
 
     lc = BKE_layer_collection_get_active(view_layer);
 
-    if (!data->archive->proto_readers().empty()) {
-      create_proto_collections(data->bmain,
-                               view_layer,
-                               lc->collection,
-                               data->archive->proto_readers(),
-                               data->archive->readers());
-    }
-
     for (USDPrimReader *reader : data->archive->readers()) {
 
       if (!reader) {
diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc
index 3a2288e0543..180de601dd6 100644
--- a/source/blender/io/usd/intern/usd_reader_stage.cc
+++ b/source/blender/io/usd/intern/usd_reader_stage.cc
@@ -48,7 +48,6 @@ USDStageReader::USDStageReader(struct Main *bmain, const char *filename)
 USDStageReader::~USDStageReader()
 {
   clear_readers(true);
-  clear_proto_readers(true);
 
   if (stage_) {
     stage_->Unload();
@@ -66,10 +65,7 @@ USDPrimReader *USDStageReader::create_reader(const pxr::UsdPrim &prim,
 {
   USDPrimReader *reader = nullptr;
 
-  if (params.use_instancing && prim.IsInstance()) {
-    reader = new USDInstanceReader(prim, params, settings);
-  }
-  else if (params.import_c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list