[Bf-blender-cvs] [396a8b8ad81] tmp-dynamic-usd: USD import: import textures for UMM.
Michael Kowalski
noreply at git.blender.org
Tue Nov 29 01:16:49 CET 2022
Commit: 396a8b8ad81a1cbf5aeb6c30ac73bf9a6b1dd601
Author: Michael Kowalski
Date: Mon Nov 28 19:14:45 2022 -0500
Branches: tmp-dynamic-usd
https://developer.blender.org/rB396a8b8ad81a1cbf5aeb6c30ac73bf9a6b1dd601
USD import: import textures for UMM.
Added logic to support importing textures when invoking
UMM shader conversion.
===================================================================
M source/blender/io/usd/intern/usd_asset_utils.h
M source/blender/io/usd/intern/usd_reader_material.cc
M source/blender/io/usd/intern/usd_umm.cc
M source/blender/io/usd/intern/usd_umm.h
===================================================================
diff --git a/source/blender/io/usd/intern/usd_asset_utils.h b/source/blender/io/usd/intern/usd_asset_utils.h
index 683047254d2..e3bc7dd7fc9 100644
--- a/source/blender/io/usd/intern/usd_asset_utils.h
+++ b/source/blender/io/usd/intern/usd_asset_utils.h
@@ -19,6 +19,6 @@ namespace blender::io::usd {
bool usd_paths_equal(const char *p1, const char *p2);
- std::string usd_import_texture(const char *src, const char *basepath, bool overwrite);
+ std::string usd_import_texture(const char *src, const char *import_textures_dir, bool overwrite);
} // namespace blender::io::usd
diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc
index c1e1e393617..93d2a6336e3 100644
--- a/source/blender/io/usd/intern/usd_reader_material.cc
+++ b/source/blender/io/usd/intern/usd_reader_material.cc
@@ -390,7 +390,7 @@ Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial &usd_mater
bool has_mdl = false;
#ifdef WITH_PYTHON
/* Invoke UMM to convert to MDL. */
- bool mdl_imported = umm_import_mdl_material(mtl, usd_material, true /* Verbose */, &has_mdl);
+ bool mdl_imported = umm_import_mdl_material(params_, mtl, usd_material, true /* Verbose */, &has_mdl);
#endif
if (!(has_mdl && mdl_imported) && usd_preview) {
/* The material has no MDL shader or we couldn't convert the MDL,
diff --git a/source/blender/io/usd/intern/usd_umm.cc b/source/blender/io/usd/intern/usd_umm.cc
index c648c2f2c23..1fc0f146ab2 100644
--- a/source/blender/io/usd/intern/usd_umm.cc
+++ b/source/blender/io/usd/intern/usd_umm.cc
@@ -19,6 +19,7 @@
# include "usd_umm.h"
# include "usd.h"
+# include "usd_asset_utils.h"
# include "usd_exporter_context.h"
# include "usd_writer_material.h"
@@ -380,7 +381,8 @@ static void test_python()
PyGILState_Release(gilstate);
}
-static PyObject *get_shader_source_data(const pxr::UsdShadeShader &usd_shader)
+static PyObject *get_shader_source_data(const USDImportParams ¶ms,
+ const pxr::UsdShadeShader &usd_shader)
{
if (!usd_shader) {
return nullptr;
@@ -463,6 +465,11 @@ static PyObject *get_shader_source_data(const pxr::UsdShadeShader &usd_shader)
asset_path.GetAssetPath());
}
+ if (params.import_textures) {
+ resolved_path = usd_import_texture(
+ resolved_path.c_str(), params.import_textures_dir, params.overwrite_textures);
+ }
+
pxr::TfToken color_space_tok = usd_attr.GetColorSpace();
if (color_space_tok.IsEmpty() && have_connected_source) {
@@ -527,7 +534,8 @@ static PyObject *get_shader_source_data(const pxr::UsdShadeShader &usd_shader)
return ret;
}
-static bool import_material(Material *mtl,
+static bool import_material(const USDImportParams ¶ms,
+ Material *mtl,
const pxr::UsdShadeShader &usd_shader,
const std::string &source_class)
{
@@ -558,7 +566,7 @@ static bool import_material(Material *mtl,
return false;
}
- PyObject *source_data = get_shader_source_data(usd_shader);
+ PyObject *source_data = get_shader_source_data(params, usd_shader);
if (!source_data) {
std::cout << "WARNING: Couldn't get source data for shader " << usd_shader.GetPath()
@@ -747,7 +755,8 @@ bool umm_module_loaded()
return loaded;
}
-bool umm_import_mdl_material(Material *mtl,
+bool umm_import_mdl_material(const USDImportParams ¶ms,
+ Material *mtl,
const pxr::UsdShadeMaterial &usd_material,
bool verbose,
bool *r_has_mdl)
@@ -796,7 +805,7 @@ bool umm_import_mdl_material(Material *mtl,
}
std::string source_class = path + "|" + source_asset_sub_identifier.GetString();
- return import_material(mtl, surf_shader, source_class);
+ return import_material(params, mtl, surf_shader, source_class);
}
return false;
diff --git a/source/blender/io/usd/intern/usd_umm.h b/source/blender/io/usd/intern/usd_umm.h
index 718f54f53ab..af1d5e7c1b4 100644
--- a/source/blender/io/usd/intern/usd_umm.h
+++ b/source/blender/io/usd/intern/usd_umm.h
@@ -24,6 +24,7 @@
# include "Python.h"
struct Material;
+struct USDImportParams;
namespace blender::io::usd {
@@ -31,7 +32,8 @@ struct USDExporterContext;
bool umm_module_loaded();
-bool umm_import_mdl_material(Material *mtl,
+bool umm_import_mdl_material(const USDImportParams ¶ms,
+ Material *mtl,
const pxr::UsdShadeMaterial &usd_material,
bool verbose,
bool *r_has_material);
More information about the Bf-blender-cvs
mailing list