Commit: 61a9ee88a34d2db3fed7a50b2fa9aad030bb5f18 Author: Michael Kowalski Date: Thu Sep 29 20:16:07 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB61a9ee88a34d2db3fed7a50b2fa9aad030bb5f18
USD import: handle context-dependent UDIM paths. This change helps address the issue where contex-dependent UDIM texture paths (e.g., '0/foo.<UDIM>.png') were not getting resolved by the call to SdfLayer::::ComputeAbsolutePath(). To work around this limitation, I updated the code to compute the absolute path on just the parent directory portion of the UDIM file path. This makes the simplifying assumption that context-dependent asset paths are essentially relative paths, which might not always be correct. It's not clear how else to efficiently address this without performing a potentially expensive search. =================================================================== M source/blender/io/usd/intern/usd_reader_material.cc =================================================================== diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index 606a8395929..3376a930926 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -752,10 +752,37 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader &usd_shader, * necessary for UDIM paths). */ file_path = asset_path.GetAssetPath(); - /* Texture paths are frequently relative to the USD, so get - * the absolute path. */ - if (pxr::SdfLayerHandle layer_handle = get_layer_handle(file_input.GetAttr())) { - file_path = layer_handle->ComputeAbsolutePath(file_path); + if (!file_path.empty() && is_udim_path(file_path)) { + /* Texture paths are frequently relative to the USD, so get + * the absolute path. */ + if (pxr::SdfLayerHandle layer_handle = get_layer_handle(file_input.GetAttr())) { + + /* SdfLayer::ComputeAbsolutePath() doesn' work for context-dependent paths + * where the file name has a UDIM token (e.g., '0/foo.<UDIM>.png'). + * We therefore compute the absolube path of the parent directory of the + * UDIM file. */ + + char file[FILE_MAXFILE]; + char dir[FILE_MAXDIR]; + BLI_split_dirfile(file_path.c_str(), dir, file, sizeof(dir), sizeof(file)); + + if (strlen(dir) == 0) { + /* No directory in path, assume asset is a sibling of the layer. */ + dir[0] = '.'; + dir[1] = '\0'; + } + + /* Get the absolute path of the directory relative to the layer. */ + std::string dir_abs_path = layer_handle->ComputeAbsolutePath(dir); + + char result[FILE_MAX]; + /* Finally, join the original file name with the absolute path. */ + BLI_path_join(result, FILE_MAX, dir_abs_path.c_str(), file, nullptr); + + /* Use forward slashes. */ + BLI_str_replace_char(result, SEP, ALTSEP); + file_path = result; + } } } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs