From 8e89d1c8680251b9e3fd3e5be758f8900ad8e274 Mon Sep 17 00:00:00 2001 From: kiki Date: Fri, 28 Jun 2024 20:01:06 -0400 Subject: [PATCH 1/2] USD Export Fix: When the World material has no texture input, export the color as a solid image so that Hydra doesn't choke. --- .../io/usd/intern/usd_light_convert.cc | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/source/blender/io/usd/intern/usd_light_convert.cc b/source/blender/io/usd/intern/usd_light_convert.cc index 3fd3cef91f3..e269a6cfa09 100644 --- a/source/blender/io/usd/intern/usd_light_convert.cc +++ b/source/blender/io/usd/intern/usd_light_convert.cc @@ -26,10 +26,14 @@ #include "BLI_fileops.h" #include "BLI_listbase.h" #include "BLI_math_vector.h" +#include "BLI_path_util.h" +#include "BLI_string.h" #include "DNA_node_types.h" #include "DNA_scene_types.h" #include "DNA_world_types.h" +#include "../hydra/image.hh" + #include #include "CLG_log.h" @@ -297,6 +301,34 @@ void world_material_to_dome_light(const USDExportParams ¶ms, pxr::UsdLuxDomeLight dome_light = pxr::UsdLuxDomeLight::Define(stage, env_light_path); + if (!res.env_tex_found) { + /* Like the Hydra delegate, if no texture is found export a solid + * color texture as a stand-in so that Hydra renderers don't + * throw errors. */ + + float fill_color[4] = {res.world_color[0], res.world_color[1], res.world_color[2], 1.0f}; + + std::string source_path = blender::io::hydra::cache_image_color(fill_color); + const std::string base_path = stage->GetRootLayer()->GetRealPath(); + + /* It'll be short, coming from cache_image_color. */ + char file_path[64]; + BLI_path_split_file_part(source_path.c_str(), file_path, 64); + char dest_path[FILE_MAX]; + BLI_path_split_dir_part(base_path.c_str(), dest_path, FILE_MAX); + + BLI_path_join(dest_path, FILE_MAX, dest_path, "textures", file_path); + + if (BLI_copy(source_path.c_str(), dest_path) != 0) { + CLOG_WARN(&LOG, "USD Export: Couldn't write world color image to %s", dest_path); + } + else { + res.env_tex_found = true; + BLI_path_join(dest_path, FILE_MAX, ".", "textures", file_path); + res.file_path = dest_path; + } + } + if (res.env_tex_found) { pxr::SdfAssetPath path(res.file_path); dome_light.CreateTextureFileAttr().Set(path); -- 2.30.2 From 37adfdbca9b674fd8008e868b1960f58cbc68c7f Mon Sep 17 00:00:00 2001 From: kiki Date: Fri, 28 Jun 2024 22:15:11 -0400 Subject: [PATCH 2/2] Good catch-- ensure the ./textures path is created, even if no other object in the scene has textures to export, when a non-textured domelight is exported. --- source/blender/io/usd/intern/usd_light_convert.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/io/usd/intern/usd_light_convert.cc b/source/blender/io/usd/intern/usd_light_convert.cc index e269a6cfa09..29dcda43fe6 100644 --- a/source/blender/io/usd/intern/usd_light_convert.cc +++ b/source/blender/io/usd/intern/usd_light_convert.cc @@ -317,7 +317,10 @@ void world_material_to_dome_light(const USDExportParams ¶ms, char dest_path[FILE_MAX]; BLI_path_split_dir_part(base_path.c_str(), dest_path, FILE_MAX); - BLI_path_join(dest_path, FILE_MAX, dest_path, "textures", file_path); + BLI_path_append_dir(dest_path, FILE_MAX, "textures"); + BLI_dir_create_recursive(dest_path); + + BLI_path_append(dest_path, FILE_MAX, file_path); if (BLI_copy(source_path.c_str(), dest_path) != 0) { CLOG_WARN(&LOG, "USD Export: Couldn't write world color image to %s", dest_path); -- 2.30.2