From a6d4e91db8783d61a7223c52ec82cc5d64ea683c Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Thu, 12 Dec 2024 00:57:29 +0100 Subject: [PATCH] Cleanup: USD: various non-functional changes Tidy up: - Use blender::Map and blender::Vector for newly created `prim_map` - Leave bread-crumb comment for moving map creation outside of loop - Expand UI tooltip for newly added export option Pull Request: https://projects.blender.org/blender/blender/pulls/131770 --- source/blender/editors/io/io_usd.cc | 6 +++--- source/blender/io/usd/intern/usd_capi_import.cc | 12 ++++++------ source/blender/io/usd/intern/usd_hook.cc | 4 ++-- source/blender/io/usd/intern/usd_hook.hh | 8 ++++++-- source/blender/io/usd/usd.hh | 3 +-- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/source/blender/editors/io/io_usd.cc b/source/blender/editors/io/io_usd.cc index ee6f2dc89f0..90edf258571 100644 --- a/source/blender/editors/io/io_usd.cc +++ b/source/blender/editors/io/io_usd.cc @@ -854,9 +854,9 @@ void WM_OT_usd_export(wmOperatorType *ot) "merge_parent_xform", false, "Merge parent Xform", - "Merge USD primitives with their Xform parent if possible: " - "USD does not allow nested UsdGeomGprim. Intermediary Xform will " - "be defined to keep the USD file valid."); + "Merge USD primitives with their Xform parent if possible. USD does not allow " + "nested UsdGeomGprims, intermediary Xform prims will be defined to keep the USD " + "file valid when encountering object hierarchies."); } /* ====== USD Import ====== */ diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 3fae95d7b0a..f26c5cb06b8 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -343,7 +343,6 @@ static void import_startjob(void *customdata, wmJobWorkerStatus *worker_status) /* Setup parenthood and read actual object data. */ i = 0; for (USDPrimReader *reader : archive->readers()) { - if (!reader) { continue; } @@ -355,11 +354,12 @@ static void import_startjob(void *customdata, wmJobWorkerStatus *worker_status) reader->read_object_data(data->bmain, 0.0); - data->prim_map[reader->object_prim_path()].push_back(RNA_id_pointer_create(&ob->id)); - + /* TODO: Move this outside the loop once when we support reading object data in parallel. */ + data->prim_map.lookup_or_add_default(reader->object_prim_path()) + .append(RNA_id_pointer_create(&ob->id)); if (ob->data) { - data->prim_map[reader->data_prim_path()].push_back( - RNA_id_pointer_create(static_cast(ob->data))); + data->prim_map.lookup_or_add_default(reader->data_prim_path()) + .append(RNA_id_pointer_create(static_cast(ob->data))); } USDPrimReader *parent = reader->parent(); @@ -384,7 +384,7 @@ static void import_startjob(void *customdata, wmJobWorkerStatus *worker_status) [&](const std::string &path, const std::string &name) { Material *mat = data->settings.mat_name_to_mat.lookup_default(name, nullptr); if (mat) { - data->prim_map[path].push_back(RNA_id_pointer_create(&mat->id)); + data->prim_map.lookup_or_add_default(path).append(RNA_id_pointer_create(&mat->id)); } }); diff --git a/source/blender/io/usd/intern/usd_hook.cc b/source/blender/io/usd/intern/usd_hook.cc index 0ed541e78f1..f93adf36846 100644 --- a/source/blender/io/usd/intern/usd_hook.cc +++ b/source/blender/io/usd/intern/usd_hook.cc @@ -145,7 +145,7 @@ struct USDSceneImportContext { if (!prim_map_dict) { prim_map_dict = new boost::python::dict; - for (auto &[path, ids] : prim_map) { + prim_map.foreach_item([&](const std::string &path, const Vector &ids) { if (!prim_map_dict->has_key(path)) { (*prim_map_dict)[path] = boost::python::list(); } @@ -155,7 +155,7 @@ struct USDSceneImportContext { for (auto &ptr_rna : ids) { list.append(ptr_rna); } - } + }); } return *prim_map_dict; diff --git a/source/blender/io/usd/intern/usd_hook.hh b/source/blender/io/usd/intern/usd_hook.hh index 8404257d886..9b2734c3194 100644 --- a/source/blender/io/usd/intern/usd_hook.hh +++ b/source/blender/io/usd/intern/usd_hook.hh @@ -3,17 +3,21 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once +#include "BLI_map.hh" +#include "BLI_vector.hh" + +#include "RNA_types.hh" + #include #include struct Depsgraph; struct Material; -struct PointerRNA; struct ReportList; namespace blender::io::usd { -using ImportedPrimMap = std::map>; +using ImportedPrimMap = Map>; /** Ensure classes and type converters necessary for invoking import and export hooks * are registered. */ diff --git a/source/blender/io/usd/usd.hh b/source/blender/io/usd/usd.hh index 98ac5da2d6c..12b1e8ee6f0 100644 --- a/source/blender/io/usd/usd.hh +++ b/source/blender/io/usd/usd.hh @@ -136,6 +136,7 @@ struct USDExportParams { bool only_deform_bones = false; bool convert_world_material = true; + bool merge_parent_xform = false; bool use_instancing = false; bool export_custom_properties = true; @@ -168,8 +169,6 @@ struct USDExportParams { char collection[MAX_IDPROP_NAME] = ""; char custom_properties_namespace[MAX_IDPROP_NAME] = ""; - bool merge_parent_xform = false; - /** Communication structure between the wmJob management code and the worker code. Currently used * to generate safely reports from the worker thread. */ wmJobWorkerStatus *worker_status = nullptr;