[Bf-blender-cvs] [f71ad78dc1b] universal-scene-description: USD Preview Surface import as a fallback.
Michael Kowalski
noreply at git.blender.org
Wed Nov 10 15:27:41 CET 2021
Commit: f71ad78dc1bc58ce5f9dcb5e31b452a01c0b3563
Author: Michael Kowalski
Date: Tue Nov 9 13:02:22 2021 -0500
Branches: universal-scene-description
https://developer.blender.org/rBf71ad78dc1bc58ce5f9dcb5e31b452a01c0b3563
USD Preview Surface import as a fallback.
Added logic to fall back on importing existing
USD Preview Surface shaders if importing MDL
is selected as an option but the material has
no MDL shaders.
===================================================================
M source/blender/editors/io/io_usd.c
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/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 9283e2d0427..7a07c5f403d 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -85,7 +85,9 @@ const EnumPropertyItem rna_enum_usd_import_shaders_mode_items[] = {
"USD MDL",
0,
"MDL",
- "Convert MDL shaders to Blender materials"},
+ "Convert MDL shaders to Blender materials; if no MDL shaders "
+ "exist on the material, log a warning and import existing USD "
+ "Preview Surface shaders instead"},
{0, NULL, 0, NULL, NULL},
};
diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc
index aa702233929..fb5c8a8368d 100644
--- a/source/blender/io/usd/intern/usd_reader_material.cc
+++ b/source/blender/io/usd/intern/usd_reader_material.cc
@@ -33,6 +33,8 @@
#include "DNA_material_types.h"
+#include "WM_api.h"
+
#include <pxr/base/gf/vec3f.h>
#include <pxr/usd/ar/resolver.h>
#include <pxr/usd/usdShade/material.h>
@@ -347,18 +349,29 @@ Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial &usd_mater
* if there is one. */
pxr::UsdShadeShader usd_preview;
if (get_usd_preview_surface(usd_material, usd_preview)) {
+ /* Always set the viewport material properties from the USD
+ * Preview Surface settings. */
set_viewport_material_props(mtl, usd_preview);
-
- /* Optionally, create shader nodes to represent a UsdPreviewSurface. */
- if (params_.import_shaders_mode == USD_IMPORT_USD_PREVIEW_SURFACE) {
- import_usd_preview(mtl, usd_preview);
- }
}
- if (params_.import_shaders_mode == USD_IMPORT_MDL) {
+ if (params_.import_shaders_mode == USD_IMPORT_USD_PREVIEW_SURFACE
+ && usd_preview) {
+ /* Create shader nodes to represent a UsdPreviewSurface. */
+ import_usd_preview(mtl, usd_preview);
+ }
+ else if (params_.import_shaders_mode == USD_IMPORT_MDL) {
+ bool imported_mdl = false;
#ifdef WITH_PYTHON
- umm_import_material(mtl, usd_material);
+ /* Invoke UMM to convert to MDL. */
+ imported_mdl = umm_import_material(mtl, usd_material, true /* Verbose */);
#endif
+ if (!imported_mdl && usd_preview) {
+ /* We failed to import an MDL, so fall back on importing UsdPreviewSuface. */
+ std::string message = "Couldn't import MDL shaders for material "
+ + mtl_name + ", importing USD Preview Surface shaders instead";
+ WM_reportf(RPT_INFO, message.c_str());
+ import_usd_preview(mtl, usd_preview);
+ }
}
return mtl;
diff --git a/source/blender/io/usd/intern/usd_umm.cc b/source/blender/io/usd/intern/usd_umm.cc
index c417a06da24..0dfc1d3d1d1 100644
--- a/source/blender/io/usd/intern/usd_umm.cc
+++ b/source/blender/io/usd/intern/usd_umm.cc
@@ -577,7 +577,11 @@ static bool import_material(Material *mtl,
if (ret) {
std::cout << "result:\n";
print_obj(ret);
- report_notification(ret);
+ if (report_notification(ret)) {
+ /* The function returned a notification object,
+ * indicating a failure. */
+ success = false;
+ }
Py_DECREF(ret);
}
@@ -712,7 +716,7 @@ bool umm_module_loaded()
return loaded;
}
-bool umm_import_material(Material *mtl, const pxr::UsdShadeMaterial &usd_material)
+bool umm_import_material(Material *mtl, const pxr::UsdShadeMaterial &usd_material, bool verbose)
{
if (!(mtl && usd_material)) {
return false;
@@ -725,13 +729,17 @@ bool umm_import_material(Material *mtl, const pxr::UsdShadeMaterial &usd_materia
/* Check if we have an mdl source asset. */
pxr::SdfAssetPath source_asset;
if (!surf_shader.GetSourceAsset(&source_asset, usdtokens::mdl)) {
- std::cout << "No mdl source asset for shader " << surf_shader.GetPath() << std::endl;
+ if (verbose) {
+ std::cout << "No mdl source asset for shader " << surf_shader.GetPath() << std::endl;
+ }
return false;
}
pxr::TfToken source_asset_sub_identifier;
if (!surf_shader.GetSourceAssetSubIdentifier(&source_asset_sub_identifier, usdtokens::mdl)) {
- std::cout << "No mdl source asset sub identifier for shader " << surf_shader.GetPath()
- << std::endl;
+ if (verbose) {
+ std::cout << "No mdl source asset sub identifier for shader " << surf_shader.GetPath()
+ << std::endl;
+ }
return false;
}
diff --git a/source/blender/io/usd/intern/usd_umm.h b/source/blender/io/usd/intern/usd_umm.h
index d63308cb4ee..ad8465a4e49 100644
--- a/source/blender/io/usd/intern/usd_umm.h
+++ b/source/blender/io/usd/intern/usd_umm.h
@@ -31,7 +31,7 @@ struct USDExporterContext;
bool umm_module_loaded();
-bool umm_import_material(Material *mtl, const pxr::UsdShadeMaterial &usd_material);
+bool umm_import_material(Material *mtl, const pxr::UsdShadeMaterial &usd_material, bool verbose = false);
bool umm_export_material(const USDExporterContext &usd_export_context,
const Material *mtl,
More information about the Bf-blender-cvs
mailing list