diff --git a/source/blender/io/usd/intern/usd_instancing_utils.cc b/source/blender/io/usd/intern/usd_instancing_utils.cc index 133a5864ce4..abbaa990bda 100644 --- a/source/blender/io/usd/intern/usd_instancing_utils.cc +++ b/source/blender/io/usd/intern/usd_instancing_utils.cc @@ -6,6 +6,7 @@ #include "usd.hh" #include "usd_hash_types.hh" +#include "usd_utils.hh" #include "BLI_map.hh" #include "BLI_set.hh" @@ -21,23 +22,6 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.usd"}; -namespace { - -/* If the given path already exists on the given stage, return the path with - * a numerical suffix appended to the name that ensures the path is unique. - * If the path does not exist on the stage, it will be returned unchanged. */ -pxr::SdfPath get_unique_path(pxr::UsdStageRefPtr stage, const std::string &path) -{ - std::string unique_path = path; - int suffix = 2; - while (stage->GetPrimAtPath(pxr::SdfPath(unique_path)).IsValid()) { - unique_path = path + std::to_string(suffix++); - } - return pxr::SdfPath(unique_path); -} - -} // End anonymous namespace - namespace blender::io::usd { /* We need an ordered map so we use std::map. */ diff --git a/source/blender/io/usd/intern/usd_light_convert.cc b/source/blender/io/usd/intern/usd_light_convert.cc index 385f7c66c43..2f89d9be575 100644 --- a/source/blender/io/usd/intern/usd_light_convert.cc +++ b/source/blender/io/usd/intern/usd_light_convert.cc @@ -7,6 +7,7 @@ #include "usd.hh" #include "usd_asset_utils.hh" #include "usd_private.hh" +#include "usd_utils.hh" #include "usd_writer_material.hh" #include @@ -111,21 +112,6 @@ struct WorldNtreeSearchResults { namespace blender::io::usd { -/** - * If the given path already exists on the given stage, return the path with - * a numerical suffix appended to the name that ensures the path is unique. If - * the path does not exist on the stage, it will be returned unchanged. - */ -static pxr::SdfPath get_unique_path(pxr::UsdStageRefPtr stage, const std::string &path) -{ - std::string unique_path = path; - int suffix = 2; - while (stage->GetPrimAtPath(pxr::SdfPath(unique_path)).IsValid()) { - unique_path = path + std::to_string(suffix++); - } - return pxr::SdfPath(unique_path); -} - /** * Load the image at the given path. Handle packing and copying based in the import options. * Return the opened image on success or a nullptr on failure. diff --git a/source/blender/io/usd/intern/usd_utils.cc b/source/blender/io/usd/intern/usd_utils.cc index 222c22d6169..f69d98524c2 100644 --- a/source/blender/io/usd/intern/usd_utils.cc +++ b/source/blender/io/usd/intern/usd_utils.cc @@ -56,4 +56,15 @@ std::string make_safe_name(const StringRef name, bool allow_unicode) return {buf.data(), offset}; } +pxr::SdfPath get_unique_path(pxr::UsdStageRefPtr stage, const std::string &path) +{ + std::string unique_path = path; + int suffix = 2; + while (stage->GetPrimAtPath(pxr::SdfPath(unique_path)).IsValid()) { + unique_path = path + std::to_string(suffix++); + } + + return pxr::SdfPath(unique_path); +} + } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_utils.hh b/source/blender/io/usd/intern/usd_utils.hh index accae0b9a61..2fa6358315e 100644 --- a/source/blender/io/usd/intern/usd_utils.hh +++ b/source/blender/io/usd/intern/usd_utils.hh @@ -18,4 +18,14 @@ namespace blender::io::usd { */ std::string make_safe_name(StringRef name, bool allow_unicode); +/* Return a unique USD `SdfPath`. If the given path already exists on the given stage, return + * the path with a numerical suffix appended to the name that ensures the path is unique. + * If the path does not exist on the stage, it will be returned unchanged. + * + * \param stage: The stage + * \param path: The original path + * \return A valid, and unique, USD `SdfPath` + */ +pxr::SdfPath get_unique_path(pxr::UsdStageRefPtr stage, const std::string &path); + } // namespace blender::io::usd