[Bf-blender-cvs] [363aff2ad0a] universal-scene-description: USD export: fix apply_subdiv option.
Commit: 363aff2ad0a29da67f2ae57927ba83226d2f125a Author: Michael Kowalski Date: Mon Feb 6 11:37:22 2023 -0500 Branches: universal-scene-description https://developer.blender.org/rB363aff2ad0a29da67f2ae57927ba83226d2f125a USD export: fix apply_subdiv option. Fixed logic to disable applying subdivision modifiers on mesh export when the apply_subdiv USD export option is disabled. === M source/blender/io/usd/intern/usd_writer_mesh.cc === diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index f7965514bff..ceaa3e96a64 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -51,12 +51,12 @@ static const pxr::TfToken blenderDataNS("data:", pxr::TfToken::Immortal); /* check if the mesh is a subsurf, ignoring disabled modifiers and * displace if it's after subsurf. */ -static ModifierData *get_subsurf_modifier(Scene *scene, Object *ob) +static ModifierData *get_subsurf_modifier(Object *ob, ModifierMode mode) { ModifierData *md = static_cast(ob->modifiers.last); for (; md; md = md->prev) { -if (BKE_modifier_is_enabled(scene, md, eModifierMode_Render)) { +if (!BKE_modifier_is_enabled(nullptr, md, mode)) { continue; } @@ -120,10 +120,15 @@ void USDGenericMeshWriter::do_write(HierarchyContext ) { Object *object_eval = context.object; - m_subsurf_mod = get_subsurf_modifier(DEG_get_evaluated_scene(usd_export_context_.depsgraph), - context.object); + const ModifierMode mode = usd_export_context_.export_params.evaluation_mode == +DAG_EVAL_VIEWPORT ? +eModifierMode_Realtime : +eModifierMode_Render; - if (m_subsurf_mod && !usd_export_context_.export_params.apply_subdiv) { + m_subsurf_mod = get_subsurf_modifier(context.object, mode); + const bool should_disable_temporary = m_subsurf_mod && !usd_export_context_.export_params.apply_subdiv; + + if (should_disable_temporary) { m_subsurf_mod->mode |= eModifierMode_DisableTemporary; } @@ -178,7 +183,7 @@ void USDGenericMeshWriter::do_write(HierarchyContext ) if (usd_export_context_.export_params.export_custom_properties && mesh) write_id_properties(prim, mesh->id, get_export_time_code()); - if (m_subsurf_mod && !usd_export_context_.export_params.apply_subdiv) { + if (should_disable_temporary) { m_subsurf_mod->mode &= ~eModifierMode_DisableTemporary; } } ___ 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
[Bf-blender-cvs] [f359a39d115] master: Fix T100028: Convert USD camera properties to mm from USD units.
Commit: f359a39d11511721c5a201be6f6dcaa6d8780792 Author: Michael Kowalski Date: Mon Jan 30 17:22:26 2023 -0500 Branches: master https://developer.blender.org/rBf359a39d11511721c5a201be6f6dcaa6d8780792 Fix T100028: Convert USD camera properties to mm from USD units. Authored by Sonny Campbell. Currently when importing a USD file, some of the camera properties are ignored, or the units are not converted correctly from USD world units. On import we currently set the focal length, but not the camera sensor size (horizontal and vertical aperture), so the camera field of view is wrong. The sensor size information is in the USD file, but is ignored for perspective cameras. USD uses "tenth of a world unit" scale for some physical camera properties like focal length and aperture. https://graphics.pixar.com/usd/release/api/class_usd_geom_camera.html#UsdGeom_CameraUnits I have added the UsdStage's metersPerUnit parameter to the ImportSettings so the camera can do the required conversion on import. This will convert from the USD file's world units to millimeters for Blender's camera settings. Reviewed by: Sybren and makowalski. Differential Revision: https://developer.blender.org/D16019 === M source/blender/io/usd/intern/usd_capi_import.cc M source/blender/io/usd/intern/usd_reader_camera.cc M source/blender/io/usd/intern/usd_reader_prim.h M tests/python/bl_usd_import_test.py === diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index fb870eb154c..f60bca22e45 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -212,6 +212,7 @@ static void import_startjob(void *customdata, bool *stop, bool *do_update, float } convert_to_z_up(stage, >settings); + data->settings.stage_meters_per_unit = UsdGeomGetStageMetersPerUnit(stage); /* Set up the stage for animated data. */ if (data->params.set_frame_range) { diff --git a/source/blender/io/usd/intern/usd_reader_camera.cc b/source/blender/io/usd/intern/usd_reader_camera.cc index da51787e437..db47e6373c9 100644 --- a/source/blender/io/usd/intern/usd_reader_camera.cc +++ b/source/blender/io/usd/intern/usd_reader_camera.cc @@ -54,14 +54,19 @@ void USDCameraReader::read_object_data(Main *bmain, const double motionSampleTim pxr::VtValue horAp; cam_prim.GetHorizontalApertureAttr().Get(, motionSampleTime); - bcam->lens = val.Get(); - /* TODO(@makowalski): support sensor size. */ -#if 0 - bcam->sensor_x = 0.0f; - bcam->sensor_y = 0.0f; -#endif - bcam->shiftx = verApOffset.Get(); - bcam->shifty = horApOffset.Get(); + /* + * For USD, these camera properties are in tenths of a world unit. + * https://graphics.pixar.com/usd/release/api/class_usd_geom_camera.html#UsdGeom_CameraUnits + * tenth_of_unit = stage_meters_per_unit / 10 + * val_in_meters = val.Get() * tenth_of_unit + * val_in_millimeters = val_in_meters * 1000 + */ + const double scale_to_mm = 100.0 * settings_->stage_meters_per_unit; + bcam->lens = val.Get() * scale_to_mm; + bcam->sensor_x = horAp.Get() * scale_to_mm; + bcam->sensor_y = verAp.Get() * scale_to_mm; + bcam->shiftx = verApOffset.Get() * scale_to_mm; + bcam->shifty = horApOffset.Get() * scale_to_mm; bcam->type = (projectionVal.Get().GetString() == "perspective") ? CAM_PERSP : CAM_ORTHO; diff --git a/source/blender/io/usd/intern/usd_reader_prim.h b/source/blender/io/usd/intern/usd_reader_prim.h index 377228929ff..c909f7c27e7 100644 --- a/source/blender/io/usd/intern/usd_reader_prim.h +++ b/source/blender/io/usd/intern/usd_reader_prim.h @@ -49,6 +49,10 @@ struct ImportSettings { * and is mutable similar to the map above. */ mutable std::map mat_name_to_mat; + /* We use the stage metersPerUnit to convert camera properties from USD scene units to the + * correct millimeter scale that Blender uses for camera parameters. */ + double stage_meters_per_unit; + ImportSettings() : do_convert_mat(false), from_up(0), @@ -60,7 +64,8 @@ struct ImportSettings { sequence_offset(0), read_flag(0), validate_meshes(false), -cache_file(NULL) +cache_file(NULL), +stage_meters_per_unit(1.0) { } }; diff --git a/tests/python/bl_usd_import_test.py b/tests/python/bl_usd_import_test.py index 70c1ac1c127..438a5c48d73 100644 --- a/tests/python/bl_usd_import_test.py +++ b/tests/python/bl_usd_import_test.py @@ -155,6 +155,39 @@ class USDImportTest(AbstractUSDTest): coords = list(filter(lambda x: x[0] > 1.0, coords)) self.assertGreater(len(coords), 16) +def test_import_camera_properti
[Bf-blender-cvs] [f4deed288ba] master: USD export: style fixes to previous commit.
Commit: f4deed288ba946de0c23f3bac6075eaf1e9cfc84 Author: Michael Kowalski Date: Mon Jan 30 11:57:28 2023 -0500 Branches: master https://developer.blender.org/rBf4deed288ba946de0c23f3bac6075eaf1e9cfc84 USD export: style fixes to previous commit. Changed to C-style comments and added braces. === M source/blender/io/usd/intern/usd_writer_material.cc === diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 1f758bee86a..813579be22f 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -210,31 +210,36 @@ void set_normal_texture_range(pxr::UsdShadeShader _shader, const InputSpec & * The USD spec requires them to be within the -1 to 1 space * */ - // Only run if this input_spec is for a normal - if (input_spec.input_name != usdtokens::normal) + /* Only run if this input_spec is for a normal. */ + if (input_spec.input_name != usdtokens::normal) { return; + } - // Make sure this is a texture shader prim + /* Make sure this is a texture shader prim. */ pxr::TfToken shader_id; - if (!usd_shader.GetIdAttr().Get(_id) || shader_id != usdtokens::uv_texture) + if (!usd_shader.GetIdAttr().Get(_id) || shader_id != usdtokens::uv_texture) { return; + } - // We should only be setting this if the colorspace is raw. sRGB will not map the same. + /* We should only be setting this if the colorspace is raw. sRGB will not map the same. */ pxr::TfToken colorspace; auto colorspace_attr = usd_shader.GetInput(usdtokens::sourceColorSpace); - if (!colorspace_attr || !colorspace_attr.Get() || colorspace != usdtokens::raw) + if (!colorspace_attr || !colorspace_attr.Get() || colorspace != usdtokens::raw) { return; + } - // Get or Create the scale attribute and set it + /* Get or Create the scale attribute and set it. */ auto scale_attr = usd_shader.GetInput(usdtokens::scale); - if (!scale_attr) + if (!scale_attr) { scale_attr = usd_shader.CreateInput(usdtokens::scale, pxr::SdfValueTypeNames->Float4); + } scale_attr.Set(pxr::GfVec4f(2.0f, 2.0f, 2.0f, 2.0f)); - // Get or Create the bias attribute and set it + /* Get or Create the bias attribute and set it. */ auto bias_attr = usd_shader.GetInput(usdtokens::bias); - if (!bias_attr) + if (!bias_attr) { bias_attr = usd_shader.CreateInput(usdtokens::bias, pxr::SdfValueTypeNames->Float4); + } bias_attr.Set(pxr::GfVec4f(-1.0f, -1.0f, -1.0f, -1.0f)); } ___ 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
[Bf-blender-cvs] [c79b55fc056] master: USD export: add scale and bias for normal maps.
Commit: c79b55fc056bbe63818fdb5c697085dd1e0eaceb Author: Michael Kowalski Date: Mon Jan 30 11:32:03 2023 -0500 Branches: master https://developer.blender.org/rBc79b55fc056bbe63818fdb5c697085dd1e0eaceb USD export: add scale and bias for normal maps. Changes authored by Michael B Johnson (drwave). This addresses the issue in T102911. Add scale and bias inputs to ensure the normals are in tangent space [(-1,-1,-1), (1,1,1)]. This is following the convention as set in the USD Spec (https://graphics.pixar.com/usd/dev/spec_usdpreviewsurface.html). Differential Revision: https://developer.blender.org/D17072 === M source/blender/io/usd/intern/usd_writer_material.cc === diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 3e2f34b1b1e..1f758bee86a 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -61,6 +61,8 @@ static const pxr::TfToken normal("normal", pxr::TfToken::Immortal); static const pxr::TfToken ior("ior", pxr::TfToken::Immortal); static const pxr::TfToken file("file", pxr::TfToken::Immortal); static const pxr::TfToken raw("raw", pxr::TfToken::Immortal); +static const pxr::TfToken scale("scale", pxr::TfToken::Immortal); +static const pxr::TfToken bias("bias", pxr::TfToken::Immortal); static const pxr::TfToken sRGB("sRGB", pxr::TfToken::Immortal); static const pxr::TfToken sourceColorSpace("sourceColorSpace", pxr::TfToken::Immortal); static const pxr::TfToken Shader("Shader", pxr::TfToken::Immortal); @@ -114,6 +116,7 @@ static bNode *traverse_channel(bNodeSocket *input, short target_type); template void create_input(pxr::UsdShadeShader , const InputSpec , const void *value); +void set_normal_texture_range(pxr::UsdShadeShader _shader, const InputSpec _spec); void create_usd_preview_surface_material(const USDExporterContext _export_context, Material *material, pxr::UsdShadeMaterial _material, @@ -162,6 +165,7 @@ void create_usd_preview_surface_material(const USDExporterContext _export_co preview_surface.CreateInput(input_spec.input_name, input_spec.input_type) .ConnectToSource(created_shader.ConnectableAPI(), input_spec.source_name); + set_normal_texture_range(created_shader, input_spec); } else if (input_spec.set_default_value) { /* Set hardcoded value. */ @@ -200,6 +204,40 @@ void create_usd_preview_surface_material(const USDExporterContext _export_co } } +void set_normal_texture_range(pxr::UsdShadeShader _shader, const InputSpec _spec) +{ + /* Set the scale and bias for normal map textures + * The USD spec requires them to be within the -1 to 1 space + * */ + + // Only run if this input_spec is for a normal + if (input_spec.input_name != usdtokens::normal) +return; + + // Make sure this is a texture shader prim + pxr::TfToken shader_id; + if (!usd_shader.GetIdAttr().Get(_id) || shader_id != usdtokens::uv_texture) +return; + + // We should only be setting this if the colorspace is raw. sRGB will not map the same. + pxr::TfToken colorspace; + auto colorspace_attr = usd_shader.GetInput(usdtokens::sourceColorSpace); + if (!colorspace_attr || !colorspace_attr.Get() || colorspace != usdtokens::raw) +return; + + // Get or Create the scale attribute and set it + auto scale_attr = usd_shader.GetInput(usdtokens::scale); + if (!scale_attr) +scale_attr = usd_shader.CreateInput(usdtokens::scale, pxr::SdfValueTypeNames->Float4); + scale_attr.Set(pxr::GfVec4f(2.0f, 2.0f, 2.0f, 2.0f)); + + // Get or Create the bias attribute and set it + auto bias_attr = usd_shader.GetInput(usdtokens::bias); + if (!bias_attr) +bias_attr = usd_shader.CreateInput(usdtokens::bias, pxr::SdfValueTypeNames->Float4); + bias_attr.Set(pxr::GfVec4f(-1.0f, -1.0f, -1.0f, -1.0f)); +} + void create_usd_viewport_material(const USDExporterContext _export_context, Material *material, pxr::UsdShadeMaterial _material) ___ 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
[Bf-blender-cvs] [b67b84bd5d6] master: Fix T103984: USD exports pass usdchecker
Commit: b67b84bd5d6dea88a8941abe4205556a4a74f549 Author: Michael Kowalski Date: Fri Jan 27 10:29:58 2023 -0500 Branches: master https://developer.blender.org/rBb67b84bd5d6dea88a8941abe4205556a4a74f549 Fix T103984: USD exports pass usdchecker These changes were authored by Michael B Johnson (drwave). The default Blender USD export currently produces files that trigger errors in the usdchecker that ships with USD 22.11. The changes are: - Set the defaultPrim if no defaultPrim is set. This sets it to the first prim in the hierarchy which matches the behaviour of Pixar's referencing (where referencing a USD layer without a defaultPrim will pick the first prim) as well as matches the logic in Pixar's Maya USD exporter code. - Applies the MaterialBindingAPI to prims with material binding attributes. This is a relatively new requirement for USD as it will help for efficiency with upcoming changes to Hydra. - Removes the preview scope in the USD shader hierarchy, because it is no longer valid for shaders to have any non-container ancestors in their hierarchy up until the enclosing Material prim. Reviewed by: Michael Kowalski Differential Revision: https://developer.blender.org/D17041 === M source/blender/io/usd/intern/usd_capi_export.cc M source/blender/io/usd/intern/usd_writer_material.cc M source/blender/io/usd/intern/usd_writer_mesh.cc M source/blender/io/usd/tests/usd_export_test.cc === diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc index 1d33ca3a13c..7ab244f18f0 100644 --- a/source/blender/io/usd/intern/usd_capi_export.cc +++ b/source/blender/io/usd/intern/usd_capi_export.cc @@ -7,6 +7,8 @@ #include #include +#include +#include #include #include @@ -138,6 +140,17 @@ static void export_startjob(void *customdata, } iter.release_writers(); + + /* Set the default prim if it doesn't exist */ + if (!usd_stage->GetDefaultPrim()) { +/* Use TraverseAll since it's guaranteed to be depth first and will get the first top level + * prim, and is less verbose than getting the PseudoRoot + iterating its children.*/ +for (auto prim : usd_stage->TraverseAll()) { + usd_stage->SetDefaultPrim(prim); + break; +} + } + usd_stage->GetRootLayer()->Save(); /* Finish up by going back to the keyframe that was current before we started. */ diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 7e744b74f61..3e2f34b1b1e 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -60,7 +60,6 @@ static const pxr::TfToken out("out", pxr::TfToken::Immortal); static const pxr::TfToken normal("normal", pxr::TfToken::Immortal); static const pxr::TfToken ior("ior", pxr::TfToken::Immortal); static const pxr::TfToken file("file", pxr::TfToken::Immortal); -static const pxr::TfToken preview("preview", pxr::TfToken::Immortal); static const pxr::TfToken raw("raw", pxr::TfToken::Immortal); static const pxr::TfToken sRGB("sRGB", pxr::TfToken::Immortal); static const pxr::TfToken sourceColorSpace("sourceColorSpace", pxr::TfToken::Immortal); @@ -124,10 +123,6 @@ void create_usd_preview_surface_material(const USDExporterContext _export_co return; } - /* Define a 'preview' scope beneath the material which will contain the preview shaders. */ - pxr::UsdGeomScope::Define(usd_export_context.stage, - usd_material.GetPath().AppendChild(usdtokens::preview)); - /* Default map when creating UV primvar reader shaders. */ pxr::TfToken default_uv_sampler = default_uv.empty() ? cyclestokens::UVMap : pxr::TfToken(default_uv); @@ -470,9 +465,8 @@ static pxr::UsdShadeShader create_usd_preview_shader(const USDExporterContext const char *name, const int type) { - pxr::SdfPath shader_path = material.GetPath() - .AppendChild(usdtokens::preview) - .AppendChild(pxr::TfToken(pxr::TfMakeValidIdentifier(name))); + pxr::SdfPath shader_path = material.GetPath().AppendChild( + pxr::TfToken(pxr::TfMakeValidIdentifier(name))); pxr::UsdShadeShader shader = pxr::UsdShadeShader::Define(usd_export_context.stage, shader_path); switch (type) { diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index 7f3444d88f4..62656c902d0 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/
[Bf-blender-cvs] [e735bf02cb5] master: Fix linux/mac compiler warning.
Commit: e735bf02cb5d73f7ab96f6ef4032ab758d890b60 Author: Michael Kowalski Date: Thu Jan 26 20:16:07 2023 -0500 Branches: master https://developer.blender.org/rBe735bf02cb5d73f7ab96f6ef4032ab758d890b60 Fix linux/mac compiler warning. === M source/blender/io/usd/intern/usd_reader_stage.cc === diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc index 0c179ceae48..3ee5e666d38 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.cc +++ b/source/blender/io/usd/intern/usd_reader_stage.cc @@ -355,7 +355,7 @@ void USDStageReader::fake_users_for_unused_materials() { /* Iterate over the imported materials and set a fake user for any unused * materials. */ - for (const std::pair _mat_pair : settings_.usd_path_to_mat_name) { + for (const std::pair _mat_pair : settings_.usd_path_to_mat_name) { std::map::iterator mat_it = settings_.mat_name_to_mat.find( path_mat_pair.second); ___ 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
[Bf-blender-cvs] [ebccb23bba6] tmp-mak-012623: Fix linux/mac warnings.
Commit: ebccb23bba6b8ba3a74bbd078b1d3622032fe778 Author: Michael Kowalski Date: Thu Jan 26 19:45:00 2023 -0500 Branches: tmp-mak-012623 https://developer.blender.org/rBebccb23bba6b8ba3a74bbd078b1d3622032fe778 Fix linux/mac warnings. === M source/blender/io/usd/intern/usd_reader_stage.cc === diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc index 0c179ceae48..3ee5e666d38 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.cc +++ b/source/blender/io/usd/intern/usd_reader_stage.cc @@ -355,7 +355,7 @@ void USDStageReader::fake_users_for_unused_materials() { /* Iterate over the imported materials and set a fake user for any unused * materials. */ - for (const std::pair _mat_pair : settings_.usd_path_to_mat_name) { + for (const std::pair _mat_pair : settings_.usd_path_to_mat_name) { std::map::iterator mat_it = settings_.mat_name_to_mat.find( path_mat_pair.second); ___ 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
[Bf-blender-cvs] [cdef135f6f6] master: USD import: Support importing USDZ.
Commit: cdef135f6f651c669f526a931a3cfd996d1e8cbd Author: Michael Kowalski Date: Thu Jan 26 18:08:45 2023 -0500 Branches: master https://developer.blender.org/rBcdef135f6f651c669f526a931a3cfd996d1e8cbd USD import: Support importing USDZ. This addressed feature request T99811. Added the following features to fully support importing USDZ archives: - Added .usdz to the list of supported extensions. - Added new USD import options to copy textures from USDZ archives. The textures may be imported as packed data (the default) or to a directory on disk. - Extended the USD material import logic to handle package-relative texture assets paths by invoking the USD asset resolver to copy the textures from the USDZ archive to a directory on disk. When importing in Packed mode, the textures are first saved to Blender's temporary session directory prior to packing. The new USD import options are - Import Textures: Behavior when importing textures from a USDZ archive - Textures Directory: Path to the directory where imported textures will be copied - File Name Collision: Behavior when the name of an imported texture file conflicts with an existing file Import Textures menu options: - None: Don't import textures - Packed: Import textures as packed data (the default) - Copy: Copy files to Textures Directory File Name Collision menu options: - Use Existing: If a file with the same name already exists, use that instead of copying (the default) - Overwrite: Overwrite existing files Reviewed by: Bastien Differential Revision: https://developer.blender.org/D17074 === M release/scripts/startup/bl_ui/space_topbar.py M source/blender/blenkernel/intern/cachefile.c M source/blender/editors/io/io_usd.c M source/blender/editors/space_file/filelist.cc M source/blender/io/usd/CMakeLists.txt A source/blender/io/usd/intern/usd_asset_utils.cc A source/blender/io/usd/intern/usd_asset_utils.h M source/blender/io/usd/intern/usd_reader_material.cc M source/blender/io/usd/usd.h === diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py index 97f8a1bfad1..50bb1e42602 100644 --- a/release/scripts/startup/bl_ui/space_topbar.py +++ b/release/scripts/startup/bl_ui/space_topbar.py @@ -468,7 +468,7 @@ class TOPBAR_MT_file_import(Menu): self.layout.operator("wm.alembic_import", text="Alembic (.abc)") if bpy.app.build_options.usd: self.layout.operator( -"wm.usd_import", text="Universal Scene Description (.usd, .usdc, .usda)") +"wm.usd_import", text="Universal Scene Description (.usd*)") if bpy.app.build_options.io_gpencil: self.layout.operator("wm.gpencil_import_svg", text="SVG as Grease Pencil") diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index 5d19db323f8..5968a6b7296 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -366,7 +366,7 @@ void BKE_cachefile_eval(Main *bmain, Depsgraph *depsgraph, CacheFile *cache_file } #endif #ifdef WITH_USD - if (BLI_path_extension_check_glob(filepath, "*.usd;*.usda;*.usdc")) { + if (BLI_path_extension_check_glob(filepath, "*.usd;*.usda;*.usdc;*.usdz")) { cache_file->type = CACHEFILE_TYPE_USD; cache_file->handle = USD_create_handle(bmain, filepath, _file->object_paths); BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX); diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 99d4e84cfd4..e6426732584 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -72,6 +72,23 @@ const EnumPropertyItem rna_enum_usd_mtl_name_collision_mode_items[] = { {0, NULL, 0, NULL, NULL}, }; +const EnumPropertyItem rna_enum_usd_tex_import_mode_items[] = { +{USD_TEX_IMPORT_NONE, "IMPORT_NONE", 0, "None", "Don't import textures"}, +{USD_TEX_IMPORT_PACK, "IMPORT_PACK", 0, "Packed", "Import textures as packed data"}, +{USD_TEX_IMPORT_COPY, "IMPORT_COPY", 0, "Copy", "Copy files to Textures Directory"}, +{0, NULL, 0, NULL, NULL}, +}; + +const EnumPropertyItem rna_enum_usd_tex_name_collision_mode_items[] = { +{USD_TEX_NAME_COLLISION_USE_EXISTING, + "USE_EXISTING", + 0, + "Use Existing", + "If a file with the same name already exists, use that instead of copying"}, +{USD_TEX_NAME_COLLISION_OVERWRITE, "OVERWRITE", 0, "Overwrite", "Overwrite existing files"}, +{0, NULL, 0, N
[Bf-blender-cvs] [f19f50d288e] master: USD export test format fixes.
Commit: f19f50d288e2751bf36d7d4d1261008c7ea19da5 Author: Michael Kowalski Date: Thu Jan 26 10:35:14 2023 -0500 Branches: master https://developer.blender.org/rBf19f50d288e2751bf36d7d4d1261008c7ea19da5 USD export test format fixes. === M source/blender/io/usd/tests/usd_export_test.cc === diff --git a/source/blender/io/usd/tests/usd_export_test.cc b/source/blender/io/usd/tests/usd_export_test.cc index c13da695c87..c34ab7cd6f7 100644 --- a/source/blender/io/usd/tests/usd_export_test.cc +++ b/source/blender/io/usd/tests/usd_export_test.cc @@ -25,8 +25,8 @@ #include "BKE_node.h" #include "BLI_fileops.h" #include "BLI_math.h" -#include "BLI_path_util.h" #include "BLI_math_vector_types.hh" +#include "BLI_path_util.h" #include "BLO_readfile.h" #include "BKE_node_runtime.hh" @@ -45,11 +45,9 @@ const StringRefNull simple_scene_filename = "usd/usd_simple_scene.blend"; const StringRefNull materials_filename = "usd/usd_materials_export.blend"; const StringRefNull output_filename = "output.usd"; - static const bNode *find_node_for_type_in_graph(const bNodeTree *nodetree, const blender::StringRefNull type_idname); - class UsdExportTest : public BlendfileLoadingBaseTest { protected: struct bContext *context = nullptr; @@ -104,7 +102,9 @@ class UsdExportTest : public BlendfileLoadingBaseTest { * Loop the sockets on the Blender bNode, and fail if any of their values do * not match the equivalent Attribtue values on the UsdPrim. */ - const void compare_blender_node_to_usd_prim(const bNode *bsdf_node, const pxr::UsdPrim& bsdf_prim) { + const void compare_blender_node_to_usd_prim(const bNode *bsdf_node, + const pxr::UsdPrim _prim) + { ASSERT_NE(bsdf_node, nullptr); ASSERT_TRUE(bool(bsdf_prim)); @@ -155,7 +155,9 @@ class UsdExportTest : public BlendfileLoadingBaseTest { } } - const void compare_blender_image_to_usd_image_shader(const bNode *image_node, const pxr::UsdPrim& image_prim) { + const void compare_blender_image_to_usd_image_shader(const bNode *image_node, + const pxr::UsdPrim _prim) + { const Image *image = reinterpret_cast(image_node->id); const pxr::UsdShadeShader image_shader(image_prim); @@ -171,14 +173,16 @@ class UsdExportTest : public BlendfileLoadingBaseTest { /* The path is expected to be relative, but that means in Blender the * path will start with //. */ -EXPECT_EQ(BLI_path_cmp_normalized(image->filepath+2, image_prim_asset.GetAssetPath().c_str()), 0); +EXPECT_EQ( +BLI_path_cmp_normalized(image->filepath + 2, image_prim_asset.GetAssetPath().c_str()), 0); } /* * Determine if a Blender Mesh matches a UsdGeomMesh prim by checking counts * on vertices, faces, face indices, and normals. */ - const void compare_blender_mesh_to_usd_prim(const Mesh *mesh, const pxr::UsdGeomMesh& mesh_prim) { + const void compare_blender_mesh_to_usd_prim(const Mesh *mesh, const pxr::UsdGeomMesh _prim) + { pxr::VtIntArray face_indices; pxr::VtIntArray face_counts; pxr::VtVec3fArray positions; @@ -196,10 +200,8 @@ class UsdExportTest : public BlendfileLoadingBaseTest { EXPECT_EQ(mesh->totloop, face_indices.size()); EXPECT_EQ(mesh->totloop, normals.size()); } - }; - TEST_F(UsdExportTest, usd_export_rain_mesh) { if (!load_file_and_depsgraph(simple_scene_filename)) { @@ -239,8 +241,8 @@ TEST_F(UsdExportTest, usd_export_rain_mesh) } } - -static const bNode *find_node_for_type_in_graph(const bNodeTree *nodetree, const blender::StringRefNull type_idname) +static const bNode *find_node_for_type_in_graph(const bNodeTree *nodetree, +const blender::StringRefNull type_idname) { auto found_nodes = nodetree->nodes_by_type(type_idname); if (found_nodes.size() == 1) { @@ -250,7 +252,6 @@ static const bNode *find_node_for_type_in_graph(const bNodeTree *nodetree, const return nullptr; } - /* * Export Material test-- export a scene with a material, then read it back * in and check that the BSDF and Image Texture nodes translated correctly @@ -269,7 +270,8 @@ TEST_F(UsdExportTest, usd_export_material) /* There are two materials because of the Dots Stroke. */ EXPECT_EQ(BLI_listbase_count(>main->materials), 2); - Material *material = reinterpret_cast(BKE_libblock_find_name(bfile->main, ID_MA, "Material")); + Material *material = reinterpret_cast( + BKE_libblock_find_name(bfile->main, ID_MA, "Material")); EXPECT_TRUE(bool(material))
[Bf-blender-cvs] [fa57c691f66] master: USD IO CI Tests
Commit: fa57c691f663bf4b446ccf0f91ce82ed9a2078b2 Author: Michael Kowalski Date: Wed Jan 25 14:51:39 2023 -0500 Branches: master https://developer.blender.org/rBfa57c691f663bf4b446ccf0f91ce82ed9a2078b2 USD IO CI Tests Various new CI tests for USD Import / Export functionalty: Import: - Added mesh import tests for topology types and multiple UV sets. (Python) Export: - Added a verification tests for mesh topology. (C++) - Added a test to make sure UsdPreviewSurface export conversion of materials is correct. (C++) Reviewed by: Sybren and Hans. Differential Revision: https://developer.blender.org/D16274 === M source/blender/blenloader/tests/blendfile_loading_base_test.cc M source/blender/io/usd/CMakeLists.txt M source/blender/io/usd/intern/usd_capi_export.cc M source/blender/io/usd/intern/usd_capi_import.cc M source/blender/io/usd/intern/usd_writer_material.cc M source/blender/io/usd/intern/usd_writer_material.h A source/blender/io/usd/tests/usd_export_test.cc M tests/python/bl_usd_import_test.py === diff --git a/source/blender/blenloader/tests/blendfile_loading_base_test.cc b/source/blender/blenloader/tests/blendfile_loading_base_test.cc index 6f190ce427e..6613c65c42a 100644 --- a/source/blender/blenloader/tests/blendfile_loading_base_test.cc +++ b/source/blender/blenloader/tests/blendfile_loading_base_test.cc @@ -103,8 +103,8 @@ void BlendfileLoadingBaseTest::TearDownTestCase() void BlendfileLoadingBaseTest::TearDown() { BKE_mball_cubeTable_free(); - depsgraph_free(); blendfile_free(); + depsgraph_free(); testing::Test::TearDown(); } diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt index ebd292782c0..862bd41c087 100644 --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@ -163,13 +163,18 @@ target_link_libraries(bf_usd INTERFACE ${TBB_LIBRARIES}) if(WITH_GTESTS) set(TEST_SRC tests/usd_stage_creation_test.cc +tests/usd_export_test.cc tests/usd_tests_common.cc tests/usd_tests_common.h + +intern/usd_writer_material.h ) if(USD_IMAGING_HEADERS) list(APPEND TEST_SRC tests/usd_imaging_test.cc) endif() + include_directories(intern) + set(TEST_INC ) set(TEST_LIB diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc index 28da9e388c5..1d33ca3a13c 100644 --- a/source/blender/io/usd/intern/usd_capi_export.cc +++ b/source/blender/io/usd/intern/usd_capi_export.cc @@ -66,7 +66,9 @@ static void export_startjob(void *customdata, data->start_time = timeit::Clock::now(); G.is_rendering = true; - WM_set_locked_interface(data->wm, true); + if (data->wm) { +WM_set_locked_interface(data->wm, true); + } G.is_break = false; /* Construct the depsgraph for exporting. */ @@ -160,7 +162,9 @@ static void export_endjob(void *customdata) } G.is_rendering = false; - WM_set_locked_interface(data->wm, false); + if (data->wm) { +WM_set_locked_interface(data->wm, false); + } report_job_duration(data); } diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 66319a7f04e..fb870eb154c 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -207,6 +207,7 @@ static void import_startjob(void *customdata, bool *stop, bool *do_update, float if (!stage) { WM_reportf(RPT_ERROR, "USD Import: unable to open stage to read %s", data->filepath); data->import_ok = false; +data->error_code = USD_ARCHIVE_FAIL; return; } diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 98cd4036fd0..7e744b74f61 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -748,4 +748,16 @@ static void export_texture(bNode *node, } } +const pxr::TfToken token_for_input(const char *input_name) +{ + const InputSpecMap _map = preview_surface_input_map(); + const InputSpecMap::const_iterator it = input_map.find(input_name); + + if (it == input_map.end()) { +return pxr::TfToken(); + } + + return it->second.input_name; +} + } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_material.h b/source/blender/io/usd/intern/usd_writer_material.h index fdfd13871ff..c6123b3cce2 100644 --- a/source/blender/io/usd/intern/usd_writer_material.h +++ b/source/blender/io/usd/intern/usd_writer_material.h @@ -14,6 +14,10 @@ namespace blender::io::usd { struct USDExporterContext; +/* Returns a USDPreviewSurface token name for a given Blender shader Socket name, + * or an empty TfToke
[Bf-blender-cvs] [ffe45ad87a5] master: USD import unused materials.
Commit: ffe45ad87a564fd2cb7d53f222785ecb608a6e30 Author: Michael Kowalski Date: Wed Jan 25 10:46:07 2023 -0500 Branches: master https://developer.blender.org/rBffe45ad87a564fd2cb7d53f222785ecb608a6e30 USD import unused materials. Added a new Import All Materials USD import option. When this option is enabled, USD materials not used by any geometry will be included in the import. Imported materials with no users will have a fake user assigned. Maniphest Tasks: T97195 Differential Revision: https://developer.blender.org/D16172 === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_capi_import.cc M source/blender/io/usd/intern/usd_reader_material.cc M source/blender/io/usd/intern/usd_reader_material.h M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/usd/intern/usd_reader_stage.cc M source/blender/io/usd/intern/usd_reader_stage.h M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index acd60bbd40a..99d4e84cfd4 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -381,6 +381,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const bool import_proxy = RNA_boolean_get(op->ptr, "import_proxy"); const bool import_render = RNA_boolean_get(op->ptr, "import_render"); + const bool import_all_materials = RNA_boolean_get(op->ptr, "import_all_materials"); + const bool import_usd_preview = RNA_boolean_get(op->ptr, "import_usd_preview"); const bool set_material_blend = RNA_boolean_get(op->ptr, "set_material_blend"); @@ -427,7 +429,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .import_usd_preview = import_usd_preview, .set_material_blend = set_material_blend, .light_intensity_scale = light_intensity_scale, - .mtl_name_collision_mode = mtl_name_collision_mode}; + .mtl_name_collision_mode = mtl_name_collision_mode, + .import_all_materials = import_all_materials}; STRNCPY(params.prim_path_mask, prim_path_mask); @@ -480,6 +483,7 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) box = uiLayoutBox(layout); col = uiLayoutColumnWithHeading(box, true, IFACE_("Materials")); + uiItemR(col, ptr, "import_all_materials", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_usd_preview", 0, NULL, ICON_NONE); uiLayoutSetEnabled(col, RNA_boolean_get(ptr, "import_materials")); uiLayout *row = uiLayoutRow(col, true); @@ -579,6 +583,14 @@ void WM_OT_usd_import(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "import_render", true, "Render", "Import final render geometry"); + RNA_def_boolean(ot->srna, + "import_all_materials", + false, + "Import All Materials", + "Also import materials that are not used by any geometry. " + "Note that when this option is false, materials referenced " + "by geometry will still be imported"); + RNA_def_boolean(ot->srna, "import_usd_preview", true, diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 600d1f0a9eb..66319a7f04e 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -227,6 +227,10 @@ static void import_startjob(void *customdata, bool *stop, bool *do_update, float archive->collect_readers(data->bmain); + if (data->params.import_materials && data->params.import_all_materials) { +archive->import_all_materials(data->bmain); + } + *data->do_update = true; *data->progress = 0.2f; @@ -352,6 +356,10 @@ static void import_endjob(void *customdata) DEG_id_tag_update(>scene->id, ID_RECALC_BASE_FLAGS); DEG_relations_tag_update(data->bmain); + +if (data->params.import_materials && data->params.import_all_materials) { + data->archive->fake_users_for_unused_materials(); +} } WM_set_locked_interface(data->wm, false); diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index d1af4553083..351f9bc3438 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/u
[Bf-blender-cvs] [e49e5f6f081] master: Enable USD Preview Surface import by default
Commit: e49e5f6f081d9e58837e14131cd732e4ac8b1696 Author: Michael Kowalski Date: Mon Jan 23 11:58:15 2023 -0500 Branches: master https://developer.blender.org/rBe49e5f6f081d9e58837e14131cd732e4ac8b1696 Enable USD Preview Surface import by default The USD Preview Surface material import feature is now considered stable, so this patch removes this option from the Experimental category in the UI. The Import USD Preview option is now enabled by default. The Experimental box has been removed. A new Materials box has been added to group the Import USD Preview Surface, Set Material Blend and Material Collision Mode options. Reviewed by: Sybren Differential Revision: https://developer.blender.org/D17053 === M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index c776fbf0dd7..acd60bbd40a 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -477,15 +477,15 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) uiItemR(col, ptr, "relative_path", 0, NULL, ICON_NONE); uiItemR(col, ptr, "create_collection", 0, NULL, ICON_NONE); uiItemR(box, ptr, "light_intensity_scale", 0, NULL, ICON_NONE); - uiItemR(box, ptr, "mtl_name_collision_mode", 0, NULL, ICON_NONE); box = uiLayoutBox(layout); - col = uiLayoutColumnWithHeading(box, true, IFACE_("Experimental")); + col = uiLayoutColumnWithHeading(box, true, IFACE_("Materials")); uiItemR(col, ptr, "import_usd_preview", 0, NULL, ICON_NONE); uiLayoutSetEnabled(col, RNA_boolean_get(ptr, "import_materials")); uiLayout *row = uiLayoutRow(col, true); uiItemR(row, ptr, "set_material_blend", 0, NULL, ICON_NONE); uiLayoutSetEnabled(row, RNA_boolean_get(ptr, "import_usd_preview")); + uiItemR(col, ptr, "mtl_name_collision_mode", 0, NULL, ICON_NONE); } void WM_OT_usd_import(struct wmOperatorType *ot) @@ -581,7 +581,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "import_usd_preview", - false, + true, "Import USD Preview", "Convert UsdPreviewSurface shaders to Principled BSDF shader networks"); ___ 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
[Bf-blender-cvs] [90c6674f281] master: Fix T102615: crash on USD export for scenes with point clouds or hair
Commit: 90c6674f281bdf064b2c9607d3b0f81f41ef Author: Michael Kowalski Date: Thu Jan 19 10:57:22 2023 -0500 Branches: master https://developer.blender.org/rB90c6674f281bdf064b2c9607d3b0f81f41ef Fix T102615: crash on USD export for scenes with point clouds or hair Code authored by Michael B Johnson (drwave). Reviewed by Sybren and makowalski. This patch addresses a crash that occurs when exporting a scene to a USD file, when that scene includes a point cloud object or hair. Added OB_POINTCLOUD and OB_CURVES enums and a default case statement in the switch statement in USDHierarchyIterator::create_data_writer, to avoid dereferencing a NULL pointer. Differential Revision: https://developer.blender.org/D16776 === M source/blender/io/usd/intern/usd_hierarchy_iterator.cc === diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc index fbfda975055..abf6c0cb0f9 100644 --- a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc +++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc @@ -118,10 +118,15 @@ AbstractHierarchyWriter *USDHierarchyIterator::create_data_writer(const Hierarch case OB_LATTICE: case OB_ARMATURE: case OB_GPENCIL: +case OB_POINTCLOUD: +case OB_CURVES: return nullptr; case OB_TYPE_MAX: BLI_assert_msg(0, "OB_TYPE_MAX should not be used"); return nullptr; +default: + BLI_assert_unreachable(); + return nullptr; } if (!data_writer->is_supported(context)) { ___ 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
[Bf-blender-cvs] [f8b11528b29] master: USD export: ensure edit mode changes are exported
Commit: f8b11528b29b1f7565475679715e1e0c80e266de Author: Michael Kowalski Date: Tue Jan 17 10:24:43 2023 -0500 Branches: master https://developer.blender.org/rBf8b11528b29b1f7565475679715e1e0c80e266de USD export: ensure edit mode changes are exported Code authored by Charles Wardlaw. Reviewed by Bastien, Sybren and makowalski. Differential Revision: https://developer.blender.org/D15916 === M source/blender/io/usd/intern/usd_writer_mesh.cc === diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index 9551fea75fb..7f3444d88f4 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -18,6 +18,7 @@ #include "BKE_lib_id.h" #include "BKE_material.h" #include "BKE_mesh.h" +#include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_object.h" @@ -151,6 +152,8 @@ void USDGenericMeshWriter::write_mesh(HierarchyContext , Mesh *mesh) write_visibility(context, timecode, usd_mesh); USDMeshData usd_mesh_data; + /* Ensure data exists if currently in edit mode. */ + BKE_mesh_wrapper_ensure_mdata(mesh); get_geometry_data(mesh, usd_mesh_data); if (usd_export_context_.export_params.use_instancing && context.is_instance()) { ___ 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
[Bf-blender-cvs] [56a97ba816c] universal-scene-description: USD import: fix crash on empty blendshapes.
Commit: 56a97ba816c4d4090ded4a9b69c558b362556d89 Author: Michael Kowalski Date: Sun Jan 8 20:54:57 2023 -0500 Branches: universal-scene-description https://developer.blender.org/rB56a97ba816c4d4090ded4a9b69c558b362556d89 USD import: fix crash on empty blendshapes. Now guarding against an empty offsets array and out-of-bounds offset indices. === M source/blender/io/usd/intern/usd_skel_convert.cc === diff --git a/source/blender/io/usd/intern/usd_skel_convert.cc b/source/blender/io/usd/intern/usd_skel_convert.cc index 69ab05c234e..03535326d84 100644 --- a/source/blender/io/usd/intern/usd_skel_convert.cc +++ b/source/blender/io/usd/intern/usd_skel_convert.cc @@ -260,6 +260,11 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim) continue; } +if (offsets.empty()) { + std::cout << "No offsets for blendshape " << path << std::endl; + continue; +} + shapekey_names.insert(blendshapes[i]); kb = BKE_keyblock_add(key, blendshapes[i].GetString().c_str()); @@ -274,6 +279,11 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim) if (point_indices.empty()) { for (int a = 0; a < kb->totelem; ++a, fp += 3) { +if (a >= offsets.size()) { + std::cout << "Number of offsets greater than number of mesh vertices for blendshape " +<< path << std::endl; + break; +} add_v3_v3(fp, offsets[a].data()); } } @@ -281,10 +291,14 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim) int a = 0; for (int i : point_indices) { if (i < 0 || i > kb->totelem) { - std::cout << "out of bounds point index " << i << std::endl; + std::cout << "Out of bounds point index " << i << " for blendshape " << path << std::endl; ++a; continue; } +if (a >= offsets.size()) { + std::cout << "Number of offsets greater than number of mesh vertices for blendshape " << path << std::endl; + break; +} add_v3_v3([3 * i], offsets[a].data()); ++a; } ___ 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
[Bf-blender-cvs] [1f9e90bb1cf] universal-scene-description: USD export: incorrect blend shape base mesh.
Commit: 1f9e90bb1cf3b6ec52d741425421f87653c8db97 Author: Michael Kowalski Date: Mon Jan 9 11:32:24 2023 -0500 Branches: universal-scene-description https://developer.blender.org/rB1f9e90bb1cf3b6ec52d741425421f87653c8db97 USD export: incorrect blend shape base mesh. Fixed error acquiring un-modified Blender mesh when creating USD blendshape base meshes. === M source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc === diff --git a/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc b/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc index 44c2d1947f4..231f7a24166 100644 --- a/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc @@ -355,9 +355,9 @@ Mesh *USDBlendShapeMeshWriter::get_export_mesh(Object *object_eval, bool _need return nullptr; } - Mesh *src_mesh = static_cast(object_eval->data); + Mesh *src_mesh = BKE_object_get_pre_modified_mesh(object_eval); - if (!src_mesh->key || !src_mesh->key->block.first) { + if (!src_mesh || !src_mesh->key || !src_mesh->key->block.first) { return nullptr; } ___ 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
[Bf-blender-cvs] [921fc1e44ce] universal-scene-description: USD export: fix export parameter memory leak.
Commit: 921fc1e44cedd595b4048c6e7476cdf54817f5e5 Author: Michael Kowalski Date: Wed Dec 28 17:58:01 2022 -0500 Branches: universal-scene-description https://developer.blender.org/rB921fc1e44cedd595b4048c6e7476cdf54817f5e5 USD export: fix export parameter memory leak. Now freeing default_prim_custom_kind export option string. === M source/blender/io/usd/intern/usd_capi_export.cc === diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc index 8c724e6c0be..9e69f9f6bdb 100644 --- a/source/blender/io/usd/intern/usd_capi_export.cc +++ b/source/blender/io/usd/intern/usd_capi_export.cc @@ -572,6 +572,7 @@ static void export_endjob(void *customdata) MEM_freeN(data->params.default_prim_path); MEM_freeN(data->params.root_prim_path); MEM_freeN(data->params.material_prim_path); + MEM_freeN(data->params.default_prim_custom_kind); if (data->was_canceled && BLI_exists(data->filepath)) { BLI_delete(data->filepath, false, false); ___ 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
[Bf-blender-cvs] [91368f7b7dc] universal-scene-description: USD import: fix crash adding event notifiers.
Commit: 91368f7b7dc5ec29a4f28d64ff59faf4ee575d01 Author: Michael Kowalski Date: Wed Dec 28 15:53:07 2022 -0500 Branches: universal-scene-description https://developer.blender.org/rB91368f7b7dc5ec29a4f28d64ff59faf4ee575d01 USD import: fix crash adding event notifiers. Fixed crash due to race condition adding event notifiers when converting materials when the importer is invoked in a background job. Now acquiring the main thread lock before reading object data, to avoid possible crashes when event notifiers are added by timers for progress updates in the main thread. === M source/blender/io/usd/intern/usd_capi_import.cc === diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index b0913db3d0f..ced906149f0 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -284,8 +284,25 @@ struct ImportJobData { bool was_canceled; bool import_ok; timeit::TimePoint start_time; + + wmJob *wm_job; }; +static void main_thread_lock_acquire(ImportJobData *data) +{ + if (data->wm_job) { +WM_job_main_thread_lock_acquire(data->wm_job); + } +} + +static void main_thread_lock_release(ImportJobData *data) +{ + if (data->wm_job) { +WM_job_main_thread_lock_release(data->wm_job); + } +} + + static CacheFile *create_cache_file(const ImportJobData *data) { if (!data) { @@ -505,6 +522,17 @@ static void import_startjob(void *customdata, bool *stop, bool *do_update, float } } + *data->do_update = true; + *data->progress = 0.5f; + + /* Reading materials may trigger adding event notifiers, which + * isn't thread safe when the importer is invoked in a background + * job. We therefore acquire the main thread lock before reading + * object data, to avoid possible crashes when events are added + * in job timers for progress updates in the main thread. + * (See wm_jobs_timer()). */ + main_thread_lock_acquire(data); + /* Setup parenthood and read actual object data. */ i = 0; for (USDPrimReader *reader : archive->readers()) { @@ -528,15 +556,22 @@ static void import_startjob(void *customdata, bool *stop, bool *do_update, float ob->parent = parent->object(); } -*data->progress = 0.5f + 0.5f * (++i / size); -*data->do_update = true; +if ((++i & 255) == 0) { + main_thread_lock_release(data); + *data->progress = 0.5f + 0.5f * (i / size); + *data->do_update = true; + main_thread_lock_acquire(data); +} if (G.is_break) { data->was_canceled = true; + main_thread_lock_release(data); return; } } + main_thread_lock_release(data); + if (data->params.import_skeletons) { archive->process_armature_modifiers(); } @@ -708,6 +743,8 @@ bool USD_import(struct bContext *C, WM_JOB_PROGRESS, WM_JOB_TYPE_ALEMBIC); +job->wm_job = wm_job; + /* setup job */ WM_jobs_customdata_set(wm_job, job, import_freejob); WM_jobs_timer(wm_job, 0.1, NC_SCENE, NC_SCENE); ___ 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
[Bf-blender-cvs] [edc59cefb66] universal-scene-description: USD import: fix prim_path_mask storage.
Commit: edc59cefb66542d2f9cf11496d15ab2cff419b2b Author: Michael Kowalski Date: Wed Dec 14 12:18:08 2022 -0500 Branches: universal-scene-description https://developer.blender.org/rBedc59cefb66542d2f9cf11496d15ab2cff419b2b USD import: fix prim_path_mask storage. Now accessing the prm_path_mask string property as an allocated string, as the string is of arbitrary length. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_capi_import.cc M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 0e26d6e8820..b1b511affa0 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -1119,8 +1119,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const bool create_collection = RNA_boolean_get(op->ptr, "create_collection"); - char prim_path_mask[1024]; - RNA_string_get(op->ptr, "prim_path_mask", prim_path_mask); + char *prim_path_mask = RNA_string_get_alloc(op->ptr, "prim_path_mask", NULL, 0, NULL); const bool import_guide = RNA_boolean_get(op->ptr, "import_guide"); const bool import_proxy = RNA_boolean_get(op->ptr, "import_proxy"); @@ -1198,8 +1197,6 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .import_shapes = import_shapes, .import_defined_only = import_defined_only}; - STRNCPY(params.prim_path_mask, prim_path_mask); - const bool ok = USD_import(C, filename, , as_background_job); return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index e26e2d36adb..b0913db3d0f 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -648,6 +648,8 @@ static void import_endjob(void *customdata) break; } + MEM_freeN(data->params.prim_path_mask); + WM_main_add_notifier(NC_SCENE | ND_FRAME, data->scene); report_job_duration(data); } diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h index 097740db87a..714fb3069a5 100644 --- a/source/blender/io/usd/usd.h +++ b/source/blender/io/usd/usd.h @@ -167,7 +167,7 @@ struct USDImportParams { bool import_blendshapes; bool import_volumes; bool import_skeletons; - char prim_path_mask[1024]; + char *prim_path_mask; bool import_subdiv; bool import_instance_proxies; bool create_collection; ___ 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
[Bf-blender-cvs] [27eea5e69ec] universal-scene-description: Merge branch 'master' into universal-scene-description
Commit: 27eea5e69ecabfeec912e30923f26835de0f420c Author: Michael Kowalski Date: Tue Dec 13 18:40:08 2022 -0500 Branches: universal-scene-description https://developer.blender.org/rB27eea5e69ecabfeec912e30923f26835de0f420c Merge branch 'master' into universal-scene-description === === diff --cc source/blender/io/usd/CMakeLists.txt index 455bda271e7,ebd292782c0..ece12f5fe7e --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@@ -156,7 -123,7 +156,8 @@@ set(LI list(APPEND LIB ${BOOST_LIBRARIES} + ${PYTHON_LINKFLAGS} + ${BOOST_PYTHON_LIBRARIES} ${PYTHON_LIBRARIES} ) @@@ -179,10 -146,10 +180,11 @@@ if(WIN32 set_property(TARGET bf_usd APPEND_STRING PROPERTY INTERFACE_LINK_OPTIONS "$<$:/WHOLEARCHIVE:${USD_RELEASE_LIB}>") endif() - # Source: https://github.com/PixarAnimationStudios/USD/blob/master/BUILDING.md#linking-whole-archives + # Source: + # https://github.com/PixarAnimationStudios/USD/blob/master/BUILDING.md#linking-whole-archives if(WIN32) target_link_libraries(bf_usd INTERFACE ${USD_LIBRARIES}) + target_compile_options(bf_usd PRIVATE /w34101) elseif(APPLE) target_link_libraries(bf_usd INTERFACE -Wl,-force_load ${USD_LIBRARIES}) elseif(UNIX) diff --cc source/blender/io/usd/intern/usd_capi_export.cc index 85335172533,28da9e388c5..8c724e6c0be --- a/source/blender/io/usd/intern/usd_capi_export.cc +++ b/source/blender/io/usd/intern/usd_capi_export.cc @@@ -60,15 -40,8 +60,13 @@@ struct ExportJobData wmWindowManager *wm; char filepath[FILE_MAX]; + char usdz_filepath[FILE_MAX]; + bool is_usdz_export; USDExportParams params; - short *stop; - short *do_update; + float *progress; + + bool was_canceled; bool export_ok; timeit::TimePoint start_time; }; @@@ -241,119 -54,6 +239,119 @@@ static void report_job_duration(const E std::cout << '\n'; } +static void process_usdz_textures(const ExportJobData *data, const char *path) { + const eUSDZTextureDownscaleSize enum_value = data->params.usdz_downscale_size; + if (enum_value == USD_TEXTURE_SIZE_KEEP) { +return; + } + + int image_size = ( + (enum_value == USD_TEXTURE_SIZE_CUSTOM ? data->params.usdz_downscale_custom_size : enum_value) + ); + + image_size = image_size < 128 ? 128 : image_size; + + char texture_path[4096]; + BLI_strcpy_rlen(texture_path, path); + BLI_path_append(texture_path, 4096, "textures"); - BLI_path_slash_ensure(texture_path); ++ BLI_path_slash_ensure(texture_path, sizeof(texture_path)); + + struct direntry *entries; + unsigned int num_files = BLI_filelist_dir_contents(texture_path, ); + + for (int index = 0; index < num_files; index++) { +/* We can skip checking extensions as this folder is only created + * when we're doing a USDZ export. */ +if (!BLI_is_dir(entries[index].path)) { + Image *im = BKE_image_load_ex(data->bmain, entries[index].path, LIB_ID_CREATE_NO_MAIN); + if (!im) { +std::cerr << "-- Unable to open file for downscaling: " << entries[index].path << std::endl; +continue; + } + + int width, height; + BKE_image_get_size(im, NULL, , ); + const int longest = width >= height ? width : height; + const float scale = 1.0 / ((float)longest / (float)image_size); + + if (longest > image_size) { +const int width_adjusted = (float)width * scale; +const int height_adjusted = (float)height * scale; +BKE_image_scale(im, width_adjusted, height_adjusted); + +ImageSaveOptions opts; + +if (BKE_image_save_options_init(, data->bmain, data->scene, im, NULL, false, false)) { + bool result = BKE_image_save(NULL, data->bmain, im, NULL, ); + if (!result) { +std::cerr << "-- Unable to resave " << data->filepath << " (new size: " + << width_adjusted << "x" << height_adjusted << ")" << std::endl; + } + else { +std::cout << "Downscaled " << entries[index].path << " to " + << width_adjusted << "x" << height_adjusted << std::endl; + } +} + +BKE_image_save_options_free(); + } + + /* Make sure to free the image so it doesn't stick + * around in the library of the open file. */ + BKE_id_free(data->bmain, (void*)im); +} + } + + BLI_filelist_free(entries, num_files); +} + +static bool perform_usdz_conversion(const ExportJobData *data) +{ + char usdc_temp_dir[FILE_MAX], usdc_file[FILE_MAX];
[Bf-blender-cvs] [6a478622151] universal-scene-description: USD: Path Mask import option improvements.
Commit: 6a478622151cce676f28e2c02b35b5e2c8200c24 Author: Michael Kowalski Date: Mon Dec 12 12:26:29 2022 -0500 Branches: universal-scene-description https://developer.blender.org/rB6a478622151cce676f28e2c02b35b5e2c8200c24 USD: Path Mask import option improvements. The prim_path_mask USD import option string property length is now unlimited. Updated the Path Mask option tooltip. === M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 05dc0cbf986..0e26d6e8820 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -1374,9 +1374,10 @@ void WM_OT_usd_import(struct wmOperatorType *ot) RNA_def_string(ot->srna, "prim_path_mask", NULL, - 1024, + 0, "Path Mask", - "Import only the subset of the USD scene rooted at the given primitive"); + "Import only the primitive at the given path and its descendents. " + "Multiple paths may be specified in a list delimited by spaces, commas or somicolons"); RNA_def_boolean(ot->srna, "import_guide", false, "Guide", "Import guide geometry"); ___ 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
[Bf-blender-cvs] [6ce3e0495ae] universal-scene-description: USD export: support authoring Kind
Commit: 6ce3e0495ae11efc91a4bc759609a0317d5baeda Author: Michael Kowalski Date: Fri Dec 9 18:37:54 2022 -0500 Branches: universal-scene-description https://developer.blender.org/rB6ce3e0495ae11efc91a4bc759609a0317d5baeda USD export: support authoring Kind Added a switch to the exporter to write USD Kind. Added options to add USD Kind to the Default Prim. Added a special case for the IDProperty "usdkind", which is now written as the Kind through the UsdModelAPI. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_capi_export.cc M source/blender/io/usd/intern/usd_writer_abstract.cc M source/blender/io/usd/intern/usd_writer_abstract.h M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index e82aefc4383..05dc0cbf986 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -164,6 +164,16 @@ const EnumPropertyItem prop_usdz_downscale_size[] = { {0, NULL, 0, NULL, NULL}, }; +const EnumPropertyItem prop_default_prim_kind_items[] = { +{ USD_KIND_NONE, "NONE", 0, "None", "No kind is exported for default prim" }, +{ USD_KIND_COMPONENT, "COMPONENT", 0, "Component", "Set Default Prim Kind to Component" }, +{ USD_KIND_GROUP, "GROUP", 0, "Group", "Set Default Prim Kind to Group" }, +{ USD_KIND_ASSEMBLY, "ASSEMBLY", 0, "Assembly", "Set Default Prim Kind to Assembly" }, +{ USD_KIND_CUSTOM,"CUSTOM", 0, "Custom", "Specify a custom Kind for the Default Prim" }, +{0, NULL, 0, NULL, NULL}, +}; + + /* Stored in the wmOperator's customdata field to indicate it should run as a background job. * This is set when the operator is invoked, and not set when it is only executed. */ enum { AS_BACKGROUND_JOB = 1 }; @@ -314,6 +324,11 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op) const bool export_blender_metadata = RNA_boolean_get(op->ptr, "export_blender_metadata"); + /* USDKind support. */ + const bool export_usd_kind = RNA_boolean_get(op->ptr, "export_usd_kind"); + const int default_prim_kind = RNA_enum_get(op->ptr, "default_prim_kind"); + char *default_prim_custom_kind = RNA_string_get_alloc(op->ptr, "default_prim_custom_kind", NULL, 0, NULL); + struct USDExportParams params = {RNA_int_get(op->ptr, "start"), RNA_int_get(op->ptr, "end"), export_animation, @@ -377,7 +392,11 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op) export_blender_metadata, triangulate_meshes, quad_method, - ngon_method}; + ngon_method, + .export_usd_kind = export_usd_kind, + .default_prim_kind = default_prim_kind, + .default_prim_custom_kind = default_prim_custom_kind + }; /* Take some defaults from the scene, if not specified explicitly. */ Scene *scene = CTX_data_scene(C); @@ -427,6 +446,7 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op) uiItemR(box, ptr, "end", 0, NULL, ICON_NONE); uiItemR(box, ptr, "frame_step", 0, NULL, ICON_NONE); } + uiItemR(box, ptr, "export_usd_kind", 0, NULL, ICON_NONE); uiItemR(box, ptr, "export_as_overs", 0, NULL, ICON_NONE); uiItemR(box, ptr, "merge_transform_and_shape", 0, NULL, ICON_NONE); uiItemR(box, ptr, "export_identity_transforms", 0, NULL, ICON_NONE); @@ -493,6 +513,12 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op) uiItemR(box, ptr, "default_prim_path", 0, NULL, ICON_NONE); uiItemR(box, ptr, "root_prim_path", 0, NULL, ICON_NONE); uiItemR(box, ptr, "material_prim_path", 0, NULL, ICON_NONE); + if (RNA_boolean_get(ptr, "export_usd_kind")) { +uiItemR(box, ptr, "default_prim_kind", 0, NULL, ICON_NONE); +if (RNA_enum_get(ptr, "default_prim_kind") == USD_KIND_CUSTOM) { +uiItemR(box, ptr, "default_prim_custom_kind", 0, NULL, ICON_NONE); + } + } box = uiLayoutBox(layout); uiItemL(box, IFACE_("Conversion:"), ICON_ORIENTATION_GLOBAL); @@ -1010,6 +1036,26 @@ void WM_OT_usd_export(struct wmOperatorType *ot) MOD_TRIANGULATE_NGON_BEAUTY,
[Bf-blender-cvs] [362d5b42c8a] tmp-dynamic-usd: USD: error importing texture from empty path.
Commit: 362d5b42c8a1df15eea59a4414de477680f9f5da Author: Michael Kowalski Date: Wed Dec 7 19:59:52 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rB362d5b42c8a1df15eea59a4414de477680f9f5da USD: error importing texture from empty path. Added check for empty path before attempting to import textures. === M source/blender/io/usd/intern/usd_umm.cc === diff --git a/source/blender/io/usd/intern/usd_umm.cc b/source/blender/io/usd/intern/usd_umm.cc index 1fc0f146ab2..678a98dc341 100644 --- a/source/blender/io/usd/intern/usd_umm.cc +++ b/source/blender/io/usd/intern/usd_umm.cc @@ -465,7 +465,7 @@ static PyObject *get_shader_source_data(const USDImportParams , asset_path.GetAssetPath()); } - if (params.import_textures) { + if (params.import_textures && !resolved_path.empty()) { resolved_path = usd_import_texture( resolved_path.c_str(), params.import_textures_dir, params.overwrite_textures); } ___ 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
[Bf-blender-cvs] [48eef11eb09] tmp-dynamic-usd: Merge branch 'universal-scene-description' into tmp-dynamic-usd
Commit: 48eef11eb09d355bd8064a4875a93264848a43fd Author: Michael Kowalski Date: Wed Dec 7 14:36:08 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rB48eef11eb09d355bd8064a4875a93264848a43fd Merge branch 'universal-scene-description' into tmp-dynamic-usd === === diff --cc source/blender/editors/io/io_usd.c index 7c873463790,e82aefc4383..3f9390813f9 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@@ -1170,11 -1150,9 +1172,12 @@@ static int wm_usd_import_exec(bContext .mtl_name_collision_mode = mtl_name_collision_mode, .attr_import_mode = attr_import_mode, .import_shapes = import_shapes, + .import_textures = import_textures, -.overwrite_textures = overwrite_textures}; ++ .overwrite_textures = overwrite_textures, +.import_defined_only = import_defined_only}; STRNCPY(params.prim_path_mask, prim_path_mask); + STRNCPY(params.import_textures_dir, import_textures_dir); const bool ok = USD_import(C, filename, , as_background_job); diff --cc source/blender/io/usd/usd.h index 6b729d5dfb5,e62cf965424..e3f9dbf6bbe --- a/source/blender/io/usd/usd.h +++ b/source/blender/io/usd/usd.h @@@ -176,9 -176,7 +176,10 @@@ struct USDImportParams eUSDAttrImportMode attr_import_mode; bool triangulate_meshes; bool import_shapes; + bool import_textures; + char import_textures_dir[1024]; + bool overwrite_textures; + bool import_defined_only; }; /* The USD_export takes a as_background_job parameter, and returns a boolean. ___ 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
[Bf-blender-cvs] [f6bc13b21ba] tmp-dynamic-usd: Merge branch 'tmp-vfx-platform-2023' of git.blender.org:blender into tmp-dynamic-usd
Commit: f6bc13b21bae213ce71fa88d21b19055a9bd0b83 Author: Michael Kowalski Date: Wed Dec 7 12:48:26 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rBf6bc13b21bae213ce71fa88d21b19055a9bd0b83 Merge branch 'tmp-vfx-platform-2023' of git.blender.org:blender into tmp-dynamic-usd === === diff --cc source/blender/io/usd/intern/usd_writer_material.cc index 2677b72fa5d,98cd4036fd0..1f798ab39ba --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@@ -16,7 -9,7 +16,8 @@@ #include "BKE_image_format.h" #include "BKE_main.h" #include "BKE_node.h" + #include "BKE_node_runtime.hh" +#include "BKE_node_tree_update.h" #include "IMB_colormanagement.h" ___ 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
[Bf-blender-cvs] [32b8a598dc2] tmp-dynamic-usd: USD: new URI import/export options.
Commit: 32b8a598dc2a6f1f5b705770efa32ef91f166dcf Author: Michael Kowalski Date: Tue Dec 6 22:34:52 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rB32b8a598dc2a6f1f5b705770efa32ef91f166dcf USD: new URI import/export options. Added USD URI string IO options, to allow specifying the filepath as a URI. === M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 131e86af1df..7c873463790 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -206,8 +206,13 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } + /* If the file URI is not empty, use it for the file path. */ char filename[FILE_MAX]; - RNA_string_get(op->ptr, "filepath", filename); + RNA_string_get(op->ptr, "fileuri", filename); + + if (strlen(filename) == 0) { +RNA_string_get(op->ptr, "filepath", filename); + } eUSDOperatorOptions *options = (eUSDOperatorOptions *)op->customdata; const bool as_background_job = (options != NULL && options->as_background_job); @@ -414,6 +419,9 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op) uiLayoutSetPropSep(layout, true); + box = uiLayoutBox(layout); + uiItemR(box, ptr, "fileuri", 0, NULL, ICON_NONE); + box = uiLayoutBox(layout); uiItemL(box, IFACE_("USD Export"), ICON_NONE); uiItemR(box, ptr, "evaluation_mode", 0, NULL, ICON_NONE); @@ -1010,6 +1018,8 @@ void WM_OT_usd_export(struct wmOperatorType *ot) MOD_TRIANGULATE_NGON_BEAUTY, "N-gon Method", "Method for splitting the n-gons into triangles"); + + RNA_def_string(ot->srna, "fileuri", NULL, FILE_MAX, "USD URI", "URI the USD file to import"); } /* == USD Import == */ @@ -1030,8 +1040,13 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } + /* If the file URI is not empty, use it for the file path. */ char filename[FILE_MAX]; - RNA_string_get(op->ptr, "filepath", filename); + RNA_string_get(op->ptr, "fileuri", filename); + + if (strlen(filename) == 0) { +RNA_string_get(op->ptr, "filepath", filename); + } eUSDOperatorOptions *options = (eUSDOperatorOptions *)op->customdata; const bool as_background_job = (options != NULL && options->as_background_job); @@ -1180,6 +1195,9 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) uiLayoutSetPropDecorate(layout, false); uiLayout *box = uiLayoutBox(layout); + uiItemR(box, ptr, "fileuri", 0, NULL, ICON_NONE); + + box = uiLayoutBox(layout); uiLayout *col = uiLayoutColumnWithHeading(box, true, IFACE_("Data Types")); uiItemR(col, ptr, "import_cameras", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_curves", 0, NULL, ICON_NONE); @@ -1448,6 +1466,13 @@ void WM_OT_usd_import(struct wmOperatorType *ot) false, "Overwrite Textures", "Allow overwriting existing files when copying imported textures"); + + RNA_def_string(ot->srna, + "fileuri", + NULL, + FILE_MAX, + "USD URI", + "URI the USD file to import"); } #endif /* WITH_USD */ ___ 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
[Bf-blender-cvs] [98670cfe824] universal-scene-description: USD import: Defined Primitives Only option.
Commit: 98670cfe8242c4f69dcfbd4cc99dcbfac83fa4b1 Author: Michael Kowalski Date: Tue Nov 29 14:18:06 2022 -0500 Branches: universal-scene-description https://developer.blender.org/rB98670cfe8242c4f69dcfbd4cc99dcbfac83fa4b1 USD import: Defined Primitives Only option. New option to load defined primitives only. This may be turned off to allow loading overrides with the Path Mask. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_reader_stage.cc M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 313e2488ace..e82aefc4383 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -1069,6 +1069,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const bool import_visible_only = RNA_boolean_get(op->ptr, "import_visible_only"); + const bool import_defined_only = RNA_boolean_get(op->ptr, "import_defined_only"); + const bool create_collection = RNA_boolean_get(op->ptr, "create_collection"); char prim_path_mask[1024]; @@ -1147,7 +1149,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .create_background_shader = create_background_shader, .mtl_name_collision_mode = mtl_name_collision_mode, .attr_import_mode = attr_import_mode, - .import_shapes = import_shapes}; + .import_shapes = import_shapes, + .import_defined_only = import_defined_only}; STRNCPY(params.prim_path_mask, prim_path_mask); @@ -1193,6 +1196,7 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) uiItemR(col, ptr, "import_subdiv", 0, IFACE_("Subdivision"), ICON_NONE); uiItemR(col, ptr, "import_instance_proxies", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_visible_only", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "import_defined_only", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_guide", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_proxy", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_render", 0, NULL, ICON_NONE); @@ -1303,6 +1307,13 @@ void WM_OT_usd_import(struct wmOperatorType *ot) "Only applies to primitives with a non-animated visibility attribute. " "Primitives with animated visibility will always be imported"); + RNA_def_boolean(ot->srna, + "import_defined_only", + true, + "Defined Primitives Only", + "Turn this off to allow importing USD primitives which are not defined, " + "for example, to load overrides with the Path Mask"); + RNA_def_boolean(ot->srna, "create_collection", false, diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc index 052b71bfcc5..70ddcb3faa6 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.cc +++ b/source/blender/io/usd/intern/usd_reader_stage.cc @@ -287,10 +287,14 @@ USDPrimReader *USDStageReader::collect_readers(Main *bmain, dome_lights_.push_back(pxr::UsdLuxDomeLight(prim)); } - pxr::Usd_PrimFlagsPredicate filter_predicate = pxr::UsdPrimDefaultPredicate; + pxr::Usd_PrimFlagsConjunction filter_predicate = pxr::UsdPrimIsActive && pxr::UsdPrimIsLoaded && + !pxr::UsdPrimIsAbstract; + if (params_.import_defined_only) { +filter_predicate &= pxr::UsdPrimIsDefined; + } if (!params_.use_instancing && params_.import_instance_proxies) { -filter_predicate = pxr::UsdTraverseInstanceProxies(filter_predicate); +filter_predicate.TraverseInstanceProxies(true); } pxr::UsdPrimSiblingRange children = prim.GetFilteredChildren(filter_predicate); diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h index 88f65c7dfca..e62cf965424 100644 --- a/source/blender/io/usd/usd.h +++ b/source/blender/io/usd/usd.h @@ -176,6 +176,7 @@ struct USDImportParams { eUSDAttrImportMode attr_import_mode; bool triangulate_meshes; bool import_shapes; + bool import_defined_only; }; /* The USD_export takes a as_background_job parameter, and returns a boolean. ___ 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
[Bf-blender-cvs] [91ba17da8b2] tmp-dynamic-usd: USD import textures option.
Commit: 91ba17da8b26cd7e9eb9ed77ea27a7327f7c4e96 Author: Michael Kowalski Date: Mon Nov 28 09:56:15 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rB91ba17da8b26cd7e9eb9ed77ea27a7327f7c4e96 USD import textures option. Added USD import option to copy textures which are not on the local file system (e.g., textures in USDZ archives or those specified by custom URIs) to a designated directory using the USD ArResolver. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_asset_utils.cc 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/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 313e2488ace..131e86af1df 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -1103,6 +1103,13 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const bool validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes"); + const bool import_textures = RNA_boolean_get(op->ptr, "import_textures"); + + char import_textures_dir[FILE_MAX]; + RNA_string_get(op->ptr, "import_textures_dir", import_textures_dir); + + const bool overwrite_textures = RNA_boolean_get(op->ptr, "overwrite_textures"); + /* TODO(makowalski): Add support for sequences. */ const bool is_sequence = false; int offset = 0; @@ -1147,9 +1154,12 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .create_background_shader = create_background_shader, .mtl_name_collision_mode = mtl_name_collision_mode, .attr_import_mode = attr_import_mode, - .import_shapes = import_shapes}; + .import_shapes = import_shapes, + .import_textures = import_textures, + .overwrite_textures = overwrite_textures}; STRNCPY(params.prim_path_mask, prim_path_mask); + STRNCPY(params.import_textures_dir, import_textures_dir); const bool ok = USD_import(C, filename, , as_background_job); @@ -1221,6 +1231,16 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) row = uiLayoutRow(col, true); uiItemR(row, ptr, "set_material_blend", 0, NULL, ICON_NONE); uiLayoutSetEnabled(row, import_mtls); + col = uiLayoutColumn(box, true); + uiItemR(col, ptr, "import_textures", 0, NULL, ICON_NONE); + bool import_textures = RNA_boolean_get(ptr, "import_textures"); + row = uiLayoutRow(col, true); + uiItemR(row, ptr, "import_textures_dir", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, import_textures); + row = uiLayoutRow(col, true); + uiItemR(row, ptr, "overwrite_textures", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(row, import_textures); + uiLayoutSetEnabled(col, import_mtls); } void WM_OT_usd_import(struct wmOperatorType *ot) @@ -1407,6 +1427,27 @@ void WM_OT_usd_import(struct wmOperatorType *ot) false, "Validate Meshes", "Validate meshes for degenerate geometry on import"); + + RNA_def_boolean(ot->srna, + "import_textures", + false, + "Import Textures", + "Copy textures which not on the local file system " + "(e.g., textures in USDZ archives or referenced by custom URIs) " + "to the directory given by the Import Textures Directory option"); + + RNA_def_string(ot->srna, + "import_textures_dir", + "//textures/", + FILE_MAX, + "Textures Directory", + "Path to the directory where imported textures will be copied"); + + RNA_def_boolean(ot->srna, + "overwrite_textures", + false, + "Overwrite Textures", + "Allow overwriting existing files when copying imported textures"); } #endif /* WITH_USD */ diff --git a/source/blender/io/usd/intern/usd_asset_utils.cc b/source/blender/io/usd/intern/usd_asset_utils.cc index c2aa0d142ab..ec97d0d2b2d 100644 --- a/source/blender/io/usd/intern/usd_asset_utils.cc +++ b/source/blender/io/usd/intern/usd_asset_utils.cc @@ -4,9 +4,13 @@ #include "usd_asset_utils.h" #include +#include #include #include +#include "BKE_main.h" + +#include "BLI_fileops.h" #include "BLI_path_util.h&quo
[Bf-blender-cvs] [396a8b8ad81] tmp-dynamic-usd: USD import: import textures for UMM.
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 _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 */, _mdl); +bool mdl_imported = umm_import_mdl_material(params_, mtl, usd_material, true /* Verbose */, _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 _shader) +static PyObject *get_shader_source_data(const USDImportParams , +const pxr::UsdShadeShader _shader) { if (!usd_shader) { return nullptr; @@ -463,6 +465,11 @@ static PyObject *get_shader_source_data(const pxr::UsdShadeShader _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 _shader) return ret; } -static bool import_material(Material *mtl, +static bool import_material(const USDImportParams , +Material *mtl, const pxr::UsdShadeShader _shader, const std::string _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 , + Material *mtl, const pxr::UsdShadeMaterial _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.
[Bf-blender-cvs] [e176dba6de0] tmp-dynamic-usd: USD: export in-memory textures through resolver.
Commit: e176dba6de0579c161c251ce1fd5fee98516a5d2 Author: Michael Kowalski Date: Fri Nov 25 16:03:07 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rBe176dba6de0579c161c251ce1fd5fee98516a5d2 USD: export in-memory textures through resolver. Also, added allow_overwrite paramter to export_textures(). === M source/blender/io/usd/intern/usd_writer_abstract.cc M source/blender/io/usd/intern/usd_writer_material.cc M source/blender/io/usd/intern/usd_writer_material.h === diff --git a/source/blender/io/usd/intern/usd_writer_abstract.cc b/source/blender/io/usd/intern/usd_writer_abstract.cc index 70c3268d01d..57f8474f543 100644 --- a/source/blender/io/usd/intern/usd_writer_abstract.cc +++ b/source/blender/io/usd/intern/usd_writer_abstract.cc @@ -233,13 +233,13 @@ pxr::UsdShadeMaterial USDAbstractWriter::ensure_usd_material(const HierarchyCont usd_material, this->usd_export_context_.export_params); if (this->usd_export_context_.export_params.export_textures) { - export_textures(material, this->usd_export_context_.stage); + export_textures(material, this->usd_export_context_.stage, this->usd_export_context_.export_params.overwrite_textures); } } if (material->use_nodes && this->usd_export_context_.export_params.generate_mdl) { create_mdl_material(this->usd_export_context_, material, usd_material); if (this->usd_export_context_.export_params.export_textures) { - export_textures(material, this->usd_export_context_.stage); + export_textures(material, this->usd_export_context_.stage, this->usd_export_context_.export_params.overwrite_textures); } } if (material->use_nodes && this->usd_export_context_.export_params.generate_preview_surface) { diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index f9520151355..2677b72fa5d 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -7,6 +7,7 @@ #include "usd_exporter_context.h" #include "usd_umm.h" +#include "BKE_appdir.h" #include "BKE_colorband.h" #include "BKE_colortools.h" #include "BKE_curve.h" @@ -394,6 +395,7 @@ static void export_in_memory_texture(Image *ima, const std::string _dir, const bool allow_overwrite) { + printf("allow_overwrite %d\n", allow_overwrite); char image_abs_path[FILE_MAX]; char file_name[FILE_MAX]; @@ -422,21 +424,39 @@ static void export_in_memory_texture(Image *ima, char export_path[FILE_MAX]; BLI_path_join(export_path, FILE_MAX, export_dir.c_str(), file_name); + BLI_str_replace_char(export_path, '\\', '/'); - if (!allow_overwrite && BLI_exists(export_path)) { + if (!allow_overwrite && usd_path_exists(export_path)) { return; } - if ((BLI_path_cmp_normalized(export_path, image_abs_path) == 0) && BLI_exists(image_abs_path)) { + if (usd_paths_equal(export_path, image_abs_path) && usd_path_exists(image_abs_path)) { /* As a precaution, don't overwrite the original path. */ return; } std::cout << "Exporting in-memory texture to " << export_path << std::endl; - if (BKE_imbuf_write_as(imbuf, export_path, , true) == 0) { -WM_reportf(RPT_WARNING, "USD export: couldn't export in-memory texture to %s", export_path); + /* We save the image to a temporary location on disk before copying + * it to its final destination. */ + char temp_filepath[FILE_MAX]; + BLI_path_join(temp_filepath, FILE_MAX, BKE_tempdir_session(), file_name); + BLI_str_replace_char(export_path, '\\', '/'); + + std::cout << "Saving in-memory texture to temporary location " << temp_filepath << std::endl; + + if (BKE_imbuf_write_as(imbuf, temp_filepath, , true) == 0) { +WM_reportf(RPT_WARNING, "USD export: couldn't save in-memory texture to temporary location %s", temp_filepath); } + + /* Copy to destination. */ + if (!copy_usd_asset(temp_filepath, export_path, allow_overwrite)) { +WM_reportf(RPT_WARNING, + "USD export: couldn't export in-memory texture to %s", + temp_filepath); + } + + BLI_delete(temp_filepath, false, false); } /* Get the absolute filepath of the given image. Assumes @@ -2404,7 +2424,7 @@ void export_texture(bNode *node, /* Export the texture of every texture image node in the given material's node tree. */ -void export_textures(const Material *material, const pxr::UsdStageRefPtr stage) +voi
[Bf-blender-cvs] [35c7e74af9e] tmp-dynamic-usd: Merge branch 'tmp-vfx-platform-2023' into tmp-dynamic-usd
Commit: 35c7e74af9e794e95a10085b0dac6e4052f6ddcd Author: Michael Kowalski Date: Mon Nov 28 18:32:32 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rB35c7e74af9e794e95a10085b0dac6e4052f6ddcd Merge branch 'tmp-vfx-platform-2023' into tmp-dynamic-usd === === ___ 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
[Bf-blender-cvs] [bb8433f76aa] tmp-dynamic-usd: USD export: copy UDIM textures with resolver.
Commit: bb8433f76aa7f7abcdfc98645d03a28532a820f3 Author: Michael Kowalski Date: Tue Nov 15 19:42:08 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rBbb8433f76aa7f7abcdfc98645d03a28532a820f3 USD export: copy UDIM textures with resolver. === M source/blender/io/usd/intern/usd_writer_material.cc === diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index a471a9bad57..f9520151355 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -2322,21 +2322,19 @@ static void copy_tiled_textures(Image *ima, char dest_tile_path[FILE_MAX]; BLI_path_join(dest_tile_path, FILE_MAX, dest_dir.c_str(), dest_filename); +BLI_str_replace_char(dest_tile_path, SEP, ALTSEP); -if (!allow_overwrite && BLI_exists(dest_tile_path)) { +if (!allow_overwrite && usd_path_exists(dest_tile_path)) { continue; } -if (BLI_path_cmp_normalized(src_tile_path, dest_tile_path) == 0) { +if (usd_paths_equal(src_tile_path, dest_tile_path)) { /* Source and destination paths are the same, don't copy. */ continue; } -std::cout << "Copying texture tile from " << src_tile_path << " to " << dest_tile_path - << std::endl; - /* Copy the file. */ -if (BLI_copy(src_tile_path, dest_tile_path) != 0) { +if (!copy_usd_asset(src_tile_path, dest_tile_path, allow_overwrite)) { WM_reportf(RPT_WARNING, "USD export: couldn't copy texture tile from %s to %s", src_tile_path, ___ 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
[Bf-blender-cvs] [19a7c7f4e17] tmp-dynamic-usd: USD export: added get_textures_dir() utility.
Commit: 19a7c7f4e17ea7deb547e8122b336a576fb276d1 Author: Michael Kowalski Date: Mon Nov 14 20:55:20 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rB19a7c7f4e17ea7deb547e8122b336a576fb276d1 USD export: added get_textures_dir() utility. === M source/blender/io/usd/intern/usd_asset_utils.cc M source/blender/io/usd/intern/usd_asset_utils.h M source/blender/io/usd/intern/usd_writer_material.cc === diff --git a/source/blender/io/usd/intern/usd_asset_utils.cc b/source/blender/io/usd/intern/usd_asset_utils.cc index a01e8ae953f..85cbd4cc85b 100644 --- a/source/blender/io/usd/intern/usd_asset_utils.cc +++ b/source/blender/io/usd/intern/usd_asset_utils.cc @@ -7,6 +7,8 @@ #include #include +#include "BLI_path_util.h" + #include "WM_api.h" #include "WM_types.h" @@ -110,5 +112,18 @@ bool copy_usd_asset(const char *src, const char *dst, bool overwrite) return bytes_written > 0; } + std::string get_textures_dir(const pxr::UsdStageRefPtr stage) +{ + pxr::SdfLayerHandle layer = stage->GetRootLayer(); + std::string stage_path = layer->GetRealPath(); + if (stage_path.empty()) { + return ""; + } + + char usd_dir_path[FILE_MAX]; + BLI_split_dir_part(stage_path.c_str(), usd_dir_path, FILE_MAX); + + return std::string(usd_dir_path) + std::string("textures/"); + } } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_asset_utils.h b/source/blender/io/usd/intern/usd_asset_utils.h index 1a4fe83c59d..aeefde3a859 100644 --- a/source/blender/io/usd/intern/usd_asset_utils.h +++ b/source/blender/io/usd/intern/usd_asset_utils.h @@ -2,9 +2,17 @@ * Copyright 2021 NVIDIA Corporation. All rights reserved. */ #pragma once +#include + +#include + namespace blender::io::usd { /* Invoke the the USD asset resolver to copy assets. */ bool copy_usd_asset(const char *src, const char *dst, bool overwrite); + /* Return the path to a 'textures' directory which is a sibling to the given + * stage's root layer path. */ + std::string get_textures_dir(const pxr::UsdStageRefPtr stage); + } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 39d56e6cb44..52035df6f3e 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -3,6 +3,7 @@ #include "usd_writer_material.h" #include "usd.h" +#include "usd_asset_utils.h" #include "usd_exporter_context.h" #include "usd_umm.h" @@ -2392,21 +2393,7 @@ void export_texture(bNode *node, return; } - pxr::SdfLayerHandle layer = stage->GetRootLayer(); - std::string stage_path = layer->GetRealPath(); - if (stage_path.empty()) { -return; - } - - char usd_dir_path[FILE_MAX]; - BLI_split_dir_part(stage_path.c_str(), usd_dir_path, FILE_MAX); - - char tex_dir_path[FILE_MAX]; - BLI_path_join(tex_dir_path, FILE_MAX, usd_dir_path, "textures", SEP_STR); - - BLI_dir_create_recursive(tex_dir_path); - - std::string dest_dir(tex_dir_path); + std::string dest_dir = get_textures_dir(stage); if (is_in_memory_texture(ima)) { export_in_memory_texture(ima, dest_dir, allow_overwrite); ___ 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
[Bf-blender-cvs] [b8e64404305] tmp-dynamic-usd: USD export: copy textures with asset resolver.
Commit: b8e6440430580ff79ff97738989ecfa59c5c013b Author: Michael Kowalski Date: Tue Nov 15 15:44:49 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rBb8e6440430580ff79ff97738989ecfa59c5c013b USD export: copy textures with asset resolver. Refactored the texture export code to copy the texture by invoking the asset resolver. === M source/blender/io/usd/intern/usd_asset_utils.cc M source/blender/io/usd/intern/usd_asset_utils.h M source/blender/io/usd/intern/usd_common.cc M source/blender/io/usd/intern/usd_writer_material.cc === diff --git a/source/blender/io/usd/intern/usd_asset_utils.cc b/source/blender/io/usd/intern/usd_asset_utils.cc index 85cbd4cc85b..c2aa0d142ab 100644 --- a/source/blender/io/usd/intern/usd_asset_utils.cc +++ b/source/blender/io/usd/intern/usd_asset_utils.cc @@ -8,6 +8,7 @@ #include #include "BLI_path_util.h" +#include "BLI_string.h" #include "WM_api.h" #include "WM_types.h" @@ -126,4 +127,22 @@ bool copy_usd_asset(const char *src, const char *dst, bool overwrite) return std::string(usd_dir_path) + std::string("textures/"); } + bool usd_path_exists(const char *src) + { + return src && !pxr::ArGetResolver().Resolve(src).IsEmpty(); + } + + bool usd_paths_equal(const char *p1, const char *p2) + { + BLI_assert_msg(!BLI_path_is_rel(p1) && !BLI_path_is_rel(p2), + "Paths arguments must be absolute"); + + pxr::ArResolver = pxr::ArGetResolver(); + + std::string resolved_p1 = ar.ResolveForNewAsset(p1).GetPathString(); + std::string resolved_p2 = ar.ResolveForNewAsset(p2).GetPathString(); + + return resolved_p1 == resolved_p2; + } + } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_asset_utils.h b/source/blender/io/usd/intern/usd_asset_utils.h index aeefde3a859..fecc1bc6572 100644 --- a/source/blender/io/usd/intern/usd_asset_utils.h +++ b/source/blender/io/usd/intern/usd_asset_utils.h @@ -15,4 +15,8 @@ namespace blender::io::usd { * stage's root layer path. */ std::string get_textures_dir(const pxr::UsdStageRefPtr stage); + bool usd_path_exists(const char *src); + + bool usd_paths_equal(const char *p1, const char *p2); + } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_common.cc b/source/blender/io/usd/intern/usd_common.cc index bdb4212ece9..4c0e7db90cb 100644 --- a/source/blender/io/usd/intern/usd_common.cc +++ b/source/blender/io/usd/intern/usd_common.cc @@ -57,6 +57,8 @@ void USD_path_abs(char *path, const char *basepath, bool for_import) if (!path_str.empty()) { if (path_str.length() < FILE_MAX) { BLI_strncpy(path, path_str.c_str(), FILE_MAX); + /* Use forward slash separators, which is standard for USD. */ + BLI_str_replace_char(path, SEP, ALTSEP); } else { WM_reportf(RPT_ERROR, diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 52035df6f3e..a471a9bad57 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -445,8 +445,7 @@ static void get_absolute_path(Image *ima, char *r_path) { /* Make absolute source path. */ BLI_strncpy(r_path, ima->filepath, FILE_MAX); - BLI_path_abs(r_path, ID_BLEND_PATH_FROM_GLOBAL(>id)); - BLI_path_normalize(nullptr, r_path); + USD_path_abs(r_path, ID_BLEND_PATH_FROM_GLOBAL(>id), false /* Not for import */); } /* = Functions copied from inacessible source file @@ -2358,20 +2357,19 @@ static void copy_single_file(Image *ima, const std::string _dir, const bool char dest_path[FILE_MAX]; BLI_path_join(dest_path, FILE_MAX, dest_dir.c_str(), file_name); + BLI_str_replace_char(dest_path, SEP, ALTSEP); - if (!allow_overwrite && BLI_exists(dest_path)) { + if (!allow_overwrite && usd_path_exists(dest_path)) { return; } - if (BLI_path_cmp_normalized(source_path, dest_path) == 0) { + if (usd_paths_equal(source_path, dest_path)) { /* Source and destination paths are the same, don't copy. */ return; } - std::cout << "Copying texture from " << source_path << " to " << dest_path << std::endl; - /* Copy the file. */ - if (BLI_copy(source_path, dest_path) != 0) { + if (!copy_usd_asset(source_path, dest_path, allow_overwrite)) { WM_reportf( RPT_WARNING, "USD export: couldn't copy texture from %s to %s", source_path, dest_path); } ___ 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
[Bf-blender-cvs] [922e3ef4c23] tmp-dynamic-usd: USD IO: USD_path_abs() logic update.
Commit: 922e3ef4c23c3776b68b928fd898755af28cb8c0 Author: Michael Kowalski Date: Mon Nov 14 12:07:10 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rB922e3ef4c23c3776b68b928fd898755af28cb8c0 USD IO: USD_path_abs() logic update. For Blender relative paths that start with "//", now also invoking the USD resolver on the absolute path resolved by Blender. === M source/blender/io/usd/intern/usd_common.cc === diff --git a/source/blender/io/usd/intern/usd_common.cc b/source/blender/io/usd/intern/usd_common.cc index f8b1fd92918..bdb4212ece9 100644 --- a/source/blender/io/usd/intern/usd_common.cc +++ b/source/blender/io/usd/intern/usd_common.cc @@ -41,22 +41,27 @@ void ensure_usd_plugin_path_registered() void USD_path_abs(char *path, const char *basepath, bool for_import) { - if (!BLI_path_is_rel(path)) { -pxr::ArResolvedPath resolved_path = for_import ? pxr::ArGetResolver().Resolve(path) : - pxr::ArGetResolver().ResolveForNewAsset(path); - -std::string path_str = resolved_path.GetPathString(); - -if (!path_str.empty()) { - if (path_str.length() < FILE_MAX) { -BLI_strncpy(path, path_str.c_str(), FILE_MAX); -return; - } - WM_reportf(RPT_ERROR, "In USD_path_abs: resolved path %s exceeds path buffer length.", path_str.c_str()); -} + if (BLI_path_is_rel(path)) { +/* The path is relative to the .blend file, so use Blender's + * standard absolute path resolution. */ +BLI_path_abs(path, basepath); +/* Use forward slash separators, which is standard for USD. */ +BLI_str_replace_char(path, SEP, ALTSEP); } - /* If we got here, the path couldn't be resolved by the ArResolver, so we - * fall back on the standard Blender absolute path resolution. */ - BLI_path_abs(path, basepath); + pxr::ArResolvedPath resolved_path = for_import ? pxr::ArGetResolver().Resolve(path) : + pxr::ArGetResolver().ResolveForNewAsset(path); + + std::string path_str = resolved_path.GetPathString(); + + if (!path_str.empty()) { +if (path_str.length() < FILE_MAX) { + BLI_strncpy(path, path_str.c_str(), FILE_MAX); +} +else { + WM_reportf(RPT_ERROR, + "USD_path_abs: resolved path %s exceeds path buffer length.", + path_str.c_str()); +} + } } ___ 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
[Bf-blender-cvs] [4d9b898e0ec] tmp-dynamic-usd: USD IO: invoke resolver to write USDZ.
Commit: 4d9b898e0ecf7303d3799a7703b203dc45bd9443 Author: Michael Kowalski Date: Fri Nov 11 14:35:03 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rB4d9b898e0ecf7303d3799a7703b203dc45bd9443 USD IO: invoke resolver to write USDZ. Added new copy_usd_asset() function to invoke the USD asset resolver to copy a file. Updated the USDZ export logic to use this function when copying the temporary USDZ file to its final destination. === M source/blender/io/usd/CMakeLists.txt A source/blender/io/usd/intern/usd_asset_utils.cc A source/blender/io/usd/intern/usd_asset_utils.h M source/blender/io/usd/intern/usd_capi_export.cc === diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt index 1cbec8c471f..7a7539089df 100644 --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@ -65,6 +65,7 @@ set(INC_SYS ) set(SRC + intern/usd_asset_utils.cc intern/usd_capi_export.cc intern/usd_capi_import.cc intern/usd_common.cc @@ -107,6 +108,7 @@ set(SRC usd.h + intern/usd_asset_utils.h intern/usd_common.h intern/usd_exporter_context.h intern/usd_hierarchy_iterator.h diff --git a/source/blender/io/usd/intern/usd_asset_utils.cc b/source/blender/io/usd/intern/usd_asset_utils.cc new file mode 100644 index 000..a01e8ae953f --- /dev/null +++ b/source/blender/io/usd/intern/usd_asset_utils.cc @@ -0,0 +1,114 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2022 NVIDIA Corportation. All rights reserved. */ + +#include "usd_asset_utils.h" + +#include +#include +#include + +#include "WM_api.h" +#include "WM_types.h" + +#include + +namespace blender::io::usd { + +bool copy_usd_asset(const char *src, const char *dst, bool overwrite) +{ + if (!(src && dst)) { +return false; + } + + pxr::ArResolver = pxr::ArGetResolver(); + + if (!overwrite) { +if (!ar.Resolve(dst).IsEmpty()) { + /* The asset exists, so this is a no-op. */ + WM_reportf(RPT_INFO, "copy_usd_asset(): Will not overwrite existing asset %s", dst); + return true; +} + } + + pxr::ArResolvedPath src_path = ar.Resolve(src); + + if (src_path.IsEmpty()) { +WM_reportf(RPT_ERROR, "copy_usd_asset(): Can't resolve path %s.", src); +return false; + } + + pxr::ArResolvedPath dst_path = ar.ResolveForNewAsset(dst); + + if (dst_path.IsEmpty()) { +WM_reportf(RPT_ERROR, "copy_usd_asset(): Can't resolve path %s for writing.", dst); +return false; + } + + std::string why_not; + if (!ar.CanWriteAssetToPath(dst_path, _not)) { +WM_reportf(RPT_ERROR, + "copy_usd_asset(): Can't write to asset %s. %s.", + dst_path.GetPathString().c_str(), + why_not.c_str()); +return false; + } + + std::shared_ptr src_asset = ar.OpenAsset(src_path); + if (!src_asset) { +WM_reportf( +RPT_ERROR, "copy_usd_asset(): Can't open source asset %s.", src_path.GetPathString().c_str()); +return false; + } + + const size_t size = src_asset->GetSize(); + + if (size == 0) { +WM_reportf(RPT_WARNING, + "copy_usd_asset(): Will not copy zero size source asset %s.", + src_path.GetPathString().c_str()); +return false; + } + + std::shared_ptr buf = src_asset->GetBuffer(); + + if (!buf) { +WM_reportf(RPT_ERROR, + "copy_usd_asset(): Null buffer for source asset %s.", + src_path.GetPathString().c_str()); +return false; + } + + std::shared_ptr dst_asset = ar.OpenAssetForWrite( + dst_path, pxr::ArResolver::WriteMode::Replace); + if (!dst_asset) { +WM_reportf(RPT_ERROR, + "copy_usd_asset(): Can't open destination asset %s for writing.", + src_path.GetPathString().c_str()); +return false; + } + + size_t bytes_written = dst_asset->Write(src_asset->GetBuffer().get(), src_asset->GetSize(), 0); + + if (bytes_written == 0) { +WM_reportf(RPT_ERROR, + "copy_usd_asset(): Error writing to destination asset %s.", + dst_path.GetPathString().c_str()); + } + else { +WM_reportf(RPT_INFO, + "copy_usd_asset(): Copied %s to %s.", + src_path.GetPathString().c_str(), dst_path.GetPathString().c_str()); + } + + if (!dst_asset->Close()) { +WM_reportf(RPT_ERROR, + "copy_usd_asset(): Couldn't close destination asset %s.", + dst_path.GetPathString().c_str()); +return false; + } + + return bytes_written > 0; +} + + +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_asset_utils.h b/source/blender/io/usd/intern/usd_asset_utils.h new
[Bf-blender-cvs] [b157d0b97e3] tmp-dynamic-usd: Merge branch 'universal-scene-description' of git.blender.org:blender into tmp-dynamic-usd
Commit: b157d0b97e3b897fbe61a598798e9b116251bc9e Author: Michael Kowalski Date: Fri Nov 11 14:37:36 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rBb157d0b97e3b897fbe61a598798e9b116251bc9e Merge branch 'universal-scene-description' of git.blender.org:blender into tmp-dynamic-usd === === ___ 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
[Bf-blender-cvs] [4ab6ee68ab0] tmp-dynamic-usd: USD IO: function to resolve USD paths.
Commit: 4ab6ee68ab09635d4065fb25f6d26c896942a35a Author: Michael Kowalski Date: Thu Nov 10 13:41:56 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rB4ab6ee68ab09635d4065fb25f6d26c896942a35a USD IO: function to resolve USD paths. Added USD_path_abs() funcion, which is similar to BLI_path_abs(), but which also invokes the USD asset resolver to determine the absolute path. This is necessary for resolving paths with URIs that BLI_path_abs() would otherwise alter when attempting to normalize the path. Now calling USD_path_abs() where needed to resolve USD paths for import. === M source/blender/blenkernel/intern/cachefile.c M source/blender/io/usd/intern/usd_capi_import.cc M source/blender/io/usd/intern/usd_common.cc M source/blender/io/usd/usd.h === diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index 5968a6b7296..b81d2c90502 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -387,7 +387,17 @@ bool BKE_cachefile_filepath_get(const Main *bmain, char r_filepath[FILE_MAX]) { BLI_strncpy(r_filepath, cache_file->filepath, FILE_MAX); + +#ifdef WITH_USD + if (BLI_path_extension_check_glob(r_filepath, "*.usd;*.usda;*.usdc;*.usdz")) { +USD_path_abs(r_filepath, ID_BLEND_PATH(bmain, _file->id), true /* for import */); + } + else { +BLI_path_abs(r_filepath, ID_BLEND_PATH(bmain, _file->id)); + } +#else BLI_path_abs(r_filepath, ID_BLEND_PATH(bmain, _file->id)); +#endif int fframe; int frame_len; diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index ca518249c91..8e597550a51 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -369,7 +369,7 @@ static void import_startjob(void *customdata, bool *stop, bool *do_update, float data->view_layer, import_collection); } - BLI_path_abs(data->filepath, BKE_main_blendfile_path_from_global()); + USD_path_abs(data->filepath, BKE_main_blendfile_path_from_global(), true); *data->do_update = true; *data->progress = 0.05f; diff --git a/source/blender/io/usd/intern/usd_common.cc b/source/blender/io/usd/intern/usd_common.cc index e5a83442140..f8b1fd92918 100644 --- a/source/blender/io/usd/intern/usd_common.cc +++ b/source/blender/io/usd/intern/usd_common.cc @@ -2,10 +2,17 @@ * Copyright 2021 Blender Foundation. All rights reserved. */ #include "usd_common.h" +#include "usd.h" +#include #include #include "BKE_appdir.h" +#include "BLI_path_util.h" +#include "BLI_string.h" + +#include "WM_api.h" +#include "WM_types.h" namespace blender::io::usd { @@ -30,3 +37,26 @@ void ensure_usd_plugin_path_registered() } } // namespace blender::io::usd + + +void USD_path_abs(char *path, const char *basepath, bool for_import) +{ + if (!BLI_path_is_rel(path)) { +pxr::ArResolvedPath resolved_path = for_import ? pxr::ArGetResolver().Resolve(path) : + pxr::ArGetResolver().ResolveForNewAsset(path); + +std::string path_str = resolved_path.GetPathString(); + +if (!path_str.empty()) { + if (path_str.length() < FILE_MAX) { +BLI_strncpy(path, path_str.c_str(), FILE_MAX); +return; + } + WM_reportf(RPT_ERROR, "In USD_path_abs: resolved path %s exceeds path buffer length.", path_str.c_str()); +} + } + + /* If we got here, the path couldn't be resolved by the ArResolver, so we + * fall back on the standard Blender absolute path resolution. */ + BLI_path_abs(path, basepath); +} diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h index 0d2077d3f13..1be7e5fb58f 100644 --- a/source/blender/io/usd/usd.h +++ b/source/blender/io/usd/usd.h @@ -203,6 +203,12 @@ bool USD_umm_module_loaded(void); /* USD Import and Mesh Cache interface. */ +/* Similar to BLI_path_abs(), but also invokes the USD asset resolver + * to determine the absolute path. This is necessary for resolving + * paths with URIs that BLI_path_abs() would otherwise alter when + * attempting to normalize the path. */ +void USD_path_abs(char *path, const char *basepath, bool for_import); + struct CacheArchiveHandle *USD_create_handle(struct Main *bmain, const char *filepath, struct ListBase *object_paths); ___ 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
[Bf-blender-cvs] [90f1d1f4b66] universal-scene-description: USD Import: Support multiple prim path masks.
Commit: 90f1d1f4b665fff57da774ced961fadd5424e0db Author: Michael Kowalski Date: Wed Nov 23 14:13:17 2022 -0500 Branches: universal-scene-description https://developer.blender.org/rB90f1d1f4b665fff57da774ced961fadd5424e0db USD Import: Support multiple prim path masks. Extended the Prim Path option to support multiple path entries, delimited by commas, spaces or semicolons. === M source/blender/io/usd/intern/usd_capi_import.cc M source/blender/io/usd/intern/usd_reader_stage.cc === diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 9ed0e4cb69f..22b9eb2186d 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -383,8 +383,21 @@ static void import_startjob(void *customdata, short *stop, short *do_update, flo *data->do_update = true; *data->progress = 0.1f; - pxr::UsdStageRefPtr stage = pxr::UsdStage::Open(data->filepath); + std::string prim_path_mask(data->params.prim_path_mask); + pxr::UsdStagePopulationMask pop_mask; + if (!prim_path_mask.empty()) { +const std::vector mask_tokens = pxr::TfStringTokenize(prim_path_mask, " ,;"); +for (const std::string : mask_tokens) { + pxr::SdfPath prim_path(tok); + if (!prim_path.IsEmpty()) { +pop_mask.Add(prim_path); + } +} + } + pxr::UsdStageRefPtr stage = pop_mask.IsEmpty() ? + pxr::UsdStage::Open(data->filepath) : + pxr::UsdStage::OpenMasked(data->filepath, pop_mask); if (!stage) { WM_reportf(RPT_ERROR, "USD Import: unable to open stage to read %s", data->filepath); data->import_ok = false; diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc index 6c29a5e01b0..052b71bfcc5 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.cc +++ b/source/blender/io/usd/intern/usd_reader_stage.cc @@ -353,19 +353,6 @@ void USDStageReader::collect_readers(Main *bmain) /* Iterate through the stage. */ pxr::UsdPrim root = stage_->GetPseudoRoot(); - std::string prim_path_mask(params_.prim_path_mask); - - if (!prim_path_mask.empty()) { -pxr::UsdPrim prim = stage_->GetPrimAtPath(pxr::SdfPath(prim_path_mask)); -if (prim.IsValid()) { - root = prim; -} -else { - std::cerr << "WARNING: Prim Path Mask " << prim_path_mask -<< " does not specify a valid prim.\n"; -} - } - stage_->SetInterpolationType(pxr::UsdInterpolationType::UsdInterpolationTypeHeld); pxr::UsdGeomXformCache xf_cache; ___ 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
[Bf-blender-cvs] [4d8c634820f] universal-scene-description: USD export: access deform verts as custom data.
Commit: 4d8c634820f54b13992831ca6cd6430f20a11095 Author: Michael Kowalski Date: Mon Nov 7 22:34:26 2022 -0500 Branches: universal-scene-description https://developer.blender.org/rB4d8c634820f54b13992831ca6cd6430f20a11095 USD export: access deform verts as custom data. Due to a recent Blender API change, MDeformVert entries must be read as custom data. === M source/blender/io/usd/intern/usd_writer_skinned_mesh.cc === diff --git a/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc b/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc index 320cd41b1ae..9f691e765d8 100644 --- a/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc @@ -194,7 +194,7 @@ void USDSkinnedMeshWriter::write_weights(const Object *ob, const pxr::UsdSkelBindingAPI _api, const std::vector _names) const { - if (!(skel_api && ob && mesh && mesh->dvert && mesh->totvert > 0)) { + if (!(skel_api && ob && mesh && mesh->totvert > 0)) { return; } @@ -223,16 +223,17 @@ void USDSkinnedMeshWriter::write_weights(const Object *ob, return; } + const Span dverts = mesh->deform_verts(); + int max_totweight = 1; - for (int i = 0; i < mesh->totvert; ++i) { -MDeformVert = mesh->dvert[i]; + for (const int i : dverts.index_range()) { +const MDeformVert = dverts[i]; if (vert.totweight > max_totweight) { max_totweight = vert.totweight; } } const int ELEM_SIZE = max_totweight; - int num_points = mesh->totvert; pxr::VtArray joint_indices(num_points * ELEM_SIZE, 0); @@ -244,9 +245,8 @@ void USDSkinnedMeshWriter::write_weights(const Object *ob, /* Record number of out of bounds vert group indices, for error reporting. */ int num_out_of_bounds = 0; - for (int i = 0; i < mesh->totvert; ++i) { - -MDeformVert = mesh->dvert[i]; + for (const int i : dverts.index_range()) { +const MDeformVert = dverts[i]; /* Sum of the weights, for normalizing. */ float sum_weights = 0.0f; ___ 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
[Bf-blender-cvs] [036e10e5462] tmp-dynamic-usd: Merge branch 'universal-scene-description' into tmp-dynamic-usd
Commit: 036e10e5462b95ec6a12e9dd4a900ba7ff05032c Author: Michael Kowalski Date: Mon Nov 7 12:31:34 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rB036e10e5462b95ec6a12e9dd4a900ba7ff05032c Merge branch 'universal-scene-description' into tmp-dynamic-usd === === ___ 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
[Bf-blender-cvs] [a400935d29f] tmp-dynamic-usd: Merge branch 'tmp-vfx-platform-2023' into tmp-dynamic-usd
Commit: a400935d29f54b9bd821d093873eb4643a279e59 Author: Michael Kowalski Date: Mon Nov 7 19:37:51 2022 -0500 Branches: tmp-dynamic-usd https://developer.blender.org/rBa400935d29f54b9bd821d093873eb4643a279e59 Merge branch 'tmp-vfx-platform-2023' into tmp-dynamic-usd === === diff --cc source/blender/io/usd/CMakeLists.txt index 6973c181981,745a1c69dce..1cbec8c471f --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@@ -178,10 -145,10 +178,11 @@@ if(WIN32 set_property(TARGET bf_usd APPEND_STRING PROPERTY INTERFACE_LINK_OPTIONS "$<$:/WHOLEARCHIVE:${USD_RELEASE_LIB}>") endif() - # Source: https://github.com/PixarAnimationStudios/USD/blob/master/BUILDING.md#linking-whole-archives + # Source: + # https://github.com/PixarAnimationStudios/USD/blob/master/BUILDING.md#linking-whole-archives if(WIN32) target_link_libraries(bf_usd INTERFACE ${USD_LIBRARIES}) + target_compile_options(bf_usd PRIVATE /w34101) elseif(APPLE) target_link_libraries(bf_usd INTERFACE -Wl,-force_load ${USD_LIBRARIES}) elseif(UNIX) diff --cc source/blender/io/usd/intern/usd_capi_export.cc index 8df13fd0dcd,28da9e388c5..72c20f28b62 --- a/source/blender/io/usd/intern/usd_capi_export.cc +++ b/source/blender/io/usd/intern/usd_capi_export.cc @@@ -58,15 -40,8 +58,15 @@@ struct ExportJobData wmWindowManager *wm; char filepath[FILE_MAX]; + char usdz_filepath[FILE_MAX]; + bool is_usdz_export; USDExportParams params; - short *stop; - short *do_update; ++ bool *stop; ++ bool *do_update; + float *progress; + + bool was_canceled; bool export_ok; timeit::TimePoint start_time; }; @@@ -208,119 -54,6 +208,119 @@@ static void report_job_duration(const E std::cout << '\n'; } +static void process_usdz_textures(const ExportJobData *data, const char *path) { + const eUSDZTextureDownscaleSize enum_value = data->params.usdz_downscale_size; + if (enum_value == USD_TEXTURE_SIZE_KEEP) { +return; + } + + int image_size = ( + (enum_value == USD_TEXTURE_SIZE_CUSTOM ? data->params.usdz_downscale_custom_size : enum_value) + ); + + image_size = image_size < 128 ? 128 : image_size; + + char texture_path[4096]; + BLI_strcpy_rlen(texture_path, path); + BLI_path_append(texture_path, 4096, "textures"); - BLI_path_slash_ensure(texture_path); ++ BLI_path_slash_ensure(texture_path, 4096); + + struct direntry *entries; + unsigned int num_files = BLI_filelist_dir_contents(texture_path, ); + + for (int index = 0; index < num_files; index++) { +/* We can skip checking extensions as this folder is only created + * when we're doing a USDZ export. */ +if (!BLI_is_dir(entries[index].path)) { + Image *im = BKE_image_load_ex(data->bmain, entries[index].path, LIB_ID_CREATE_NO_MAIN); + if (!im) { +std::cerr << "-- Unable to open file for downscaling: " << entries[index].path << std::endl; +continue; + } + + int width, height; + BKE_image_get_size(im, NULL, , ); + const int longest = width >= height ? width : height; + const float scale = 1.0 / ((float)longest / (float)image_size); + + if (longest > image_size) { +const int width_adjusted = (float)width * scale; +const int height_adjusted = (float)height * scale; +BKE_image_scale(im, width_adjusted, height_adjusted); + +ImageSaveOptions opts; + +if (BKE_image_save_options_init(, data->bmain, data->scene, im, NULL, false, false)) { + bool result = BKE_image_save(NULL, data->bmain, im, NULL, ); + if (!result) { +std::cerr << "-- Unable to resave " << data->filepath << " (new size: " + << width_adjusted << "x" << height_adjusted << ")" << std::endl; + } + else { +std::cout << "Downscaled " << entries[index].path << " to " + << width_adjusted << "x" << height_adjusted << std::endl; + } +} + +BKE_image_save_options_free(); + } + + /* Make sure to free the image so it doesn't stick + * around in the library of the open file. */ + BKE_id_free(data->bmain, (void*)im); +} + } + + BLI_filelist_free(entries, num_files); +} + +static bool perform_usdz_conversion(const ExportJobData *data) +{ + char usdc_temp_dir[FILE_MAX], usdc_file[FILE_MAX]; + BLI_split_dirfile(data->filepath, usdc_temp_dir, usdc_file, FILE_MAX, FILE_MAX); + + char usdz_file[FILE_MAX]; + BLI_split_file_par
[Bf-blender-cvs] [0f7433a4c87] universal-scene-description: USD export: fix curve widths calculation.
Commit: 0f7433a4c871b70371423ad3aca203d10fb4f179 Author: Michael Kowalski Date: Wed Nov 2 16:27:57 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB0f7433a4c871b70371423ad3aca203d10fb4f179 USD export: fix curve widths calculation. Now multiplying the curve radius values by the bevel radius when calculating curve widths. Change authored by Charles Wardlaw. === M source/blender/io/usd/intern/usd_writer_curve.cc === diff --git a/source/blender/io/usd/intern/usd_writer_curve.cc b/source/blender/io/usd/intern/usd_writer_curve.cc index f779bd7a1ba..3e27de3798a 100644 --- a/source/blender/io/usd/intern/usd_writer_curve.cc +++ b/source/blender/io/usd/intern/usd_writer_curve.cc @@ -118,7 +118,7 @@ void USDCurveWriter::do_write(HierarchyContext ) for (int i = 0; i < totpoint; i++, point++) { verts.push_back(pxr::GfVec3f(point->vec)); weights.push_back(point->vec[3]); -widths.push_back(point->radius * 2.0f); +widths.push_back(point->radius * curve->bevel_radius * 2.0f); } } else if (nurbs->bezt) { @@ -137,24 +137,24 @@ void USDCurveWriter::do_write(HierarchyContext ) if (i > 0) { verts.push_back(pxr::GfVec3f(bezier->vec[0])); - widths.push_back(bezier->radius * 2.0f); + widths.push_back(bezier->radius * curve->bevel_radius * 2.0f); } verts.push_back(pxr::GfVec3f(bezier->vec[1])); -widths.push_back(bezier->radius * 2.0f); +widths.push_back(bezier->radius * curve->bevel_radius * 2.0f); if (i < totpoint - 1 || is_cyclic) { verts.push_back(pxr::GfVec3f(bezier->vec[2])); - widths.push_back(bezier->radius * 2.0f); + widths.push_back(bezier->radius * curve->bevel_radius * 2.0f); } } if (is_cyclic) { verts.push_back(pxr::GfVec3f(nurbs->bezt->vec[0])); -widths.push_back(nurbs->bezt->radius * 2.0f); +widths.push_back(nurbs->bezt->radius * curve->bevel_radius * 2.0f); verts.push_back(pxr::GfVec3f(nurbs->bezt->vec[1])); -widths.push_back(nurbs->bezt->radius * 2.0f); +widths.push_back(nurbs->bezt->radius * curve->bevel_radius * 2.0f); } } // TODO: Implement knots ___ 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
[Bf-blender-cvs] [f428fe774bf] universal-scene-description: USD import: replace deprecated shape import code.
Commit: f428fe774bf88bdf56bc86a4df2462739fd482a6 Author: Michael Kowalski Date: Wed Nov 2 14:30:00 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBf428fe774bf88bdf56bc86a4df2462739fd482a6 USD import: replace deprecated shape import code. The static functions GetMeshPoints() and GetTopology() have been removed from the adapter classes in USD 22.11. In anticipation of this change, the code was updated to call the corresponding virtual functions instead. Change authored by Charles Wardlaw. === M source/blender/io/usd/intern/usd_reader_shape.cc === diff --git a/source/blender/io/usd/intern/usd_reader_shape.cc b/source/blender/io/usd/intern/usd_reader_shape.cc index 3e6170e51c8..7f32c12029d 100644 --- a/source/blender/io/usd/intern/usd_reader_shape.cc +++ b/source/blender/io/usd/intern/usd_reader_shape.cc @@ -65,19 +65,30 @@ void USDShapeReader::read_object_data(Main *bmain, double motionSampleTime) USDXformReader::read_object_data(bmain, motionSampleTime); } + template void USDShapeReader::read_values(const double motionSampleTime, pxr::VtVec3fArray , pxr::VtIntArray _indices, pxr::VtIntArray _counts) { - pxr::VtValue meshPoints = Adapter::GetMeshPoints(prim_, motionSampleTime); - positions = meshPoints.template Get>(); - pxr::HdMeshTopology meshTopologyValue = Adapter::GetMeshTopology().template Get(); - face_counts = meshTopologyValue.GetFaceVertexCounts(); - face_indices = meshTopologyValue.GetFaceVertexIndices(); + Adapter adapter; + pxr::VtValue points_val = adapter.GetPoints(prim_, motionSampleTime); + + if (points_val.template IsHolding()) { +positions = points_val.template Get(); + } + + pxr::VtValue topology_val = adapter.GetTopology(prim_, pxr::SdfPath(), motionSampleTime); + + if (topology_val.template IsHolding()) { +const pxr::HdMeshTopology = topology_val.template Get(); +face_counts = topology.GetFaceVertexCounts(); +face_indices = topology.GetFaceVertexIndices(); + } } + struct Mesh *USDShapeReader::read_mesh(struct Mesh *existing_mesh, double motionSampleTime, int /* read_flag */, ___ 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
[Bf-blender-cvs] [7e0fb88a68c] universal-scene-description: USD export: export textures for Cycles materials.
Commit: 7e0fb88a68c22135200ce9770c03023e050ea974 Author: Michael Kowalski Date: Thu Oct 27 15:25:47 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB7e0fb88a68c22135200ce9770c03023e050ea974 USD export: export textures for Cycles materials. === M source/blender/io/usd/intern/usd_writer_abstract.cc === diff --git a/source/blender/io/usd/intern/usd_writer_abstract.cc b/source/blender/io/usd/intern/usd_writer_abstract.cc index 65d42d6bba2..70c3268d01d 100644 --- a/source/blender/io/usd/intern/usd_writer_abstract.cc +++ b/source/blender/io/usd/intern/usd_writer_abstract.cc @@ -232,6 +232,9 @@ pxr::UsdShadeMaterial USDAbstractWriter::ensure_usd_material(const HierarchyCont material, usd_material, this->usd_export_context_.export_params); +if (this->usd_export_context_.export_params.export_textures) { + export_textures(material, this->usd_export_context_.stage); +} } if (material->use_nodes && this->usd_export_context_.export_params.generate_mdl) { create_mdl_material(this->usd_export_context_, material, usd_material); ___ 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
[Bf-blender-cvs] [bcc2656299a] master: USD IO: replace deprecated primvars API.
Commit: bcc2656299ad72b224c5f2644518759561c31045 Author: Michael Kowalski Date: Tue Nov 1 11:55:58 2022 -0400 Branches: master https://developer.blender.org/rBbcc2656299ad72b224c5f2644518759561c31045 USD IO: replace deprecated primvars API. Updated the code to use the UsdGeomPrimvarsAPI class to read and write mesh primvars instead of the now deprecated primvars accessors in UsdGeomImageable. This will be required to build with USD 22.11 in the future, where the deprecated functions have been removed. === M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/usd/intern/usd_writer_mesh.cc === diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 01db6baeb5c..8138f38fcad 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -287,11 +288,13 @@ bool USDMeshReader::topology_changed(const Mesh *existing_mesh, const double mot mesh_prim_.GetFaceVertexCountsAttr().Get(_counts_, motionSampleTime); mesh_prim_.GetPointsAttr().Get(_, motionSampleTime); + pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_); + /* TODO(makowalski): Reading normals probably doesn't belong in this function, * as this is not required to determine if the topology has changed. */ /* If 'normals' and 'primvars:normals' are both specified, the latter has precedence. */ - pxr::UsdGeomPrimvar primvar = mesh_prim_.GetPrimvar(usdtokens::normalsPrimvar); + pxr::UsdGeomPrimvar primvar = primvarsAPI.GetPrimvar(usdtokens::normalsPrimvar); if (primvar.HasValue()) { primvar.ComputeFlattened(_, motionSampleTime); normal_interpolation_ = primvar.GetInterpolation(); @@ -355,6 +358,8 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo std::vector uv_primvars(ldata->totlayer); + pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_); + if (has_uvs_) { for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) { const CustomDataLayer *layer = >layers[layer_idx]; @@ -385,11 +390,11 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo } /* Early out if mesh doesn't have primvar. */ - if (!mesh_prim_.HasPrimvar(uv_token)) { + if (!primvarsAPI.HasPrimvar(uv_token)) { continue; } - if (pxr::UsdGeomPrimvar uv_primvar = mesh_prim_.GetPrimvar(uv_token)) { + if (pxr::UsdGeomPrimvar uv_primvar = primvarsAPI.GetPrimvar(uv_token)) { uv_primvar.ComputeFlattened(_primvars[layer_idx].uvs, motionSampleTime); uv_primvars[layer_idx].interpolation = uv_primvar.GetInterpolation(); } @@ -835,12 +840,14 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, is_left_handed_ = true; } + pxr::UsdGeomPrimvarsAPI primvarsAPI(mesh_prim_); + std::vector uv_tokens; /* Currently we only handle UV primvars. */ if (read_flag & MOD_MESHSEQ_READ_UV) { -std::vector primvars = mesh_prim_.GetPrimvars(); +std::vector primvars = primvarsAPI.GetPrimvars(); for (pxr::UsdGeomPrimvar p : primvars) { diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index e949bafe517..e7d79e888e4 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -4,6 +4,7 @@ #include "usd_hierarchy_iterator.h" #include +#include #include #include @@ -107,6 +108,8 @@ void USDGenericMeshWriter::write_uv_maps(const Mesh *mesh, pxr::UsdGeomMesh usd_ { pxr::UsdTimeCode timecode = get_export_time_code(); + pxr::UsdGeomPrimvarsAPI primvarsAPI(usd_mesh.GetPrim()); + const CustomData *ldata = >ldata; for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) { const CustomDataLayer *layer = >layers[layer_idx]; @@ -119,7 +122,7 @@ void USDGenericMeshWriter::write_uv_maps(const Mesh *mesh, pxr::UsdGeomMesh usd_ * for texture coordinates by naming the UV Map as such, without having to guess which UV Map * is the "standard" one. */ pxr::TfToken primvar_name(pxr::TfMakeValidIdentifier(layer->name)); -pxr::UsdGeomPrimvar uv_coords_primvar = usd_mesh.CreatePrimvar( +pxr::UsdGeomPrimvar uv_coords_primvar = primvarsAPI.CreatePrimvar( primvar_name, pxr::SdfValueTypeNames->TexCoord2fArray, pxr::UsdGeomTokens->faceVarying); MLoopUV *mloopuv = static_cast(layer->data); ___ 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
[Bf-blender-cvs] [e6823f32e9a] master: USD tests: replace deprecated imaging code.
Commit: e6823f32e9a7372ca06a5989d56d855df31afea8 Author: Michael Kowalski Date: Tue Nov 1 10:32:36 2022 -0400 Branches: master https://developer.blender.org/rBe6823f32e9a7372ca06a5989d56d855df31afea8 USD tests: replace deprecated imaging code. UsdImagingCapsuleAdapter static functions GetMeshPoints() and GetTopology() have been removed in USD 22.11. In anticipation of this upcoming change, I've updated the test code to call the corresponding virtual functions instead. === M source/blender/io/usd/tests/usd_imaging_test.cc === diff --git a/source/blender/io/usd/tests/usd_imaging_test.cc b/source/blender/io/usd/tests/usd_imaging_test.cc index 5cd3c042e59..80c232ad099 100644 --- a/source/blender/io/usd/tests/usd_imaging_test.cc +++ b/source/blender/io/usd/tests/usd_imaging_test.cc @@ -42,8 +42,8 @@ TEST_F(USDImagingTest, CapsuleAdapterTest) } pxr::UsdImagingCapsuleAdapter capsule_adapter; - pxr::VtValue points_value = pxr::UsdImagingCapsuleAdapter::GetMeshPoints( - capsule.GetPrim(), pxr::UsdTimeCode::Default()); + pxr::VtValue points_value = capsule_adapter.GetPoints(capsule.GetPrim(), + pxr::UsdTimeCode::Default()); if (!points_value.IsHolding>()) { FAIL() << "Mesh points value holding unexpected type."; return; @@ -52,7 +52,8 @@ TEST_F(USDImagingTest, CapsuleAdapterTest) pxr::VtArray points = points_value.Get>(); EXPECT_FALSE(points.empty()); - pxr::VtValue topology_value = pxr::UsdImagingCapsuleAdapter::GetMeshTopology(); + pxr::VtValue topology_value = capsule_adapter.GetTopology( + capsule.GetPrim(), pxr::SdfPath(), pxr::UsdTimeCode::Default()); if (!topology_value.IsHolding()) { FAIL() << "Mesh topology value holding unexpected type."; ___ 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
[Bf-blender-cvs] [4fa478c7249] universal-scene-description: USD Export: handle meshes in edit mode.
Commit: 4fa478c724903ee3d4a4cb6aaf05775a7c46ad01 Author: Michael Kowalski Date: Wed Oct 26 19:58:28 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB4fa478c724903ee3d4a4cb6aaf05775a7c46ad01 USD Export: handle meshes in edit mode. Small change to ensure Edit mode meshes are committed during the export process. Without this change, meshes may be empty in the USD. This update was authored by Charles Wardlaw. === M source/blender/io/usd/intern/usd_writer_mesh.cc === diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index fca7ab08e30..3d2aacb2d42 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -19,6 +19,7 @@ #include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_mesh_runtime.h" +#include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_object.h" @@ -26,7 +27,6 @@ #include "bmesh_tools.h" #include "DEG_depsgraph.h" - #include "DNA_layer_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" @@ -504,6 +504,8 @@ void USDGenericMeshWriter::write_mesh(HierarchyContext , Mesh *mesh) write_visibility(context, timecode, usd_mesh); USDMeshData usd_mesh_data; + /* ensure data exists if currently in edit mode */ + BKE_mesh_wrapper_ensure_mdata(mesh); get_geometry_data(mesh, usd_mesh_data); if (usd_export_context_.export_params.export_vertices) { ___ 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
[Bf-blender-cvs] [a0a3e271a53] tmp-dynamic-usd: Merge branch 'tmp-vfx-platform-2023' into tmp-dynamic-usd
Commit: a0a3e271a532a9c8f25c0c905076987a68faee2f Author: Michael Kowalski Date: Tue Oct 25 14:54:58 2022 -0400 Branches: tmp-dynamic-usd https://developer.blender.org/rBa0a3e271a532a9c8f25c0c905076987a68faee2f Merge branch 'tmp-vfx-platform-2023' into tmp-dynamic-usd === === ___ 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
[Bf-blender-cvs] [784ea87375c] universal-scene-description: Merge branch 'master' into universal-scene-description
Commit: 784ea87375cebd7c12faada555f65c741895bca0 Author: Michael Kowalski Date: Mon Oct 24 15:28:20 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB784ea87375cebd7c12faada555f65c741895bca0 Merge branch 'master' into universal-scene-description === === diff --cc source/blender/io/usd/intern/usd_reader_mesh.cc index 7a12258df0a,01db6baeb5c..9c0c76a50c1 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@@ -861,11 -804,10 +861,11 @@@ void USDMeshReader::readFaceSetsSample( std::map mat_map; bke::MutableAttributeAccessor attributes = mesh->attributes_for_write(); - bke::SpanAttributeWriter material_indices = - attributes.lookup_or_add_for_write_only_span("material_index", ATTR_DOMAIN_FACE); + bke::SpanAttributeWriter material_indices = attributes.lookup_or_add_for_write_span( + "material_index", ATTR_DOMAIN_FACE); this->assign_facesets_to_material_indices(motionSampleTime, material_indices.span, _map); material_indices.finish(); + /* Build material name map if it's not built yet. */ if (this->settings_->mat_name_to_mat.empty()) { utils::build_mat_map(bmain, >settings_->mat_name_to_mat); ___ 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
[Bf-blender-cvs] [75064c7024b] universal-scene-description: USD import: crash reading shapes.
Commit: 75064c7024b12b845fc36d4fa3079f005651f7c7 Author: Michael Kowalski Date: Mon Oct 24 11:17:57 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB75064c7024b12b845fc36d4fa3079f005651f7c7 USD import: crash reading shapes. Updated the mesh reading code when reading shapes, to fix a crash due to the updated mesh API introduced in the last merge from master. === M source/blender/io/usd/intern/usd_reader_shape.cc === diff --git a/source/blender/io/usd/intern/usd_reader_shape.cc b/source/blender/io/usd/intern/usd_reader_shape.cc index 80478b9c9cc..3e6170e51c8 100644 --- a/source/blender/io/usd/intern/usd_reader_shape.cc +++ b/source/blender/io/usd/intern/usd_reader_shape.cc @@ -132,15 +132,17 @@ struct Mesh *USDShapeReader::read_mesh(struct Mesh *existing_mesh, existing_mesh, positions.size(), 0, 0, face_indices.size(), face_counts.size()); } + MutableSpan verts = active_mesh->verts_for_write(); + for (int i = 0; i < positions.size(); i++) { -MVert = active_mesh->mvert[i]; +MVert = verts[i]; mvert.co[0] = positions[i][0]; mvert.co[1] = positions[i][1]; mvert.co[2] = positions[i][2]; } - MPoly *mpolys = active_mesh->mpoly; - MLoop *mloops = active_mesh->mloop; + MutableSpan polys = active_mesh->polys_for_write(); + MutableSpan loops = active_mesh->loops_for_write(); int loop_index = 0; @@ -148,7 +150,7 @@ struct Mesh *USDShapeReader::read_mesh(struct Mesh *existing_mesh, for (int i = 0; i < face_counts.size(); i++) { const int face_size = face_counts[i]; - MPoly = mpolys[i]; + MPoly = polys[i]; poly.loopstart = loop_index; poly.totloop = face_size; @@ -156,7 +158,7 @@ struct Mesh *USDShapeReader::read_mesh(struct Mesh *existing_mesh, poly.flag |= is_cube ? 0 : ME_SMOOTH; for (int f = 0; f < face_size; ++f, ++loop_index) { -mloops[loop_index].v = face_indices[loop_index]; +loops[loop_index].v = face_indices[loop_index]; } } } ___ 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
[Bf-blender-cvs] [471636ffcd4] universal-scene-description: USD Import: fix error messages loading instances.
Commit: 471636ffcd49d5d339f80edce58d812cbe9aa12d Author: Michael Kowalski Date: Wed Oct 19 15:15:47 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB471636ffcd49d5d339f80edce58d812cbe9aa12d USD Import: fix error messages loading instances. Added logic to avoid attempting to bind the pxr::UsdSkelBindingAPI to instance proxies and prototypes, as this was generating errors. === M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/usd/intern/usd_skel_convert.cc === diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index d4acba8059b..7a12258df0a 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -1093,20 +1093,22 @@ bool USDMeshReader::get_local_usd_xform(pxr::GfMatrix4d *r_xform, return USDXformReader::get_local_usd_xform(r_xform, r_is_constant, time); } - if (pxr::UsdSkelBindingAPI skel_api = pxr::UsdSkelBindingAPI::Apply(prim_)) { -if (skel_api.GetGeomBindTransformAttr().HasAuthoredValue()) { - pxr::GfMatrix4d bind_xf; - if (skel_api.GetGeomBindTransformAttr().Get(_xf)) { -/* Assume that if a bind transform is defined, then the - * transform is constant. */ -if (r_is_constant) { - *r_is_constant = true; + if (!(prim_.IsInstanceProxy() || prim_.IsInPrototype())) { +if (pxr::UsdSkelBindingAPI skel_api = pxr::UsdSkelBindingAPI::Apply(prim_)) { + if (skel_api.GetGeomBindTransformAttr().HasAuthoredValue()) { +pxr::GfMatrix4d bind_xf; +if (skel_api.GetGeomBindTransformAttr().Get(_xf)) { + /* Assume that if a bind transform is defined, then the + * transform is constant. */ + if (r_is_constant) { +*r_is_constant = true; + } + return get_geom_bind_xform_correction(bind_xf, r_xform, time); +} +else { + std::cout << "WARNING: couldn't compute geom bind transform for " << prim_.GetPath() +<< std::endl; } -return get_geom_bind_xform_correction(bind_xf, r_xform, time); - } - else { -std::cout << "WARNING: couldn't compute geom bind transform for " << prim_.GetPath() - << std::endl; } } } diff --git a/source/blender/io/usd/intern/usd_skel_convert.cc b/source/blender/io/usd/intern/usd_skel_convert.cc index f05c0ffc2dc..69ab05c234e 100644 --- a/source/blender/io/usd/intern/usd_skel_convert.cc +++ b/source/blender/io/usd/intern/usd_skel_convert.cc @@ -586,6 +586,12 @@ void import_skel_bindings(Main *bmain, Object *mesh_obj, pxr::UsdPrim prim) return; } + if (prim.IsInstanceProxy() || prim.IsInPrototype()) { +/* Attempting to create a UsdSkelBindingAPI for + * instance proxies and prototypes generates USD errors. */ +return; + } + if (mesh_obj->type != OB_MESH) { return; } ___ 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
[Bf-blender-cvs] [ae342e00ca0] universal-scene-description: USD Import: hide instance prototype collections.
Commit: ae342e00ca08eca8b98e37b7ce29017320db609a Author: Michael Kowalski Date: Thu Oct 20 16:37:11 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBae342e00ca08eca8b98e37b7ce29017320db609a USD Import: hide instance prototype collections. Now hiding the instance prototype parent collection in both the viewport and render. This change was also necessary because the previous code for hiding prototype layer collections stopped working with the latest merge from master. === M source/blender/io/usd/intern/usd_capi_import.cc === diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 5ec0d73e0f9..9ed0e4cb69f 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -166,6 +166,11 @@ static void create_proto_collections(Main *bmain, { Collection *all_protos_collection = create_collection(bmain, parent_collection, "prototypes"); + if (all_protos_collection) { +all_protos_collection->flag |= COLLECTION_HIDE_VIEWPORT; +all_protos_collection->flag |= COLLECTION_HIDE_RENDER; + } + std::map proto_collection_map; for (const auto : proto_readers) { @@ -179,12 +184,6 @@ static void create_proto_collections(Main *bmain, Collection *proto_collection = create_collection( bmain, all_protos_collection, proto_collection_name.c_str()); -LayerCollection *proto_lc = BKE_layer_collection_first_from_scene_collection(view_layer, - proto_collection); -if (proto_lc) { - proto_lc->flag |= LAYER_COLLECTION_HIDE; -} - proto_collection_map.insert(std::make_pair(pair.first, proto_collection)); } ___ 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
[Bf-blender-cvs] [cf8cf884d14] universal-scene-description: Merge branch 'master' into universal-scene-description
Commit: cf8cf884d147cdd6d1786d3a1a341bbeec2b871d Author: Michael Kowalski Date: Tue Oct 18 14:16:53 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBcf8cf884d147cdd6d1786d3a1a341bbeec2b871d Merge branch 'master' into universal-scene-description === === diff --cc source/blender/editors/io/io_usd.c index 0998fc77b01,c776fbf0dd7..313e2488ace --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@@ -178,43 -85,16 +179,29 @@@ static int wm_usd_export_invoke(bContex options->as_background_job = true; op->customdata = options; + RNA_boolean_set(op->ptr, "init_scene_frame_range", true); + - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { - Main *bmain = CTX_data_main(C); - char filepath[FILE_MAX]; - const char *main_blendfile_path = BKE_main_blendfile_path(bmain); - - if (main_blendfile_path[0] == '\0') { - BLI_strncpy(filepath, "untitled", sizeof(filepath)); - } - else { - BLI_strncpy(filepath, main_blendfile_path, sizeof(filepath)); - } - - BLI_path_extension_replace(filepath, sizeof(filepath), ".usd"); - RNA_string_set(op->ptr, "filepath", filepath); - } + ED_fileselect_ensure_default_filepath(C, op, ".usdc"); WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL; } +static char *usd_ensure_prim_path(char *primpath) +{ + if (primpath != NULL && primpath[0] != '/' && primpath[0] != '\0') { +char *legal_path = BLI_strdupcat("/", primpath); +MEM_freeN(primpath); +primpath = legal_path; +return legal_path; + } + return primpath; +} + static int wm_usd_export_exec(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; } @@@ -559,11 -187,23 +546,24 @@@ static void wm_usd_export_draw(bContex uiItemR(col, ptr, "relative_paths", 0, NULL, ICON_NONE); box = uiLayoutBox(layout); - uiItemL(box, IFACE_("Experimental"), ICON_NONE); + uiItemL(box, IFACE_("Experimental:"), ICON_NONE); uiItemR(box, ptr, "use_instancing", 0, NULL, ICON_NONE); + uiItemR(box, ptr, "fix_skel_root", 0, NULL, ICON_NONE); } + static void free_operator_customdata(wmOperator *op) + { + if (op->customdata) { + MEM_freeN(op->customdata); + op->customdata = NULL; + } + } + + static void wm_usd_export_cancel(bContext *UNUSED(C), wmOperator *op) + { + free_operator_customdata(op); + } + static bool wm_usd_export_check(bContext *UNUSED(C), wmOperator *op) { char filepath[FILE_MAX]; @@@ -1137,17 -424,13 +1138,19 @@@ static int wm_usd_import_exec(bContext .import_render = import_render, .import_visible_only = import_visible_only, .use_instancing = use_instancing, - .import_usd_preview = import_usd_preview, + .import_shaders_mode = import_shaders_mode, .set_material_blend = set_material_blend, .light_intensity_scale = light_intensity_scale, - .mtl_name_collision_mode = mtl_name_collision_mode}; + .apply_unit_conversion_scale = apply_unit_conversion_scale, + .convert_light_from_nits = convert_light_from_nits, + .scale_light_radius = scale_light_radius, + .create_background_shader = create_background_shader, + .mtl_name_collision_mode = mtl_name_collision_mode, + .attr_import_mode = attr_import_mode, + .import_shapes = import_shapes}; + STRNCPY(params.prim_path_mask, prim_path_mask); + const bool ok = USD_import(C, filename, , as_background_job); return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; diff --cc source/blender/editors/space_file/filelist.cc index 000,b6f6ab39438..783e471e630 mode 00,100644..100644 --- a/source/blender/editors/space_file/filelist.cc +++ b/source/blender/editors/space_file/filelist.cc @@@ -1,0 -1,3960 +1,3960 @@@ + /* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2007 Blender Foundation. All rights reserved. */ + + /** \file + * \ingroup spfile + */ + + /* global
[Bf-blender-cvs] [f8e871168a8] universal-scene-description: Fix linux/mac build warnings and errors.
Commit: f8e871168a8ddf374ff578ce8ef817041de62e4e Author: Michael Kowalski Date: Mon Oct 17 16:33:09 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBf8e871168a8ddf374ff578ce8ef817041de62e4e Fix linux/mac build warnings and errors. === M source/blender/io/usd/intern/usd_reader_shape.cc M source/blender/io/usd/intern/usd_reader_shape.h === diff --git a/source/blender/io/usd/intern/usd_reader_shape.cc b/source/blender/io/usd/intern/usd_reader_shape.cc index 92597c290ee..9038238b387 100644 --- a/source/blender/io/usd/intern/usd_reader_shape.cc +++ b/source/blender/io/usd/intern/usd_reader_shape.cc @@ -37,7 +37,7 @@ USDShapeReader::USDShapeReader(const pxr::UsdPrim , { } -void USDShapeReader::create_object(Main *bmain, double motionSampleTime) +void USDShapeReader::create_object(Main *bmain, double /* motionSampleTime */) { Mesh *mesh = BKE_mesh_add(bmain, name_.c_str()); object_ = BKE_object_add_only_object(bmain, OB_MESH, name_.c_str()); @@ -72,16 +72,16 @@ void USDShapeReader::read_values(const double motionSampleTime, pxr::VtIntArray _counts) { pxr::VtValue meshPoints = Adapter::GetMeshPoints(prim_, motionSampleTime); - positions = meshPoints.Get>(); - pxr::HdMeshTopology meshTopologyValue = Adapter::GetMeshTopology().Get(); + positions = meshPoints.template Get>(); + pxr::HdMeshTopology meshTopologyValue = Adapter::GetMeshTopology().template Get(); face_counts = meshTopologyValue.GetFaceVertexCounts(); face_indices = meshTopologyValue.GetFaceVertexIndices(); } struct Mesh *USDShapeReader::read_mesh(struct Mesh *existing_mesh, double motionSampleTime, - int read_flag, - const char **err_str) + int /* read_flag */, + const char ** /* err_str */) { if (!prim_) { return existing_mesh; diff --git a/source/blender/io/usd/intern/usd_reader_shape.h b/source/blender/io/usd/intern/usd_reader_shape.h index 25f08aba207..7e91be1d4f4 100644 --- a/source/blender/io/usd/intern/usd_reader_shape.h +++ b/source/blender/io/usd/intern/usd_reader_shape.h @@ -32,7 +32,7 @@ class USDShapeReader : public USDGeomReader { const char **err_str) override; bool is_time_varying(); - virtual bool topology_changed(const Mesh * /* existing_mesh */, double /* motionSampleTime */) + virtual bool topology_changed(const Mesh * /* existing_mesh */, double /* motionSampleTime */) override { return false; }; ___ 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
[Bf-blender-cvs] [50a30043283] universal-scene-description: USD Import: support reading USD shapes.
Commit: 50a300432838d8f731bf567d6914fff5fc140080 Author: Michael Kowalski Date: Mon Oct 17 15:11:42 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB50a300432838d8f731bf567d6914fff5fc140080 USD Import: support reading USD shapes. Added readers for importing USD shapes (capsule, cylinder, cone, cube and sphere) as meshes. Implemented by Charles Wardlaw. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/CMakeLists.txt M source/blender/io/usd/intern/usd_capi_import.cc A source/blender/io/usd/intern/usd_reader_shape.cc A source/blender/io/usd/intern/usd_reader_shape.h M source/blender/io/usd/intern/usd_reader_stage.cc M source/blender/io/usd/intern/usd_reader_stage.h M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index ca0df20a45e..0998fc77b01 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -1060,6 +1060,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const bool import_blendshapes = RNA_boolean_get(op->ptr, "import_blendshapes"); const bool import_volumes = RNA_boolean_get(op->ptr, "import_volumes"); const bool import_skeletons = RNA_boolean_get(op->ptr, "import_skeletons"); + const bool import_shapes = RNA_boolean_get(op->ptr, "import_shapes"); const bool import_subdiv = RNA_boolean_get(op->ptr, "import_subdiv"); @@ -1144,7 +1145,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .scale_light_radius = scale_light_radius, .create_background_shader = create_background_shader, .mtl_name_collision_mode = mtl_name_collision_mode, - .attr_import_mode = attr_import_mode}; + .attr_import_mode = attr_import_mode, + .import_shapes = import_shapes}; const bool ok = USD_import(C, filename, , as_background_job); @@ -1169,6 +1171,7 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) uiItemR(col, ptr, "import_blendshapes", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_volumes", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_skeletons", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "import_shapes", 0, NULL, ICON_NONE); uiItemR(box, ptr, "prim_path_mask", 0, NULL, ICON_NONE); uiItemR(box, ptr, "scale", 0, NULL, ICON_NONE); uiItemR(box, ptr, "apply_unit_conversion_scale", 0, NULL, ICON_NONE); @@ -1267,6 +1270,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "import_blendshapes", true, "Blend Shapes", ""); RNA_def_boolean(ot->srna, "import_volumes", true, "Volumes", ""); RNA_def_boolean(ot->srna, "import_skeletons", true, "Skeletons", ""); + RNA_def_boolean(ot->srna, "import_shapes", true, "USD Shapes", ""); RNA_def_boolean(ot->srna, "import_subdiv", diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt index 4a77bb32544..28cbf158a01 100644 --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@ -74,6 +74,7 @@ set(SRC intern/usd_reader_camera.cc intern/usd_reader_curve.cc intern/usd_reader_geom.cc + intern/usd_reader_shape.cc intern/usd_reader_instance.cc intern/usd_reader_light.cc intern/usd_reader_material.cc @@ -114,6 +115,7 @@ set(SRC intern/usd_reader_camera.h intern/usd_reader_curve.h intern/usd_reader_geom.h + intern/usd_reader_shape.h intern/usd_reader_instance.h intern/usd_reader_light.h intern/usd_reader_material.h @@ -179,6 +181,7 @@ endif() # Source: https://github.com/PixarAnimationStudios/USD/blob/master/BUILDING.md#linking-whole-archives if(WIN32) target_link_libraries(bf_usd INTERFACE ${USD_LIBRARIES}) + target_compile_options(bf_usd PRIVATE /w34101) elseif(APPLE) target_link_libraries(bf_usd INTERFACE -Wl,-force_load ${USD_LIBRARIES}) elseif(UNIX) diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 1d005f92116..791ddc351e8 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -339,6 +339,7 @@ static void report_job_duration(const ImportJobData *data) std::cout << '\n'; } + static void import_startjob(void *customdata, short *stop, short *do_update,
[Bf-blender-cvs] [a067e590046] universal-scene-description: USD Import: validate meshes option.
Commit: a067e590046f649b078f770275a3b22be5581431 Author: Michael Kowalski Date: Mon Oct 10 12:48:43 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBa067e590046f649b078f770275a3b22be5581431 USD Import: validate meshes option. Added feature flag "Validate Meshes" to strip invalid geometry from meshes on import. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_reader_mesh.cc === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index abc94836d9c..ca0df20a45e 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -1099,6 +1099,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const eUSDAttrImportMode attr_import_mode = RNA_enum_get(op->ptr, "attr_import_mode"); + const bool validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes"); + /* TODO(makowalski): Add support for sequences. */ const bool is_sequence = false; int offset = 0; @@ -1110,8 +1112,6 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) ED_object_mode_set(C, OB_MODE_EDIT); } - const bool validate_meshes = false; - struct USDImportParams params = {.scale = scale, .is_sequence = is_sequence, .set_frame_range = set_frame_range, @@ -1177,6 +1177,7 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) col = uiLayoutColumnWithHeading(box, true, IFACE_("Mesh Data")); uiItemR(col, ptr, "read_mesh_uvs", 0, NULL, ICON_NONE); uiItemR(col, ptr, "read_mesh_colors", 0, NULL, ICON_NONE); + uiItemR(box, ptr, "validate_meshes", 0, NULL, ICON_NONE); col = uiLayoutColumnWithHeading(box, true, IFACE_("Include")); uiItemR(col, ptr, "import_subdiv", 0, IFACE_("Subdivision"), ICON_NONE); uiItemR(col, ptr, "import_instance_proxies", 0, NULL, ICON_NONE); @@ -1386,6 +1387,12 @@ void WM_OT_usd_import(struct wmOperatorType *ot) USD_ATTR_IMPORT_NONE, "Import Attributes", "Behavior when importing USD attributes as Blender custom properties"); + + RNA_def_boolean(ot->srna, + "validate_meshes", + false, + "Validate Meshes", + "Validate meshes for degenerate geometry on import"); } #endif /* WITH_USD */ diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 15a5707baa1..7c1b3f0fd71 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -14,10 +14,8 @@ #include "BKE_object.h" #include "BLI_math.h" -#include "BLI_math_geom.h" #include "BLI_math_vec_types.hh" #include "BLI_span.hh" -#include "BLI_string.h" #include "DNA_customdata_types.h" #include "DNA_material_types.h" @@ -299,6 +297,7 @@ bool USDMeshReader::topology_changed(const Mesh *existing_mesh, const double mot mesh_prim_.GetFaceVertexCountsAttr().Get(_counts_, motionSampleTime); mesh_prim_.GetPointsAttr().Get(_, motionSampleTime); + /* TODO(makowalski): Reading normals probably doesn't belong in this function, * as this is not required to determine if the topology has changed. */ @@ -325,9 +324,25 @@ void USDMeshReader::read_mpolys(Mesh *mesh) int loop_index = 0; + std::vector degenerate_faces; + for (int i = 0; i < face_counts_.size(); i++) { const int face_size = face_counts_[i]; +/* Check for faces with the same vertex specified twice in a row. */ +if (face_indices_[loop_index] == face_indices_[loop_index+face_size-1]) { + /* Loop below does not test first to last. */ + degenerate_faces.push_back(i); +} +else { + for (int j = loop_index+1; j < loop_index + face_size; j++) { +if (face_indices_[j] == face_indices_[j-1]) { + degenerate_faces.push_back(i); + break; +} + } +} + MPoly = mpolys[i]; poly.loopstart = loop_index; poly.totloop = face_size; @@ -351,6 +366,10 @@ void USDMeshReader::read_mpolys(Mesh *mesh) } BKE_mesh_calc_edges(mesh, false, false); + + if (!degenerate_faces.empty() && !import_params_.validate_meshes) { +WM_reportf(RPT_WARNING, "Prim %s has degenerate faces-- please consider importing with Validate Meshes enabled.", prim_.GetName().GetText()); + } } void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bool load_uvs) @@ -931,7 +950,10 @@ Mesh *USDMeshReader::read_mes
[Bf-blender-cvs] [8703e17ace0] tmp_usd_import_unbound_mtls: USD import: fixed compiler warnings.
Commit: 8703e17ace01fe2fdac1d8fc8fe3f607a589c0ca Author: Michael Kowalski Date: Thu Oct 6 10:33:43 2022 -0400 Branches: tmp_usd_import_unbound_mtls https://developer.blender.org/rB8703e17ace01fe2fdac1d8fc8fe3f607a589c0ca USD import: fixed compiler warnings. Removed unused function and assignment in a conditional expression. === M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/usd/intern/usd_reader_stage.cc === diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 3dbdd5d486b..3f7d51e3e76 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -48,20 +48,6 @@ static const pxr::TfToken normalsPrimvar("normals", pxr::TfToken::Immortal); } // namespace usdtokens namespace utils { -/* Very similar to #blender::io::alembic::utils. */ -static void build_mat_map(const Main *bmain, std::map *r_mat_map) -{ - if (r_mat_map == nullptr) { -return; - } - - Material *material = static_cast(bmain->materials.first); - - for (; material; material = static_cast(material->id.next)) { -/* We have to do this because the stored material name is coming directly from USD. */ -(*r_mat_map)[pxr::TfMakeValidIdentifier(material->id.name + 2)] = material; - } -} static pxr::UsdShadeMaterial compute_bound_material(const pxr::UsdPrim ) { diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc index 0533cbbffee..aaa14dad51b 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.cc +++ b/source/blender/io/usd/intern/usd_reader_stage.cc @@ -332,8 +332,8 @@ void USDStageReader::import_all_materials(Main *bmain) } /* Add the material now. */ - if (blend_mtl = mtl_reader.add_material(usd_mtl)) { - + blend_mtl = mtl_reader.add_material(usd_mtl); + if (blend_mtl) { if (params_.mtl_name_collision_mode == USD_MTL_NAME_COLLISION_MAKE_UNIQUE) { /* Record the name of the Blender material we created for the USD material * with the given path, so we don't import the material again if the ___ 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
[Bf-blender-cvs] [05e8eeda3c9] tmp_usd_import_unbound_mtls: USD import unbound materials.
Commit: 05e8eeda3c95c960b2481b85cd836194d78c95ad Author: Michael Kowalski Date: Wed Oct 5 23:06:21 2022 -0400 Branches: tmp_usd_import_unbound_mtls https://developer.blender.org/rB05e8eeda3c95c960b2481b85cd836194d78c95ad USD import unbound materials. This addresses issue T97195. Added a new Unbound Materials USD import option, to import materials not assigned to any geometry. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_capi_import.cc M source/blender/io/usd/intern/usd_reader_material.cc M source/blender/io/usd/intern/usd_reader_material.h M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/usd/intern/usd_reader_stage.cc M source/blender/io/usd/intern/usd_reader_stage.h M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index eb80cabcd7f..5fe8ff7a16c 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -381,6 +381,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const bool import_proxy = RNA_boolean_get(op->ptr, "import_proxy"); const bool import_render = RNA_boolean_get(op->ptr, "import_render"); + const bool import_unbound_materials = RNA_boolean_get(op->ptr, "import_unbound_materials"); + const bool import_usd_preview = RNA_boolean_get(op->ptr, "import_usd_preview"); const bool set_material_blend = RNA_boolean_get(op->ptr, "set_material_blend"); @@ -427,7 +429,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .import_usd_preview = import_usd_preview, .set_material_blend = set_material_blend, .light_intensity_scale = light_intensity_scale, - .mtl_name_collision_mode = mtl_name_collision_mode}; + .mtl_name_collision_mode = mtl_name_collision_mode, + .import_unbound_materials = import_unbound_materials}; STRNCPY(params.prim_path_mask, prim_path_mask); @@ -471,6 +474,7 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) uiItemR(col, ptr, "import_guide", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_proxy", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_render", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "import_unbound_materials", 0, NULL, ICON_NONE); col = uiLayoutColumnWithHeading(box, true, IFACE_("Options")); uiItemR(col, ptr, "set_frame_range", 0, NULL, ICON_NONE); @@ -579,6 +583,9 @@ void WM_OT_usd_import(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "import_render", true, "Render", "Import final render geometry"); + RNA_def_boolean(ot->srna, "import_unbound_materials", false, +"Unbound Materials", "Include materials not bound to any geometry"); + RNA_def_boolean(ot->srna, "import_usd_preview", false, diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 5808c6bc77a..29f3792792b 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -225,8 +225,16 @@ static void import_startjob(void *customdata, short *stop, short *do_update, flo data->archive = archive; + if (data->params.import_unbound_materials) { +archive->import_all_materials(data->bmain); + } + archive->collect_readers(data->bmain); + if (data->params.import_unbound_materials) { +archive->fake_users_for_unbound_materials(); + } + *data->do_update = true; *data->progress = 0.2f; diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index d1af4553083..6416f6861d4 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -757,4 +757,52 @@ void USDMaterialReader::convert_usd_primvar_reader_float2( link_nodes(ntree, uv_map, "UV", dest_node, dest_socket_name); } + +void build_material_map(const Main *bmain, std::map *r_mat_map) +{ + if (r_mat_map == nullptr) { +return; + } + + Material *material = static_cast(bmain->materials.first); + + for (; material; material = static_cast(material->id.next)) { +(*r_mat_map)[pxr::TfMakeValidIdentifier(material->id.name + 2)] = material; + } +} + +Material *find_existing_material( +const pxr::SdfPath _mat_path, +const USDImportParams , +cons
[Bf-blender-cvs] [689e6a1be75] tmp_usd_import_unbound_mtls: USD import: fix fake users for unbound materials.
Commit: 689e6a1be750b5904fa97ed4208bc0a942827712 Author: Michael Kowalski Date: Wed Oct 5 23:40:59 2022 -0400 Branches: tmp_usd_import_unbound_mtls https://developer.blender.org/rB689e6a1be750b5904fa97ed4208bc0a942827712 USD import: fix fake users for unbound materials. Now adding fake users in the import end job function, to ensure use counts are valid. === M source/blender/io/usd/intern/usd_capi_import.cc === diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 29f3792792b..52f1fcf4e8f 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -231,10 +231,6 @@ static void import_startjob(void *customdata, short *stop, short *do_update, flo archive->collect_readers(data->bmain); - if (data->params.import_unbound_materials) { -archive->fake_users_for_unbound_materials(); - } - *data->do_update = true; *data->progress = 0.2f; @@ -363,6 +359,10 @@ static void import_endjob(void *customdata) DEG_id_tag_update(>scene->id, ID_RECALC_BASE_FLAGS); DEG_relations_tag_update(data->bmain); + +if (data->params.import_unbound_materials) { + data->archive->fake_users_for_unbound_materials(); +} } WM_set_locked_interface(data->wm, false); ___ 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
[Bf-blender-cvs] [092fe1ef293] tmp_usd_import_unbound_mtls: USD IO format fixes.
Commit: 092fe1ef293280cbf0ff2f8b892f5c455aea3c38 Author: Michael Kowalski Date: Wed Oct 5 23:11:43 2022 -0400 Branches: tmp_usd_import_unbound_mtls https://developer.blender.org/rB092fe1ef293280cbf0ff2f8b892f5c455aea3c38 USD IO format fixes. === 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_reader_material.h M source/blender/io/usd/intern/usd_reader_stage.cc === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 5fe8ff7a16c..9bcd16a04df 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -583,8 +583,11 @@ void WM_OT_usd_import(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "import_render", true, "Render", "Import final render geometry"); - RNA_def_boolean(ot->srna, "import_unbound_materials", false, -"Unbound Materials", "Include materials not bound to any geometry"); + RNA_def_boolean(ot->srna, + "import_unbound_materials", + false, + "Unbound Materials", + "Include materials not bound to any geometry"); RNA_def_boolean(ot->srna, "import_usd_preview", diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index 6416f6861d4..bf4ee0ad208 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -757,7 +757,6 @@ void USDMaterialReader::convert_usd_primvar_reader_float2( link_nodes(ntree, uv_map, "UV", dest_node, dest_socket_name); } - void build_material_map(const Main *bmain, std::map *r_mat_map) { if (r_mat_map == nullptr) { @@ -771,11 +770,10 @@ void build_material_map(const Main *bmain, std::map *r_ } } -Material *find_existing_material( -const pxr::SdfPath _mat_path, -const USDImportParams , -const std::map _map, -const std::map _path_to_mat_name) +Material *find_existing_material(const pxr::SdfPath _mat_path, + const USDImportParams , + const std::map _map, + const std::map _path_to_mat_name) { if (params.mtl_name_collision_mode == USD_MTL_NAME_COLLISION_MAKE_UNIQUE) { /* Check if we've already created the Blender material with a modified name. */ diff --git a/source/blender/io/usd/intern/usd_reader_material.h b/source/blender/io/usd/intern/usd_reader_material.h index abd810b9936..871954f3a99 100644 --- a/source/blender/io/usd/intern/usd_reader_material.h +++ b/source/blender/io/usd/intern/usd_reader_material.h @@ -71,7 +71,6 @@ class USDMaterialReader { Main *bmain_; public: - USDMaterialReader(const USDImportParams , Main *bmain); Material *add_material(const pxr::UsdShadeMaterial _material) const; diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc index 89dd7098f6c..0533cbbffee 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.cc +++ b/source/blender/io/usd/intern/usd_reader_stage.cc @@ -353,7 +353,8 @@ void USDStageReader::import_all_materials(Main *bmain) * materials. */ void USDStageReader::fake_users_for_unbound_materials() { - std::map::const_iterator mat_name_it = settings_.usd_path_to_mat_name.begin(); + std::map::const_iterator mat_name_it = + settings_.usd_path_to_mat_name.begin(); for (; mat_name_it != settings_.usd_path_to_mat_name.end(); ++mat_name_it) { std::map::iterator mat_it = settings_.mat_name_to_mat.find( mat_name_it->second); ___ 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
[Bf-blender-cvs] [61a9ee88a34] universal-scene-description: USD import: handle context-dependent UDIM paths.
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..png') were not getting resolved by the call to SdfLayerComputeAbsolutePath(). 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 _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..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
[Bf-blender-cvs] [69251411bc7] universal-scene-description: USD Export: Added triangulate options
Commit: 69251411bc7e897e571a944d6ed016f3b7d76081 Author: Michael Kowalski Date: Wed Sep 28 14:36:41 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB69251411bc7e897e571a944d6ed016f3b7d76081 USD Export: Added triangulate options === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_writer_mesh.cc M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 044d5dfad44..abc94836d9c 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -320,6 +320,11 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op) const bool usdz_is_arkit = RNA_boolean_get(op->ptr, "usdz_is_arkit"); + const bool triangulate_meshes = RNA_boolean_get(op->ptr, "triangulate_meshes"); + + const int quad_method = RNA_enum_get(op->ptr, "quad_method"); + const int ngon_method = RNA_enum_get(op->ptr, "ngon_method"); + const bool export_blender_metadata = RNA_boolean_get(op->ptr, "export_blender_metadata"); struct USDExportParams params = {RNA_int_get(op->ptr, "start"), @@ -382,7 +387,10 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op) usdz_downscale_size, usdz_downscale_custom_size, usdz_is_arkit, - export_blender_metadata}; + export_blender_metadata, + triangulate_meshes, + quad_method, + ngon_method}; /* Take some defaults from the scene, if not specified explicitly. */ Scene *scene = CTX_data_scene(C); @@ -471,6 +479,13 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op) uiItemR(box, ptr, "export_face_maps", 0, NULL, ICON_NONE); uiItemR(box, ptr, "export_uvmaps", 0, NULL, ICON_NONE); uiItemR(box, ptr, "export_normals", 0, NULL, ICON_NONE); + +uiItemR(box, ptr, "triangulate_meshes", 0, NULL, ICON_NONE); + +uiLayout *sub = uiLayoutColumn(box, false); +uiLayoutSetActive(sub, RNA_boolean_get(ptr, "triangulate_meshes")); +uiItemR(sub, ptr, "quad_method", 0, IFACE_("Method Quads"), ICON_NONE); +uiItemR(sub, ptr, "ngon_method", 0, IFACE_("Polygons"), ICON_NONE); } box = uiLayoutBox(layout); @@ -533,7 +548,6 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op) uiItemR(box, ptr, "overwrite_textures", 0, NULL, ICON_NONE); } -//!TODO: add custom size int uiItemR(box, ptr, "usdz_downscale_size", 0, NULL, ICON_NONE); if (RNA_enum_get(ptr, "usdz_downscale_size") == USD_TEXTURE_SIZE_CUSTOM) { uiItemR(box, ptr, "usdz_downscale_custom_size", 0, NULL, ICON_NONE); @@ -548,7 +562,6 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op) uiItemL(box, IFACE_("Experimental:"), ICON_NONE); uiItemR(box, ptr, "use_instancing", 0, NULL, ICON_NONE); uiItemR(box, ptr, "fix_skel_root", 0, NULL, ICON_NONE); - } static bool wm_usd_export_check(bContext *UNUSED(C), wmOperator *op) @@ -976,6 +989,26 @@ void WM_OT_usd_export(struct wmOperatorType *ot) true, "Export Blender Metadata", "Write Blender-specific information to the Stage's customLayerData"); + + RNA_def_boolean(ot->srna, + "triangulate_meshes", + false, + "Triangulate Meshes", + "Triangulate meshes during export"); + + RNA_def_enum(ot->srna, + "quad_method", + rna_enum_modifier_triangulate_quad_method_items, + MOD_TRIANGULATE_QUAD_SHORTEDGE, + "Quad Method", + "Method for splitting the quads into triangles"); + + RNA_def_enum(ot->srna, + "ngon_method", + rna_enum_modifier_triangulate_ngon_method_items, + MOD_TRIANGULATE_NGON_BEAUTY, + "N-gon Method", + "Method for splitting the n-gons into triangles"); } /* == USD Import == */ diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index 8b2d76d92f5..cdf38d65697 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -21,6 +21,9 @@ #include "BKE_modifier.h" #include
[Bf-blender-cvs] [fb1f756bd15] universal-scene-description: USD export to USDZ.
Commit: fb1f756bd1591d6033f6ef0bcf068f13681feb29 Author: Michael Kowalski Date: Mon Sep 26 18:19:42 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBfb1f756bd1591d6033f6ef0bcf068f13681feb29 USD export to USDZ. USDZ export code developed by Sonny Campbell in patch D15623, which is currently under review. Charles added USDZ Texture downsample export functionality and a switch for creating ARKit assets during USDZ export. === M release/scripts/startup/bl_ui/space_topbar.py M source/blender/blenkernel/BKE_image.h M source/blender/blenkernel/intern/cachefile.c M source/blender/blenkernel/intern/image.cc M source/blender/blenlib/BLI_fileops.h M source/blender/blenlib/intern/fileops.c M source/blender/blenlib/intern/storage.c M source/blender/editors/io/io_usd.c M source/blender/editors/space_file/filelist.c M source/blender/io/usd/intern/usd_capi_export.cc M source/blender/io/usd/usd.h === diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py index da089ea23b0..9583e54e7c3 100644 --- a/release/scripts/startup/bl_ui/space_topbar.py +++ b/release/scripts/startup/bl_ui/space_topbar.py @@ -453,7 +453,7 @@ class TOPBAR_MT_file_import(Menu): self.layout.operator("wm.alembic_import", text="Alembic (.abc)") if bpy.app.build_options.usd: self.layout.operator( -"wm.usd_import", text="Universal Scene Description (.usd, .usdc, .usda)") +"wm.usd_import", text="Universal Scene Description (.usd*)") if bpy.app.build_options.io_gpencil: self.layout.operator("wm.gpencil_import_svg", text="SVG as Grease Pencil") @@ -476,7 +476,7 @@ class TOPBAR_MT_file_export(Menu): self.layout.operator("wm.alembic_export", text="Alembic (.abc)") if bpy.app.build_options.usd: self.layout.operator( -"wm.usd_export", text="Universal Scene Description (.usd, .usdc, .usda)") +"wm.usd_export", text="Universal Scene Description (.usd*)") if bpy.app.build_options.io_gpencil: # Pugixml lib dependency diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index eb43ce823ac..8d186e967f2 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -165,6 +165,7 @@ void BKE_image_alpha_mode_from_extension(struct Image *image); /** * Returns a new image or NULL if it can't load. */ +struct Image *BKE_image_load_ex(struct Main *bmain, const char *filepath, int flag); struct Image *BKE_image_load(struct Main *bmain, const char *filepath); /** * Returns existing Image when filename/type is same. diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index fd83ac50cad..b8ee2a1d20b 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -366,7 +366,7 @@ void BKE_cachefile_eval(Main *bmain, Depsgraph *depsgraph, CacheFile *cache_file } #endif #ifdef WITH_USD - if (BLI_path_extension_check_glob(filepath, "*.usd;*.usda;*.usdc")) { + if (BLI_path_extension_check_glob(filepath, "*.usd;*.usda;*.usdc;*.usdz")) { cache_file->type = CACHEFILE_TYPE_USD; cache_file->handle = USD_create_handle(bmain, filepath, _file->object_paths); BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX); diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index ae24383e5b9..d57ec83ae61 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -666,11 +666,11 @@ static void image_init(Image *ima, short source, short type) ima->stereo3d_format = MEM_cnew("Image Stereo Format"); } -static Image *image_alloc(Main *bmain, const char *name, short source, short type) +static Image *image_alloc_ex(Main *bmain, const char *name, short source, short type, int flag) { Image *ima; - ima = static_cast(BKE_libblock_alloc(bmain, ID_IM, name, 0)); + ima = static_cast(BKE_libblock_alloc(bmain, ID_IM, name, flag)); if (ima) { image_init(ima, source, type); } @@ -678,6 +678,11 @@ static Image *image_alloc(Main *bmain, const char *name, short source, short typ return ima; } +static Image *image_alloc(Main *bmain, const char *name, short source, short type) +{ + return image_alloc_ex(bmain, name, source, type, 0); +} + /** * Get the ibuf from an image cache by its index and entry. * Local use here only. @@ -
[Bf-blender-cvs] [90e1c892b7a] universal-scene-description: USD Export: Save Blender file path to metadata.
Commit: 90e1c892b7a1cc80de05260e7a71e2d2916ecb4d Author: Michael Kowalski Date: Mon Sep 19 16:03:11 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB90e1c892b7a1cc80de05260e7a71e2d2916ecb4d USD Export: Save Blender file path to metadata. Write source Blender file path to stage customData. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_capi_export.cc M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 924a4b18619..09d796fc315 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -303,6 +303,8 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op) const bool export_blendshapes = RNA_boolean_get(op->ptr, "export_blendshapes"); + const bool export_blender_metadata = RNA_boolean_get(op->ptr, "export_blender_metadata"); + struct USDExportParams params = {RNA_int_get(op->ptr, "start"), RNA_int_get(op->ptr, "end"), export_animation, @@ -359,7 +361,8 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op) xform_op_mode, fix_skel_root, overwrite_textures, - export_blendshapes}; + export_blendshapes, + export_blender_metadata}; /* Take some defaults from the scene, if not specified explicitly. */ Scene *scene = CTX_data_scene(C); @@ -424,6 +427,7 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op) box = uiLayoutBox(layout); uiItemL(box, IFACE_("Attributes:"), ICON_NONE); + uiItemR(box, ptr, "export_blender_metadata", 0, NULL, ICON_NONE); uiItemR(box, ptr, "export_custom_properties", 0, NULL, ICON_NONE); if (RNA_boolean_get(ptr, "export_custom_properties")) { uiItemR(box, ptr, "add_properties_namespace", 0, NULL, ICON_NONE); @@ -517,6 +521,7 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op) uiItemL(box, IFACE_("Experimental:"), ICON_NONE); uiItemR(box, ptr, "use_instancing", 0, NULL, ICON_NONE); uiItemR(box, ptr, "fix_skel_root", 0, NULL, ICON_NONE); + } static bool wm_usd_export_check(bContext *UNUSED(C), wmOperator *op) @@ -915,6 +920,12 @@ void WM_OT_usd_export(struct wmOperatorType *ot) "Relative Paths", "Use relative paths to reference external files (i.e. textures, volumes) in " "USD, otherwise use absolute paths"); + + RNA_def_boolean(ot->srna, + "export_blender_metadata", + true, + "Export Blender Metadata", + "Write Blender-specific information to the Stage's customLayerData"); } /* == USD Import == */ diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc index 645b4b12a5e..d7f719e114b 100644 --- a/source/blender/io/usd/intern/usd_capi_export.cc +++ b/source/blender/io/usd/intern/usd_capi_export.cc @@ -288,6 +288,25 @@ static void export_startjob(void *customdata, usd_stage->GetRootLayer()->SetDocumentation(std::string("Blender v") + BKE_blender_version_string()); + /* Add any Blender-specific custom export data */ + if (data->params.export_blender_metadata && strlen(data->bmain->filepath)) { +auto root_layer = usd_stage->GetRootLayer(); +char full_path[1024]; +strcpy(full_path, data->bmain->filepath); + +// make all paths uniformly unix-like +BLI_str_replace_char(full_path + 2, SEP, ALTSEP); + +char basename[128]; +strcpy(basename, BLI_path_basename(full_path)); +BLI_split_dir_part(full_path, full_path, 1024); + +pxr::VtDictionary custom_data; +custom_data.SetValueAtPath(std::string("sourceFilename"), pxr::VtValue(basename)); +custom_data.SetValueAtPath(std::string("sourceDirPath"), pxr::VtValue(full_path)); +root_layer->SetCustomLayerData(custom_data); + } + /* Set up the stage for animated data. */ if (data->params.export_animation) { usd_stage->SetTimeCodesPerSecond(FPS); diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h index 3829bbda8f4..0f32968705e 100644 --- a/source/blender/io/usd/usd.h +++ b/source/blender/io/usd/usd.h @@ -121,6 +121,7 @@ struct USDExportParams { bool fix_skel_root; bool overwrite_textures; bool
[Bf-blender-cvs] [b2ad97ba97f] tmp-usd-alab-v2-T100452: Merge branch 'master' into tmp-usd-alab-v2-T100452
Commit: b2ad97ba97f3e55d1dd463e29ca0b2ec6fe761e1 Author: Michael Kowalski Date: Fri Sep 23 16:56:14 2022 -0400 Branches: tmp-usd-alab-v2-T100452 https://developer.blender.org/rBb2ad97ba97f3e55d1dd463e29ca0b2ec6fe761e1 Merge branch 'master' into tmp-usd-alab-v2-T100452 === === diff --cc source/blender/editors/io/io_usd.c index fd8caf6836e,eb80cabcd7f..1496eac0027 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@@ -451,9 -427,10 +451,11 @@@ static int wm_usd_import_exec(bContext .import_usd_preview = import_usd_preview, .set_material_blend = set_material_blend, .light_intensity_scale = light_intensity_scale, - .mtl_name_collision_mode = mtl_name_collision_mode}; + .mtl_name_collision_mode = mtl_name_collision_mode, + .mtl_purpose = mtl_purpose}; + STRNCPY(params.prim_path_mask, prim_path_mask); + const bool ok = USD_import(C, filename, , as_background_job); return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; ___ 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
[Bf-blender-cvs] [752a9b743e9] master: USD IO: fixed compiler warnings
Commit: 752a9b743e9703e674b28e0bc041a43011147676 Author: Michael Kowalski Date: Mon Sep 12 15:47:45 2022 -0400 Branches: master https://developer.blender.org/rB752a9b743e9703e674b28e0bc041a43011147676 USD IO: fixed compiler warnings === M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 534ba813743..eb80cabcd7f 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -199,7 +199,7 @@ static void free_operator_customdata(wmOperator *op) } } -static void wm_usd_export_cancel(bContext *C, wmOperator *op, const wmEvent *event) +static void wm_usd_export_cancel(bContext *UNUSED(C), wmOperator *op) { free_operator_customdata(op); } @@ -436,7 +436,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } -static void wm_usd_import_cancel(bContext *C, wmOperator *op, const wmEvent *event) +static void wm_usd_import_cancel(bContext *UNUSED(C), wmOperator *op) { free_operator_customdata(op); } ___ 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
[Bf-blender-cvs] [ba3c642f77a] tmp_mak_091222: USD IO: fixed warnings.
Commit: ba3c642f77a46dc7dcfaa77ee1cf95d1e80fc6bf Author: Michael Kowalski Date: Mon Sep 12 14:23:54 2022 -0400 Branches: tmp_mak_091222 https://developer.blender.org/rBba3c642f77a46dc7dcfaa77ee1cf95d1e80fc6bf USD IO: fixed warnings. === M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 534ba813743..eb80cabcd7f 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -199,7 +199,7 @@ static void free_operator_customdata(wmOperator *op) } } -static void wm_usd_export_cancel(bContext *C, wmOperator *op, const wmEvent *event) +static void wm_usd_export_cancel(bContext *UNUSED(C), wmOperator *op) { free_operator_customdata(op); } @@ -436,7 +436,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } -static void wm_usd_import_cancel(bContext *C, wmOperator *op, const wmEvent *event) +static void wm_usd_import_cancel(bContext *UNUSED(C), wmOperator *op) { free_operator_customdata(op); } ___ 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
[Bf-blender-cvs] [54571003dc1] master: Fix T100016: Memory leak in USD importer.
Commit: 54571003dc115233896df97c8d80a03f00fd8c14 Author: Michael Kowalski Date: Mon Sep 12 12:46:27 2022 -0400 Branches: master https://developer.blender.org/rB54571003dc115233896df97c8d80a03f00fd8c14 Fix T100016: Memory leak in USD importer. These changes were implemented by Sonny Campbell. Fixed the first issue by freeing the operator customdata when the import is cancelled. Fixed the second issue by using a character array instead of allocating new memory for the prim_path_mask. Differential Revision: https://developer.blender.org/D15781 === M source/blender/editors/io/io_usd.c M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index ba118a5e289..534ba813743 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -191,6 +191,19 @@ static void wm_usd_export_draw(bContext *UNUSED(C), wmOperator *op) uiItemR(box, ptr, "use_instancing", 0, NULL, ICON_NONE); } +static void free_operator_customdata(wmOperator *op) +{ + if (op->customdata) { +MEM_freeN(op->customdata); +op->customdata = NULL; + } +} + +static void wm_usd_export_cancel(bContext *C, wmOperator *op, const wmEvent *event) +{ + free_operator_customdata(op); +} + static bool wm_usd_export_check(bContext *UNUSED(C), wmOperator *op) { char filepath[FILE_MAX]; @@ -215,6 +228,7 @@ void WM_OT_usd_export(struct wmOperatorType *ot) ot->exec = wm_usd_export_exec; ot->poll = WM_operator_winactive; ot->ui = wm_usd_export_draw; + ot->cancel = wm_usd_export_cancel; ot->check = wm_usd_export_check; ot->flag = OPTYPE_REGISTER | OPTYPE_PRESET; /* No UNDO possible. */ @@ -360,7 +374,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const bool create_collection = RNA_boolean_get(op->ptr, "create_collection"); - char *prim_path_mask = malloc(1024); + char prim_path_mask[1024]; RNA_string_get(op->ptr, "prim_path_mask", prim_path_mask); const bool import_guide = RNA_boolean_get(op->ptr, "import_guide"); @@ -402,7 +416,6 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .import_materials = import_materials, .import_meshes = import_meshes, .import_volumes = import_volumes, - .prim_path_mask = prim_path_mask, .import_subdiv = import_subdiv, .import_instance_proxies = import_instance_proxies, .create_collection = create_collection, @@ -416,11 +429,18 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .light_intensity_scale = light_intensity_scale, .mtl_name_collision_mode = mtl_name_collision_mode}; + STRNCPY(params.prim_path_mask, prim_path_mask); + const bool ok = USD_import(C, filename, , as_background_job); return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } +static void wm_usd_import_cancel(bContext *C, wmOperator *op, const wmEvent *event) +{ + free_operator_customdata(op); +} + static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) { uiLayout *layout = op->layout; @@ -476,6 +496,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot) ot->invoke = wm_usd_import_invoke; ot->exec = wm_usd_import_exec; + ot->cancel = wm_usd_import_cancel; ot->poll = WM_operator_winactive; ot->ui = wm_usd_import_draw; diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h index a07315d8b4e..3494d8ffdc3 100644 --- a/source/blender/io/usd/usd.h +++ b/source/blender/io/usd/usd.h @@ -52,7 +52,7 @@ struct USDImportParams { bool import_materials; bool import_meshes; bool import_volumes; - char *prim_path_mask; + char prim_path_mask[1024]; bool import_subdiv; bool import_instance_proxies; bool create_collection; ___ 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
[Bf-blender-cvs] [19fa05d37c0] universal-scene-description: USD skel export fixes.
Commit: 19fa05d37c0fc27b79baa195a6f2cf72aee621fc Author: Michael Kowalski Date: Fri Sep 2 18:51:55 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB19fa05d37c0fc27b79baa195a6f2cf72aee621fc USD skel export fixes. Fixed error in USDSkinnedMeshWriter which was causing the mesh to be written more than once when exporting blendshapes is disabled. Also removed unnecessary warnings when the mesh has deform groups that don't match any bones. Updated USDBlendShapeMeshWriter to skip creating a blendshape neutral mesh if exporting blendshapes is disabled. Added more descriptive error message when the shape key offset count doesn't match the mesh vertex count. Now exporting the default mesh when this size mismatch is detected. === M source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc M source/blender/io/usd/intern/usd_writer_skinned_mesh.cc === diff --git a/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc b/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc index 6f6a78f9974..44c2d1947f4 100644 --- a/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc @@ -39,6 +39,9 @@ #include "DNA_meshdata_types.h" #include "DNA_meta_types.h" +#include "WM_api.h" +#include "WM_types.h" + #include namespace usdtokens { @@ -144,18 +147,28 @@ void USDBlendShapeMeshWriter::write_blendshape(HierarchyContext ) const return; } - pxr::UsdSkelSkeleton skel = get_skeleton(context); + const Key *key = get_shape_key(context.object); - if (!skel) { -printf("WARNING: couldn't get skeleton for blendshape mesh prim %s\n", - this->usd_export_context_.usd_path.GetString().c_str()); + if (!key || !key->block.first) { +WM_reportf(RPT_WARNING, + "WARNING: couldn't get shape key for blendshape mesh prim %s", + usd_export_context_.usd_path.GetString().c_str()); return; } - const Key *key = get_shape_key(context.object); + /* Validate the offset counts. */ + Mesh *src_mesh = static_cast(context.object->data); + KeyBlock *basis = reinterpret_cast(src_mesh->key->block.first); + if (src_mesh->totvert != basis->totelem) { +/* No need for a warning, as we would have warned about + * the vert count mismatch when creating the mesh. */ +return; + } - if (!key) { -printf("WARNING: couldn't get shape key for blendshape mesh prim %s\n", + pxr::UsdSkelSkeleton skel = get_skeleton(context); + + if (!skel) { +printf("WARNING: couldn't get skeleton for blendshape mesh prim %s\n", this->usd_export_context_.usd_path.GetString().c_str()); return; } @@ -331,7 +344,10 @@ pxr::UsdSkelSkeleton USDBlendShapeMeshWriter::get_skeleton(const HierarchyContex Mesh *USDBlendShapeMeshWriter::get_export_mesh(Object *object_eval, bool _needsfree) { - if (!is_blendshape_mesh(object_eval)) { + /* We must check if blendshapes are enabled before attempting to create the + * blendshape mesh. */ + if (!(usd_export_context_.export_params.export_blendshapes && is_blendshape_mesh(object_eval))) { +/* Get the default mesh. */ return USDMeshWriter::get_export_mesh(object_eval, r_needsfree); } @@ -348,10 +364,15 @@ Mesh *USDBlendShapeMeshWriter::get_export_mesh(Object *object_eval, bool _need KeyBlock *basis = reinterpret_cast(src_mesh->key->block.first); if (src_mesh->totvert != basis->totelem) { -printf("WARNING: shape vert count %d doesn't match shape key number of elements %d\n", - src_mesh->totvert, - basis->totelem); -return nullptr; +WM_reportf(RPT_WARNING, + "USD Export: mesh %s can't be exported as a blendshape because the mesh vertex count %d " + "doesn't match shape key number of elements %d'. This may be because the mesh topology was " + "changed by a modifier. Exporting meshes with modifiers as blendshapes isn't currently supported", + object_eval->id.name + 2, + src_mesh->totvert, + basis->totelem); + +return USDMeshWriter::get_export_mesh(object_eval, r_needsfree); } Mesh *temp_mesh = reinterpret_cast( diff --git a/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc b/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc index a79b0dd42fe..320cd41b1ae 100644 --- a/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_skinned_mesh.cc @@ -78,9 +78,11 @@ USDSkinnedMeshWriter::USDSkinnedMeshWriter(const USDExporterContext ) void USDSkinnedMeshWriter::do_write(HierarchyContext )
[Bf-blender-cvs] [95185f6e7e0] universal-scene-description: USD IO: fixed includes.
Commit: 95185f6e7e0d14406515dc22146f2b8dfea54421 Author: Michael Kowalski Date: Tue Aug 30 19:41:37 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB95185f6e7e0d14406515dc22146f2b8dfea54421 USD IO: fixed includes. Fixed include order to fix build error. Also removed unneeded includes. === M source/blender/io/usd/intern/usd_skel_convert.cc === diff --git a/source/blender/io/usd/intern/usd_skel_convert.cc b/source/blender/io/usd/intern/usd_skel_convert.cc index 833e2ee9c5a..f05c0ffc2dc 100644 --- a/source/blender/io/usd/intern/usd_skel_convert.cc +++ b/source/blender/io/usd/intern/usd_skel_convert.cc @@ -26,9 +26,18 @@ #include #include +#include "DNA_anim_types.h" +#include "DNA_armature_types.h" +#include "DNA_key_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_meta_types.h" +#include "DNA_scene_types.h" + #include "BKE_action.h" #include "BKE_armature.h" #include "BKE_deform.h" +#include "BKE_fcurve.h" #include "BKE_key.h" #include "BKE_lib_id.h" #include "BKE_mesh.h" @@ -39,24 +48,7 @@ #include "BLI_math_vector.h" -#include "DNA_armature_types.h" -#include "DNA_key_types.h" -#include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" -#include "DNA_meta_types.h" -#include "DNA_scene_types.h" - -#include "BKE_main.h" -#include "BKE_scene.h" -#include "BLI_listbase.h" -#include "BLI_math.h" -#include "BLI_path_util.h" -#include "BLI_string.h" -#include "DNA_scene_types.h" - -#include "BKE_fcurve.h" #include "ED_keyframing.h" - #include "ED_mesh.h" #include ___ 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
[Bf-blender-cvs] [5156e12a0a4] universal-scene-description: Merge branch 'master' into universal-scene-description
Commit: 5156e12a0a4350d2f81cdd59d0385b0b04337bf3 Author: Michael Kowalski Date: Tue Aug 30 18:13:18 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB5156e12a0a4350d2f81cdd59d0385b0b04337bf3 Merge branch 'master' into universal-scene-description === === diff --cc source/blender/io/common/IO_abstract_hierarchy_iterator.h index 42663c59a9e,966eb640264..25e4ba07363 --- a/source/blender/io/common/IO_abstract_hierarchy_iterator.h +++ b/source/blender/io/common/IO_abstract_hierarchy_iterator.h @@@ -347,20 -331,8 +347,20 @@@ class AbstractHierarchyIterator /* Called by release_writers() to free what the create_XXX_writer() functions allocated. */ virtual void release_writer(AbstractHierarchyWriter *writer) = 0; + /* Return true if data writers should be created for this context. */ + virtual bool include_data_writers(const HierarchyContext *) const + { +return true; + } + + /* Return true if children of the context should be converted to writers. */ + virtual bool include_child_writers(const HierarchyContext *) const + { +return true; + } + AbstractHierarchyWriter *get_writer(const std::string _path) const; - ExportChildren _children(const HierarchyContext *parent_context); + ExportChildren _children(const HierarchyContext *context); }; } // namespace blender::io ___ 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
[Bf-blender-cvs] [219a71a4278] universal-scene-description: USD import: fix mac build warnings and error.
Commit: 219a71a4278d6cbe0f888aee20545323c73dc7c8 Author: Michael Kowalski Date: Tue Aug 30 19:03:16 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB219a71a4278d6cbe0f888aee20545323c73dc7c8 USD import: fix mac build warnings and error. === M source/blender/io/usd/intern/usd_skel_convert.cc === diff --git a/source/blender/io/usd/intern/usd_skel_convert.cc b/source/blender/io/usd/intern/usd_skel_convert.cc index f8a3aa43d8f..833e2ee9c5a 100644 --- a/source/blender/io/usd/intern/usd_skel_convert.cc +++ b/source/blender/io/usd/intern/usd_skel_convert.cc @@ -44,6 +44,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_meta_types.h" +#include "DNA_scene_types.h" #include "BKE_main.h" #include "BKE_scene.h" @@ -341,7 +342,6 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim) return; } - blendshapes; if (!skel_anim.GetBlendShapesAttr().Get()) { return; } @@ -435,7 +435,7 @@ void create_skeleton_curves(Main *bmain, if (it == joint_to_bone_map.end()) { /* This joint doesn't correspond to any bone we created. - /* Add null placeholders for the channel curves. */ + * Add null placeholders for the channel curves. */ loc_curves.push_back(nullptr); loc_curves.push_back(nullptr); loc_curves.push_back(nullptr); @@ -719,7 +719,7 @@ void import_skel_bindings(Main *bmain, Object *mesh_obj, pxr::UsdPrim prim) for (int i = 0; i < mesh->totvert; ++i) { /* Offset into the weights array, which is -/* always 0 for constant interpolation. */ + * always 0 for constant interpolation. */ int offset = 0; if (interp == pxr::UsdGeomTokens->vertex) { offset = i * joint_weights_elem_size; ___ 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
[Bf-blender-cvs] [095f016fc07] universal-scene-description: USD import: read skeletons.
Commit: 095f016fc07300a6ed30c02144e6100c313faf01 Author: Michael Kowalski Date: Tue Aug 30 15:15:42 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB095f016fc07300a6ed30c02144e6100c313faf01 USD import: read skeletons. Added new option to import USD skeletons as Blender armatures. Added new USDSkeletonReader class and updated the mesh import code to optionally create armature modifiers for meshes bound to skeletons. Added logic to the mesh reader to allow overriding the mesh transform to ensure the mesh is aligned with the authored geom bind transform. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/CMakeLists.txt M source/blender/io/usd/intern/usd_capi_import.cc M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/usd/intern/usd_reader_mesh.h A source/blender/io/usd/intern/usd_reader_skeleton.cc A source/blender/io/usd/intern/usd_reader_skeleton.h M source/blender/io/usd/intern/usd_reader_stage.cc M source/blender/io/usd/intern/usd_reader_stage.h M source/blender/io/usd/intern/usd_reader_xform.cc M source/blender/io/usd/intern/usd_reader_xform.h M source/blender/io/usd/intern/usd_skel_convert.cc M source/blender/io/usd/intern/usd_skel_convert.h M source/blender/io/usd/intern/usd_writer_armature.cc M source/blender/io/usd/intern/usd_writer_skinned_mesh.cc M source/blender/io/usd/intern/usd_writer_transform.cc M source/blender/io/usd/intern/usd_writer_transform.h M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index a9f881025c8..8c8eab0f036 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -965,6 +965,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const bool import_meshes = RNA_boolean_get(op->ptr, "import_meshes"); const bool import_blendshapes = RNA_boolean_get(op->ptr, "import_blendshapes"); const bool import_volumes = RNA_boolean_get(op->ptr, "import_volumes"); + const bool import_skeletons = RNA_boolean_get(op->ptr, "import_skeletons"); const bool import_subdiv = RNA_boolean_get(op->ptr, "import_subdiv"); @@ -1031,6 +1032,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .import_meshes = import_meshes, .import_blendshapes = import_blendshapes, .import_volumes = import_volumes, + .import_skeletons = import_skeletons, .prim_path_mask = prim_path_mask, .import_subdiv = import_subdiv, .import_instance_proxies = import_instance_proxies, @@ -1072,6 +1074,7 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) uiItemR(col, ptr, "import_meshes", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_blendshapes", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_volumes", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "import_skeletons", 0, NULL, ICON_NONE); uiItemR(box, ptr, "prim_path_mask", 0, NULL, ICON_NONE); uiItemR(box, ptr, "scale", 0, NULL, ICON_NONE); uiItemR(box, ptr, "apply_unit_conversion_scale", 0, NULL, ICON_NONE); @@ -1168,6 +1171,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "import_meshes", true, "Meshes", ""); RNA_def_boolean(ot->srna, "import_blendshapes", true, "Blend Shapes", ""); RNA_def_boolean(ot->srna, "import_volumes", true, "Volumes", ""); + RNA_def_boolean(ot->srna, "import_skeletons", true, "Skeletons", ""); RNA_def_boolean(ot->srna, "import_subdiv", diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt index 006768c06d6..4a77bb32544 100644 --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@ -80,6 +80,7 @@ set(SRC intern/usd_reader_mesh.cc intern/usd_reader_nurbs.cc intern/usd_reader_prim.cc + intern/usd_reader_skeleton.cc intern/usd_reader_stage.cc intern/usd_reader_volume.cc intern/usd_reader_xform.cc @@ -119,6 +120,7 @@ set(SRC intern/usd_reader_mesh.h intern/usd_reader_nurbs.h intern/usd_reader_prim.h + intern/usd_reader_skeleton.h intern/usd_reader_stage.h intern/usd_reader_volume.h intern/usd_reader_xform.h diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/i
[Bf-blender-cvs] [5e54c0cbf19] universal-scene-description: USD export: fix skel root by default.
Commit: 5e54c0cbf19c9da056be153130dc324f600a8149 Author: Michael Kowalski Date: Tue Aug 30 17:06:21 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB5e54c0cbf19c9da056be153130dc324f600a8149 USD export: fix skel root by default. Now enabling fixing the skel root hierarchy on export by default. Also removed 'Experimental' from the 'Armatures' export option label. === M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 8c8eab0f036..924a4b18619 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -658,7 +658,7 @@ void WM_OT_usd_export(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "export_armatures", false, - "Armatures (Experimental)", + "Armatures", "Export armatures and skinned meshes"); RNA_def_boolean(ot->srna, @@ -675,7 +675,7 @@ void WM_OT_usd_export(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "fix_skel_root", -false, +true, "Fix Skel Root", "If exporting armatures, attempt to automatically " "correct invalid USD Skel Root hierarchies"); ___ 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
[Bf-blender-cvs] [5649158db99] tmp-usd-alab-v2-T100452: USD import: Alab v2 load errors.
Commit: 5649158db9985608adf3b24d0726cdab35788036 Author: Michael Kowalski Date: Tue Aug 16 22:15:13 2022 -0400 Branches: tmp-usd-alab-v2-T100452 https://developer.blender.org/rB5649158db9985608adf3b24d0726cdab35788036 USD import: Alab v2 load errors. Work in progress addressing issues loading the Alab v2 scene. Load primvars of type Float2Array as texture coordinates. Fixed type mismatch loading UsdPrimvarReader_float2 varname input. For materials that have an authored opacity value, changed the blend mode from Alpha Blend to Alpha Hashed, to mitigate object soring issue. Added import option to specify loading materials by purpose to allow explicitly loading full materials for debugging. === 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_reader_mesh.cc M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index a59cdf60243..6c4c35fe490 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -71,6 +71,28 @@ const EnumPropertyItem rna_enum_usd_mtl_name_collision_mode_items[] = { {0, NULL, 0, NULL, NULL}, }; +const EnumPropertyItem rna_enum_usd_mtl_purpose_items[] = { +{USD_MTL_PURPOSE_ALL, + "MTL_ALL_PURPOSE", + 0, + "All Purpose", + "Attempt to import 'allPurpose' materials. " + "Load 'preview' and 'full' materials as a fallback, in that order"}, +{USD_MTL_PURPOSE_PREVIEW, + "MTL_PREVIEW", + 0, + "Preview", + "Attempt to import 'preview' materials. " + "Load 'allPurpose' and 'full' materials as a fallback, in that order"}, +{USD_MTL_PURPOSE_FULL, + "MTL_FULL", + 0, + "Full", + "Attempt to import 'full' materials. " + "Load 'allPurpose' and 'preview' materials as a fallback, in that order"}, +{0, NULL, 0, NULL, NULL}, +}; + /* Stored in the wmOperator's customdata field to indicate it should run as a background job. * This is set when the operator is invoked, and not set when it is only executed. */ enum { AS_BACKGROUND_JOB = 1 }; @@ -388,6 +410,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const eUSDMtlNameCollisionMode mtl_name_collision_mode = RNA_enum_get(op->ptr, "mtl_name_collision_mode"); + const eUSDMtlPurpose mtl_purpose = RNA_enum_get(op->ptr, "mtl_purpose"); + /* TODO(makowalski): Add support for sequences. */ const bool is_sequence = false; int offset = 0; @@ -427,7 +451,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .import_usd_preview = import_usd_preview, .set_material_blend = set_material_blend, .light_intensity_scale = light_intensity_scale, - .mtl_name_collision_mode = mtl_name_collision_mode}; + .mtl_name_collision_mode = mtl_name_collision_mode, + .mtl_purpose = mtl_purpose}; const bool ok = USD_import(C, filename, , as_background_job); @@ -479,6 +504,8 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) uiLayout *row = uiLayoutRow(col, true); uiItemR(row, ptr, "set_material_blend", 0, NULL, ICON_NONE); uiLayoutSetEnabled(row, RNA_boolean_get(ptr, "import_usd_preview")); + row = uiLayoutRow(col, true); + uiItemR(row, ptr, "mtl_purpose", 0, NULL, ICON_NONE); } void WM_OT_usd_import(struct wmOperatorType *ot) @@ -585,6 +612,16 @@ void WM_OT_usd_import(struct wmOperatorType *ot) "the material blend method will automatically be set based on the " "shader's opacity and opacityThreshold inputs"); + RNA_def_enum( + ot->srna, + "mtl_purpose", + rna_enum_usd_mtl_purpose_items, + USD_MTL_PURPOSE_ALL, + "Material Purpose", + "Attempt to import materials with the given purpose. " + "If no material with this purpose is bound to the primitive, " + "fall back on loading any other bound material"); + RNA_def_float(ot->srna, "light_intensity_scale", 1.0f, diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index f59b8be147e..5d64f3279ee 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -39
[Bf-blender-cvs] [b31807c75f0] tmp-usd-alab-v2-T100452: Format fixes.
Commit: b31807c75f0c18c43ac6979e6da57dc9d420167a Author: Michael Kowalski Date: Tue Aug 16 22:25:51 2022 -0400 Branches: tmp-usd-alab-v2-T100452 https://developer.blender.org/rBb31807c75f0c18c43ac6979e6da57dc9d420167a Format fixes. === 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_reader_mesh.cc M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 6c4c35fe490..fd8caf6836e 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -612,15 +612,14 @@ void WM_OT_usd_import(struct wmOperatorType *ot) "the material blend method will automatically be set based on the " "shader's opacity and opacityThreshold inputs"); - RNA_def_enum( - ot->srna, - "mtl_purpose", - rna_enum_usd_mtl_purpose_items, - USD_MTL_PURPOSE_ALL, - "Material Purpose", - "Attempt to import materials with the given purpose. " - "If no material with this purpose is bound to the primitive, " - "fall back on loading any other bound material"); + RNA_def_enum(ot->srna, + "mtl_purpose", + rna_enum_usd_mtl_purpose_items, + USD_MTL_PURPOSE_ALL, + "Material Purpose", + "Attempt to import materials with the given purpose. " + "If no material with this purpose is bound to the primitive, " + "fall back on loading any other bound material"); RNA_def_float(ot->srna, "light_intensity_scale", diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index 5d64f3279ee..a786cdc70f4 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -749,7 +749,8 @@ void USDMaterialReader::convert_usd_primvar_reader_float2( std::string varname; if (varname_val.IsHolding()) { varname = varname_val.Get(); - } else if (varname_val.IsHolding()) { + } + else if (varname_val.IsHolding()) { varname = varname_val.Get().GetString(); } if (!varname.empty()) { diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index fb7f2cfe41c..c016c9127ec 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -62,7 +62,8 @@ static void build_mat_map(const Main *bmain, std::map * } } -static pxr::UsdShadeMaterial compute_bound_material(const pxr::UsdPrim , eUSDMtlPurpose purpose) +static pxr::UsdShadeMaterial compute_bound_material(const pxr::UsdPrim , +eUSDMtlPurpose purpose) { pxr::UsdShadeMaterial mtl; @@ -791,8 +792,8 @@ void USDMeshReader::assign_facesets_to_mpoly(double motionSampleTime, if (!subsets.empty()) { for (const pxr::UsdGeomSubset : subsets) { - pxr::UsdShadeMaterial subset_mtl = -utils::compute_bound_material(subset.GetPrim(), import_params_.mtl_purpose); + pxr::UsdShadeMaterial subset_mtl = utils::compute_bound_material(subset.GetPrim(), + import_params_.mtl_purpose); if (!subset_mtl) { continue; } @@ -822,8 +823,7 @@ void USDMeshReader::assign_facesets_to_mpoly(double motionSampleTime, if (r_mat_map->empty()) { -pxr::UsdShadeMaterial mtl = - utils::compute_bound_material(prim_, import_params_.mtl_purpose); +pxr::UsdShadeMaterial mtl = utils::compute_bound_material(prim_, import_params_.mtl_purpose); if (mtl) { pxr::SdfPath mtl_path = mtl.GetPath(); diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h index 7caba9dea07..7f0660765d1 100644 --- a/source/blender/io/usd/usd.h +++ b/source/blender/io/usd/usd.h @@ -31,7 +31,6 @@ typedef enum eUSDMtlPurpose { USD_MTL_PURPOSE_FULL = 2 } eUSDMtlPurpose; - struct USDExportParams { bool export_animation; bool export_hair; ___ 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
[Bf-blender-cvs] [1dfe4938cdd] universal-scene-description: Merge branch 'master' into universal-scene-description
Commit: 1dfe4938cdd4e0eb0c7d8febff51f5b2ab31e81f Author: Michael Kowalski Date: Sun Aug 14 17:16:40 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB1dfe4938cdd4e0eb0c7d8febff51f5b2ab31e81f Merge branch 'master' into universal-scene-description === === diff --cc source/blender/io/usd/intern/usd_capi_import.cc index d224715588a,03af3aed2d0..7c9e403e108 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@@ -412,56 -227,32 +413,88 @@@ static void import_startjob(void *custo archive->collect_readers(data->bmain); + if (data->params.import_lights && data->params.create_background_shader && + !archive->dome_lights().empty()) { +dome_light_to_world_material( +data->params, data->settings, data->scene, data->bmain, archive->dome_lights().front()); + } + + *data->do_update = true; *data->progress = 0.2f; const float size = static_cast(archive->readers().size()); size_t i = 0; + /* Read data, set prenting and create a cache file, if needed. */ + + /* We defer creating a cache file until we know that we need + * one. This is not only more efficient, but also avoids + * the problem where we can't overwrite the USD the + * cachefile is referencing because it has a pointer to the + * open stage for the lifetime of the scene. */ + CacheFile *cache_file = nullptr; + + /* Handle instance prototypes. + * TODO(makowalski): Move this logic inside USDReaderStage? */ ++ ++ /* Create prototype objects. ++ * TODO(makowalski): Sort prototype objects by name, as below? */ ++ for (const auto : archive->proto_readers()) { ++for (USDPrimReader *reader : pair.second) { ++ if (reader) { ++reader->create_object(data->bmain, 0.0); ++ } ++} ++ } ++ + for (const auto : archive->proto_readers()) { + +for (USDPrimReader *reader : pair.second) { + + if (!reader) { +continue; + } + + /* TODO(makowalski): Here and below, should we call + * read_object_data() with the actual time? */ + reader->read_object_data(data->bmain, 0.0); + + apply_cache_file(reader, data, _file); + + Object *ob = reader->object(); + + if (!ob) { +continue; + } + + const USDPrimReader *parent_reader = reader->parent(); + + ob->parent = parent_reader ? parent_reader->object() : nullptr; + + /* TODO(makowalski): Handle progress update. */ +} + } + + /* Sort readers by name: when creating a lot of objects in Blender, +* it is much faster if the order is sorted by name. */ + archive->sort_readers(); + *data->do_update = true; + *data->progress = 0.25f; + + /* Create blender objects. */ + for (USDPrimReader *reader : archive->readers()) { + if (!reader) { + continue; + } + reader->create_object(data->bmain, 0.0); + if ((++i & 1023) == 0) { + *data->do_update = true; + *data->progress = 0.25f + 0.25f * (i / size); + } + } + + /* Setup parenthood and read actual object data. */ + i = 0; for (USDPrimReader *reader : archive->readers()) { if (!reader) { diff --cc source/blender/io/usd/intern/usd_reader_stage.cc index 6bd47704945,df75be849e2..d5631d3ad7d --- a/source/blender/io/usd/intern/usd_reader_stage.cc +++ b/source/blender/io/usd/intern/usd_reader_stage.cc @@@ -291,9 -255,7 +294,7 @@@ USDPrimReader *USDStageReader::collect_ return nullptr; } - reader->create_object(bmain, 0.0); - - readers_.push_back(reader); + r_readers.push_back(reader); reader->incref(); /* Set each child reader's parent. */ @@@ -364,27 -311,14 +365,37 @@@ void USDStageReader::clear_readers( readers_.clear(); } +void USDStageReader::clear_proto_readers() +{ + for (auto : proto_readers_) { + +for (USDPrimReader *reader : pair.second) { + + if (!reader) { +continue; + } + + reader->decref(); + + if (reader->refcount() == 0) { +delete reader; + } +} + +pair.second.clear(); + } + + proto_readers_.clear(); +} + + void USDStageReader::sort_readers() + { + blender::parallel_sort( + readers_.begin(), readers_.end(), [](const USDPrimReader *a, const USDPrimReader *b) { + const char *na = a ? a->name().c_str() : ""; + const char *nb = b ? b->name().c_str() : ""; + return BLI_strcasecmp(na, nb) < 0; + }); + } + } // Namespace blender::io::usd diff --cc source/blender/io/usd/intern/usd_reader_stage.h index 51bfc9aa7e5,5f4a343f874..87f8a782568 --- a/source/blender/io
[Bf-blender-cvs] [3f3910966a3] universal-scene-description: USD import: invalid UsdUVTexture input crash.
Commit: 3f3910966a3eb2550ec4fa01180b70010c383096 Author: Michael Kowalski Date: Sun Aug 14 15:58:02 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB3f3910966a3eb2550ec4fa01180b70010c383096 USD import: invalid UsdUVTexture input crash. Fixed crash when accessing invalud texture file inputs. === 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 1ebd88cfbc4..a63667faca7 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -719,6 +719,12 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader _shader, /* Try to load the texture image. */ pxr::UsdShadeInput file_input = usd_shader.GetInput(usdtokens::file); + if (!file_input) { +std::cerr << "WARNING: Couldn't get file input for USD shader " << usd_shader.GetPath() + << std::endl; +return; + } + /* File input may have a connected source, e.g., if it's been overridden by * an input on the mateial. */ if (file_input.HasConnectedSource()) { @@ -735,12 +741,6 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader _shader, } } - if (!file_input) { -std::cerr << "WARNING: Couldn't get file input for USD shader " << usd_shader.GetPath() - << std::endl; -return; - } - pxr::VtValue file_val; if (!file_input.Get(_val) || !file_val.IsHolding()) { std::cerr << "WARNING: Couldn't get file input value for USD shader " << usd_shader.GetPath() ___ 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
[Bf-blender-cvs] [a61fdcd3493] universal-scene-description: USD blendshape import errors for instances.
Commit: a61fdcd34930089f19941b3c08394e692b882dd0 Author: Michael Kowalski Date: Sun Aug 14 14:24:09 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBa61fdcd34930089f19941b3c08394e692b882dd0 USD blendshape import errors for instances. No longer attempting to create a skel binding on instance proxies and proxies, as doing so generates USD errors. === M source/blender/io/usd/intern/usd_skel_convert.cc === diff --git a/source/blender/io/usd/intern/usd_skel_convert.cc b/source/blender/io/usd/intern/usd_skel_convert.cc index 9d3ed2b4d83..5c0c7af4812 100644 --- a/source/blender/io/usd/intern/usd_skel_convert.cc +++ b/source/blender/io/usd/intern/usd_skel_convert.cc @@ -131,6 +131,12 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim) return; } + if (prim.IsInstanceProxy() || prim.IsInPrototype()) { +/* Attempting to create a UsdSkelBindingAPI for + * instance proxies and prototypes generates USD errors. */ +return; + } + pxr::UsdSkelBindingAPI skel_api = pxr::UsdSkelBindingAPI::Apply(prim); if (!skel_api) { ___ 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
[Bf-blender-cvs] [9a2680a626f] universal-scene-description: USD import: fixed typo in debug message.
Commit: 9a2680a626f3ec08f10fe9eb927da69a9c181e92 Author: Michael Kowalski Date: Thu Aug 11 20:06:28 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB9a2680a626f3ec08f10fe9eb927da69a9c181e92 USD import: fixed typo in debug message. This was also causing mac and linux compile errors. === M source/blender/io/usd/intern/usd_skel_convert.cc === diff --git a/source/blender/io/usd/intern/usd_skel_convert.cc b/source/blender/io/usd/intern/usd_skel_convert.cc index 8256f86bbdb..9d3ed2b4d83 100644 --- a/source/blender/io/usd/intern/usd_skel_convert.cc +++ b/source/blender/io/usd/intern/usd_skel_convert.cc @@ -324,7 +324,7 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim) } if (weights.size() != curves.size()) { - std::cout << "Programmer error: number of weight samples doesn't match number of shapekey curve entries for time " << time << std::endl; + std::cout << "Programmer error: number of weight samples doesn't match number of shapekey curve entries for frame " << frame << std::endl; continue; } ___ 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
[Bf-blender-cvs] [a37e7e682f7] universal-scene-description: USD import: fix errors loading pixar example.
Commit: a37e7e682f72429bc7916c65e2609e4b240ce397 Author: Michael Kowalski Date: Thu Aug 11 19:12:19 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBa37e7e682f72429bc7916c65e2609e4b240ce397 USD import: fix errors loading pixar example. Fixed errors loading Pixar UsdSkel sample HumanFemaleKeepAlive.usd: now reading the inherited skeleton and animation and no longer creating curves for blendshapes that weren't imported as shapekeys for a given shape. === M source/blender/io/usd/intern/usd_skel_convert.cc === diff --git a/source/blender/io/usd/intern/usd_skel_convert.cc b/source/blender/io/usd/intern/usd_skel_convert.cc index 41df30f3f28..8256f86bbdb 100644 --- a/source/blender/io/usd/intern/usd_skel_convert.cc +++ b/source/blender/io/usd/intern/usd_skel_convert.cc @@ -242,25 +242,7 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim) } } - if (!skel_api.GetSkeletonRel().HasAuthoredTargets()) { -return; - } - - pxr::UsdRelationship skel_rel = skel_api.GetSkeletonRel(); - - if (!skel_api.GetSkeletonRel().GetTargets()) { -std::cout << "Couldn't get skeleton targets for prim " << prim.GetPath() << std::endl; -return; - } - - if (targets.empty()) { -return; - } - - /* TODO(makowalski): do we need to account for multiple skeleton targets? */ - pxr::SdfPath skel_path = targets.front(); - - pxr::UsdSkelSkeleton skel_prim(stage->GetPrimAtPath(skel_path)); + pxr::UsdSkelSkeleton skel_prim = skel_api.GetInheritedSkeleton(); if (!skel_prim) { return; @@ -272,8 +254,9 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim) return; } - pxr::UsdPrim anim_prim; - if (!skel_api.GetAnimationSource(_prim)) { + pxr::UsdPrim anim_prim = skel_api.GetInheritedAnimationSource(); + + if (!anim_prim) { return; } @@ -320,8 +303,10 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim) for (auto blendshape_name : blendshapes) { if (shapekey_names.find(blendshape_name) == shapekey_names.end()) { - printf("Warning: blendshape %s doesn't match any shapekey name\n", - blendshape_name.GetString().c_str()); + /* We didn't create a shapekey fo this blendshape, so we don't + * create a curve and insert a null placeholder in the curve array. */ + curves.push_back(nullptr); + continue; } std::string rna_path = "key_blocks[\"" + blendshape_name.GetString() + "\"].value"; @@ -339,12 +324,14 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim) } if (weights.size() != curves.size()) { - std::cout << "Programmer error: number of weight samples doesn't match number of shapekey curves for time " << time << std::endl; + std::cout << "Programmer error: number of weight samples doesn't match number of shapekey curve entries for time " << time << std::endl; continue; } for (int wi = 0; wi < weights.size(); ++wi) { - add_bezt(curves[wi], frame, weights[wi]); + if (curves[wi] != nullptr) { +add_bezt(curves[wi], frame, weights[wi]); + } } } ___ 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
[Bf-blender-cvs] [833df7ebc1e] universal-scene-description: USD import blendshapes.
Commit: 833df7ebc1ef7aecf84b412240162818e5c578e7 Author: Michael Kowalski Date: Wed Aug 10 23:19:57 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB833df7ebc1ef7aecf84b412240162818e5c578e7 USD import blendshapes. Importing USD blendshapes as shapekeys and creating animation curves for animated blendshape weights. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/CMakeLists.txt M source/blender/io/usd/intern/usd_reader_mesh.cc A source/blender/io/usd/intern/usd_skel_convert.cc A source/blender/io/usd/intern/usd_skel_convert.h M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 1cfb3c1e1cc..a9f881025c8 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -963,6 +963,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const bool import_lights = RNA_boolean_get(op->ptr, "import_lights"); const bool import_materials = RNA_boolean_get(op->ptr, "import_materials"); const bool import_meshes = RNA_boolean_get(op->ptr, "import_meshes"); + const bool import_blendshapes = RNA_boolean_get(op->ptr, "import_blendshapes"); const bool import_volumes = RNA_boolean_get(op->ptr, "import_volumes"); const bool import_subdiv = RNA_boolean_get(op->ptr, "import_subdiv"); @@ -1028,6 +1029,7 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .import_lights = import_lights, .import_materials = import_materials, .import_meshes = import_meshes, + .import_blendshapes = import_blendshapes, .import_volumes = import_volumes, .prim_path_mask = prim_path_mask, .import_subdiv = import_subdiv, @@ -1068,6 +1070,7 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) uiItemR(col, ptr, "import_lights", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_materials", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_meshes", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "import_blendshapes", 0, NULL, ICON_NONE); uiItemR(col, ptr, "import_volumes", 0, NULL, ICON_NONE); uiItemR(box, ptr, "prim_path_mask", 0, NULL, ICON_NONE); uiItemR(box, ptr, "scale", 0, NULL, ICON_NONE); @@ -1163,6 +1166,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "import_lights", true, "Lights", ""); RNA_def_boolean(ot->srna, "import_materials", true, "Materials", ""); RNA_def_boolean(ot->srna, "import_meshes", true, "Meshes", ""); + RNA_def_boolean(ot->srna, "import_blendshapes", true, "Blend Shapes", ""); RNA_def_boolean(ot->srna, "import_volumes", true, "Volumes", ""); RNA_def_boolean(ot->srna, diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt index 888b7cd1055..006768c06d6 100644 --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@ -69,6 +69,7 @@ set(SRC intern/usd_common.cc intern/usd_hierarchy_iterator.cc intern/usd_light_convert.cc + intern/usd_skel_convert.cc intern/usd_reader_camera.cc intern/usd_reader_curve.cc @@ -107,6 +108,7 @@ set(SRC intern/usd_exporter_context.h intern/usd_hierarchy_iterator.h intern/usd_light_convert.h + intern/usd_skel_convert.h intern/usd_reader_camera.h intern/usd_reader_curve.h diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 329f2a7bd03..7042756a79d 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -5,6 +5,7 @@ #include "usd_reader_mesh.h" #include "usd_reader_material.h" +#include "usd_skel_convert.h" #include "BKE_customdata.h" #include "BKE_main.h" @@ -272,6 +273,10 @@ void USDMeshReader::read_object_data(Main *bmain, const double motionSampleTime) } } + if (import_params_.import_blendshapes) { +import_blendshapes(bmain, object_, prim_); + } + USDXformReader::read_object_data(bmain, motionSampleTime); } diff --git a/source/blender/io/usd/intern/usd_skel_convert.cc b/source/blender/io/usd/intern/usd_skel_convert.cc new file mode 100644 index 000..41df30f3f28 --- /dev/null +++ b/source/b
[Bf-blender-cvs] [b665ae266d9] universal-scene-description: USD export armatures with shapekeys WIP.
Commit: b665ae266d9332cec36cf35728a179719080ff9b Author: Michael Kowalski Date: Sun Aug 7 14:07:07 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBb665ae266d9332cec36cf35728a179719080ff9b USD export armatures with shapekeys WIP. Extended USDSkinnedMeshWriter to support exporting blendshapes. === M source/blender/io/usd/intern/usd_hierarchy_iterator.cc M source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc M source/blender/io/usd/intern/usd_writer_blendshape_mesh.h M source/blender/io/usd/intern/usd_writer_mesh.cc M source/blender/io/usd/intern/usd_writer_mesh.h M source/blender/io/usd/intern/usd_writer_skinned_mesh.cc M source/blender/io/usd/intern/usd_writer_skinned_mesh.h === diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc index 5dcd42ace2b..de1b22de148 100644 --- a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc +++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc @@ -136,7 +136,7 @@ AbstractHierarchyWriter *USDHierarchyIterator::create_data_writer(const Hierarch data_writer = new USDSkinnedMeshWriter(usd_export_context); } else if (usd_export_context.export_params.export_blendshapes && -is_blendshape_mesh(context->object)) { + is_blendshape_mesh(context->object)) { data_writer = new USDBlendShapeMeshWriter(usd_export_context); } else { diff --git a/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc b/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc index d4dd84c44be..6f6a78f9974 100644 --- a/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc @@ -97,7 +97,6 @@ static void print_blendshape_info(Object *obj) // BKE_keyblock_element_count_from_shape() LISTBASE_FOREACH (KeyBlock *, kb, >block) { printf("%s %f %f\n", kb->name, kb->curval, kb->pos); - } printf("anim pointer %p\n", key->adt); @@ -110,31 +109,34 @@ bool is_blendshape_mesh(Object *obj) return key && key->totkey > 0 && key->type == KEY_RELATIVE; } -USDBlendShapeMeshWriter::USDBlendShapeMeshWriter(const USDExporterContext ) : USDMeshWriter(ctx) +USDBlendShapeMeshWriter::USDBlendShapeMeshWriter(const USDExporterContext ) +: USDMeshWriter(ctx) { } void USDBlendShapeMeshWriter::do_write(HierarchyContext ) { if (!this->frame_has_been_written_) { -/* Even though this writer is potentially animated - * because it may have animating blendshape weights, - * the mesh is never animated. Setting the is_animated_ - * varialbe to false before writing the mesh prevents - * unwanted time samples for mesh properties from being - * written. Hopefully, there could be nicer way to do this. */ -bool prev_is_animated = is_animated_; -is_animated_ = false; -try { - USDGenericMeshWriter::do_write(context); - is_animated_ = prev_is_animated; -} -catch (...) { - is_animated_ = prev_is_animated; - throw; -} +USDGenericMeshWriter::do_write(context); } + write_blendshape(context); +} + +bool USDBlendShapeMeshWriter::is_supported(const HierarchyContext *context) const +{ + return is_blendshape_mesh(context->object) && USDGenericMeshWriter::is_supported(context); +} + +bool USDBlendShapeMeshWriter::check_is_animated(const HierarchyContext ) const +{ + const Key *key = get_shape_key(context.object); + + return key && key->totkey > 0 && key->adt != nullptr; +} + +void USDBlendShapeMeshWriter::write_blendshape(HierarchyContext ) const +{ /* A blendshape writer might be created even if * there are no blendshapes, so check that blendshapes * exist before continuting. */ @@ -142,17 +144,6 @@ void USDBlendShapeMeshWriter::do_write(HierarchyContext ) return; } - pxr::UsdStageRefPtr stage = usd_export_context_.stage; - pxr::UsdTimeCode timecode = get_export_time_code(); - - pxr::UsdPrim mesh_prim = stage->GetPrimAtPath(usd_export_context_.usd_path); - - if (!mesh_prim.IsValid()) { -printf("WARNING: couldn't get valid mesh prim for blendshape mesh %s\n", - this->usd_export_context_.usd_path.GetString().c_str()); -return; - } - pxr::UsdSkelSkeleton skel = get_skeleton(context); if (!skel) { @@ -163,7 +154,22 @@ void USDBlendShapeMeshWriter::do_write(HierarchyContext ) const Key *key = get_shape_key(context.object); + if (!key) { +printf("WARNING: couldn't get shape key for blendshape mesh prim %s\n", + this->usd_export_context_.usd_path.GetString()
[Bf-blender-cvs] [4655ddf3a2b] master: T90535: import UDIM textures from USD
Commit: 4655ddf3a2b7fee669f7d01f6f70d5f3711205c6 Author: Michael Kowalski Date: Thu Aug 4 11:30:48 2022 -0400 Branches: master https://developer.blender.org/rB4655ddf3a2b7fee669f7d01f6f70d5f3711205c6 T90535: import UDIM textures from USD Added logic to the USD Preview Surface importer to convert UDIM textures. Reviewed by: Sybren and Jesse Differential Revision: https://developer.blender.org/D15379 === 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 8feceee55ed..f59b8be147e 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -9,8 +9,11 @@ #include "BKE_node.h" #include "BKE_node_tree_update.h" +#include "BLI_fileops.h" #include "BLI_math_vector.h" +#include "BLI_path_util.h" #include "BLI_string.h" +#include "BLI_vector.hh" #include "DNA_material_types.h" @@ -94,6 +97,60 @@ static void link_nodes( nodeAddLink(ntree, source, source_socket, dest, dest_socket); } +/* Returns a layer handle retrieved from the given attribute's property specs. + * Note that the returned handle may be invalid if no layer could be found. */ +static pxr::SdfLayerHandle get_layer_handle(const pxr::UsdAttribute ) +{ + for (auto PropertySpec : attribute.GetPropertyStack(pxr::UsdTimeCode::EarliestTime())) { +if (PropertySpec->HasDefaultValue() || + PropertySpec->GetLayer()->GetNumTimeSamplesForPath(PropertySpec->GetPath()) > 0) { + return PropertySpec->GetLayer(); +} + } + + return pxr::SdfLayerHandle(); +} + +static bool is_udim_path(const std::string ) +{ + return path.find("") != std::string::npos; +} + +/* For the given UDIM path (assumed to contain the UDIM token), returns an array + * containing valid tile indices. */ +static blender::Vector get_udim_tiles(const std::string _path) +{ + char base_udim_path[FILE_MAX]; + BLI_strncpy(base_udim_path, file_path.c_str(), sizeof(base_udim_path)); + + blender::Vector udim_tiles; + + /* Extract the tile numbers from all files on disk. */ + ListBase tiles = {nullptr, nullptr}; + int tile_start, tile_range; + bool result = BKE_image_get_tile_info(base_udim_path, , _start, _range); + if (result) { +LISTBASE_FOREACH (LinkData *, tile, ) { + int tile_number = POINTER_AS_INT(tile->data); + udim_tiles.append(tile_number); +} + } + + BLI_freelistN(); + + return udim_tiles; +} + +/* Add tiles with the given indices to the given image. */ +static void add_udim_tiles(Image *image, const blender::Vector ) +{ + image->source = IMA_SRC_TILED; + + for (int tile_number : indices) { +BKE_image_add_tile(image, tile_number, nullptr); + } +} + /* Returns true if the given shader may have opacity < 1.0, based * on heuristics. */ static bool needs_blend(const pxr::UsdShadeShader _shader) @@ -600,12 +657,32 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader _shader, const pxr::SdfAssetPath _path = file_val.Get(); std::string file_path = asset_path.GetResolvedPath(); + if (file_path.empty()) { +/* No resolved path, so use the asset path (usually + * 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()) { std::cerr << "WARNING: Couldn't resolve image asset '" << asset_path << "' for Texture Image node." << std::endl; return; } + /* If this is a UDIM texture, this will store the + * UDIM tile indices. */ + blender::Vector udim_tiles; + + if (is_udim_path(file_path)) { +udim_tiles = get_udim_tiles(file_path); + } + const char *im_file = file_path.c_str(); Image *image = BKE_image_load_exists(bmain_, im_file); if (!image) { @@ -614,6 +691,10 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader _shader, return; } + if (udim_tiles.size() > 0) { +add_udim_tiles(image, udim_tiles); + } + tex_image->id = >id; /* Set texture color space. ___ 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
[Bf-blender-cvs] [0fade955ddc] master: USD import: Handle material purpose
Commit: 0fade955ddc3b9fd143207d08b568612a2fb16b6 Author: Michael Kowalski Date: Mon Aug 1 12:14:05 2022 -0400 Branches: master https://developer.blender.org/rB0fade955ddc3b9fd143207d08b568612a2fb16b6 USD import: Handle material purpose This is a partial fix for T90535. USD allows binding materials generically as well as for a specific purpose. I.e., purpose may be generic (unspecified) or one of - Full: truest representation of the scene - Preview: lightweight material for preview Curently, only generically bound materials, with unspecified purpose (allPurpose), are imported. This issue is preventing preview materials from being imported in the Alab scene. This patch adds logic to attempt to fall back on importing preview or full materials, in that order, if there is no generic material bound to the mesh. Reviewed by: Sybren Differential Revision: https://developer.blender.org/D15352 === M source/blender/io/usd/intern/usd_reader_mesh.cc === diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 45657525527..f65657b240c 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -64,7 +64,22 @@ static void build_mat_map(const Main *bmain, std::map * static pxr::UsdShadeMaterial compute_bound_material(const pxr::UsdPrim ) { - return pxr::UsdShadeMaterialBindingAPI(prim).ComputeBoundMaterial(); + pxr::UsdShadeMaterialBindingAPI api = pxr::UsdShadeMaterialBindingAPI(prim); + + /* Compute generically bound ('allPurpose') materials. */ + pxr::UsdShadeMaterial mtl = api.ComputeBoundMaterial(); + + /* If no generic material could be resolved, also check for 'preview' and + * 'full' purpose materials as fallbacks. */ + if (!mtl) { +mtl = api.ComputeBoundMaterial(pxr::UsdShadeTokens->preview); + } + + if (!mtl) { +mtl = api.ComputeBoundMaterial(pxr::UsdShadeTokens->full); + } + + return mtl; } /* Returns an existing Blender material that corresponds to the USD ___ 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
[Bf-blender-cvs] [1770d462ccd] universal-scene-description: USD export: fix armature export.
Commit: 1770d462ccd27e7f5c50571ff3584dc580ad5991 Author: Michael Kowalski Date: Wed Jul 27 12:23:21 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB1770d462ccd27e7f5c50571ff3584dc580ad5991 USD export: fix armature export. Fixed a bug that was preventing armature writers from being created, due to a missing break statement, introduced after the latest merge from master. === M source/blender/io/usd/intern/usd_hierarchy_iterator.cc === diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc index 5cb7ac059f4..5dcd42ace2b 100644 --- a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc +++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc @@ -174,6 +174,7 @@ AbstractHierarchyWriter *USDHierarchyIterator::create_data_writer(const Hierarch } else return nullptr; + break; case OB_VOLUME: data_writer = new USDVolumeWriter(usd_export_context); break; ___ 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
[Bf-blender-cvs] [1417bf65254] universal-scene-description: Added missing include to fix linux/mac build.
Commit: 1417bf65254033943922a22929657546e3ab17dd Author: Michael Kowalski Date: Tue Jul 26 22:19:35 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB1417bf65254033943922a22929657546e3ab17dd Added missing include to fix linux/mac build. === M source/blender/io/usd/intern/usd_exporter_context.h === diff --git a/source/blender/io/usd/intern/usd_exporter_context.h b/source/blender/io/usd/intern/usd_exporter_context.h index 97d10b44467..7acac1b2dd1 100644 --- a/source/blender/io/usd/intern/usd_exporter_context.h +++ b/source/blender/io/usd/intern/usd_exporter_context.h @@ -6,6 +6,7 @@ #include #include +#include #include struct Depsgraph; ___ 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
[Bf-blender-cvs] [df1edf2934f] universal-scene-description: Added missing include.
Commit: df1edf2934ffca91b1a677529d455eff0f57f4b6 Author: Michael Kowalski Date: Tue Jul 26 21:48:58 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBdf1edf2934ffca91b1a677529d455eff0f57f4b6 Added missing include. To fix linux/mac build errors. === M source/blender/io/usd/intern/usd_exporter_context.h === diff --git a/source/blender/io/usd/intern/usd_exporter_context.h b/source/blender/io/usd/intern/usd_exporter_context.h index 3324ac86fa8..97d10b44467 100644 --- a/source/blender/io/usd/intern/usd_exporter_context.h +++ b/source/blender/io/usd/intern/usd_exporter_context.h @@ -6,6 +6,7 @@ #include #include +#include struct Depsgraph; struct Main; ___ 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
[Bf-blender-cvs] [fa2de72f868] universal-scene-description: USD export: convert shapekeys to blendshapes.
Commit: fa2de72f868507dda4dc4e6eed6bc573128e9d37 Author: Michael Kowalski Date: Tue Jul 26 21:08:59 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rBfa2de72f868507dda4dc4e6eed6bc573128e9d37 USD export: convert shapekeys to blendshapes. Added option to export shapekeys as UdsSkel blendshapes. Implemented a new USDBlendShapeMeshWriter class to export meshes that have shapekeys defined. Currently, only relative shapekeys are converted to blendshapes. Absolute shapekeys are exported as deformed meshes. The current implementation doesn't handle shapekeys on meshes bound to armatures that are expored as skinned meshes. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/CMakeLists.txt M source/blender/io/usd/intern/usd_exporter_context.h M source/blender/io/usd/intern/usd_hierarchy_iterator.cc A source/blender/io/usd/intern/usd_writer_blendshape_mesh.cc A source/blender/io/usd/intern/usd_writer_blendshape_mesh.h M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index defcdba3a39..1cfb3c1e1cc 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -301,6 +301,8 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op) const bool relative_paths = RNA_boolean_get(op->ptr, "relative_paths"); + const bool export_blendshapes = RNA_boolean_get(op->ptr, "export_blendshapes"); + struct USDExportParams params = {RNA_int_get(op->ptr, "start"), RNA_int_get(op->ptr, "end"), export_animation, @@ -356,7 +358,8 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op) export_armatures, xform_op_mode, fix_skel_root, - overwrite_textures}; + overwrite_textures, + export_blendshapes}; /* Take some defaults from the scene, if not specified explicitly. */ Scene *scene = CTX_data_scene(C); @@ -457,6 +460,7 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op) uiItemR(box, ptr, "export_hair", 0, NULL, ICON_NONE); uiItemR(box, ptr, "export_particles", 0, NULL, ICON_NONE); uiItemR(box, ptr, "export_armatures", 0, NULL, ICON_NONE); + uiItemR(box, ptr, "export_blendshapes", 0, NULL, ICON_NONE); box = uiLayoutBox(layout); uiItemL(box, IFACE_("Stage Options:"), ICON_SCENE_DATA); @@ -657,6 +661,12 @@ void WM_OT_usd_export(struct wmOperatorType *ot) "Armatures (Experimental)", "Export armatures and skinned meshes"); + RNA_def_boolean(ot->srna, + "export_blendshapes", + false, + "Blend Shapes", + "Export shape keys as USD blend shapes"); + RNA_def_boolean(ot->srna, "use_instancing", false, diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt index 836455e9ba9..888b7cd1055 100644 --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@ -87,6 +87,7 @@ set(SRC intern/usd_writer_abstract.cc intern/usd_writer_armature.cc + intern/usd_writer_blendshape_mesh.cc intern/usd_writer_camera.cc intern/usd_writer_curve.cc intern/usd_writer_hair.cc @@ -124,6 +125,7 @@ set(SRC intern/usd_writer_abstract.h intern/usd_writer_armature.h + intern/usd_writer_blendshape_mesh.h intern/usd_writer_camera.h intern/usd_writer_curve.h intern/usd_writer_hair.h diff --git a/source/blender/io/usd/intern/usd_exporter_context.h b/source/blender/io/usd/intern/usd_exporter_context.h index a636d849296..3324ac86fa8 100644 --- a/source/blender/io/usd/intern/usd_exporter_context.h +++ b/source/blender/io/usd/intern/usd_exporter_context.h @@ -21,6 +21,11 @@ struct USDExporterContext { const pxr::SdfPath usd_path; const USDHierarchyIterator *hierarchy_iterator; const USDExportParams _params; + + template T usd_define_or_over(pxr::SdfPath path) const + { +return (export_params.export_as_overs) ? T(stage->OverridePrim(path)) : T::Define(stage, path); + } }; } // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc index 902a294727c..5cb7ac059f4 100644 --- a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc +++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc
[Bf-blender-cvs] [9374a3dbf08] universal-scene-description: Merge branch 'master' into universal-scene-description
Commit: 9374a3dbf08d47786bcf9f2dbbd2d7bf15d5 Author: Michael Kowalski Date: Sun Jul 17 12:23:26 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB9374a3dbf08d47786bcf9f2dbbd2d7bf15d5 Merge branch 'master' into universal-scene-description === === diff --cc source/blender/editors/io/io_usd.c index deab62e,a59cdf60243..defcdba3a39 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@@ -58,79 -57,17 +58,79 @@@ const EnumPropertyItem rna_enum_usd_exp {0, NULL, 0, NULL, NULL}, }; +const EnumPropertyItem rna_enum_usd_import_shaders_mode_items[] = { +{USD_IMPORT_SHADERS_NONE, "NONE", 0, "None", "Don't import USD shaders"}, +{USD_IMPORT_USD_PREVIEW_SURFACE, + "USD_PREVIEW_SURFACE", + 0, + "USD Preview Surface", + "Convert USD Preview Surface shaders to Blender Principled BSDF"}, +{USD_IMPORT_MDL, + "USD MDL", + 0, + "MDL", + "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}, +}; + +const EnumPropertyItem rna_enum_usd_import_shaders_mode_items_no_umm[] = { +{USD_IMPORT_SHADERS_NONE, "NONE", 0, "None", "Don't import USD shaders"}, +{USD_IMPORT_USD_PREVIEW_SURFACE, + "USD_PREVIEW_SURFACE", + 0, + "USD Preview Surface", + "Convert USD Preview Surface shaders to Blender Principled BSDF"}, +{0, NULL, 0, NULL, NULL}, +}; + +const EnumPropertyItem rna_enum_usd_xform_op_mode_items[] = { +{USD_XFORM_OP_SRT, + "SRT", + 0, + "Scale, Rotate, Translate", + "Export scale, rotate, and translate Xform operators"}, +{USD_XFORM_OP_SOT, + "SOT", + 0, + "Scale, Orient, Translate", + "Export scale, orient, and translate Xform operators"}, +{USD_XFORM_OP_MAT, "MAT", 0, "Matrix", "Export matrix operator"}, +{0, NULL, 0, NULL, NULL}, +}; + +const EnumPropertyItem prop_usd_export_global_forward[] = { +{USD_GLOBAL_FORWARD_X, "X", 0, "X Forward", "Global Forward is positive X Axis"}, +{USD_GLOBAL_FORWARD_Y, "Y", 0, "Y Forward", "Global Forward is positive Y Axis"}, +{USD_GLOBAL_FORWARD_Z, "Z", 0, "Z Forward", "Global Forward is positive Z Axis"}, +{USD_GLOBAL_FORWARD_MINUS_X, "-X", 0, "-X Forward", "Global Forward is negative X Axis"}, +{USD_GLOBAL_FORWARD_MINUS_Y, "-Y", 0, "-Y Forward", "Global Forward is negative Y Axis"}, +{USD_GLOBAL_FORWARD_MINUS_Z, "-Z", 0, "-Z Forward", "Global Forward is negative Z Axis"}, +{0, NULL, 0, NULL, NULL}, +}; + +const EnumPropertyItem prop_usd_export_global_up[] = { +{USD_GLOBAL_UP_X, "X", 0, "X Up", "Global UP is positive X Axis"}, +{USD_GLOBAL_UP_Y, "Y", 0, "Y Up", "Global UP is positive Y Axis"}, +{USD_GLOBAL_UP_Z, "Z", 0, "Z Up", "Global UP is positive Z Axis"}, +{USD_GLOBAL_UP_MINUS_X, "-X", 0, "-X Up", "Global UP is negative X Axis"}, +{USD_GLOBAL_UP_MINUS_Y, "-Y", 0, "-Y Up", "Global UP is negative Y Axis"}, +{USD_GLOBAL_UP_MINUS_Z, "-Z", 0, "-Z Up", "Global UP is negative Z Axis"}, +{0, NULL, 0, NULL, NULL}, +}; + const EnumPropertyItem rna_enum_usd_mtl_name_collision_mode_items[] = { - {USD_MTL_NAME_COLLISION_MODIFY, - "MODIFY", + {USD_MTL_NAME_COLLISION_MAKE_UNIQUE, + "MAKE_UNIQUE", 0, - "Modify", - "Create a unique name for the imported material"}, - {USD_MTL_NAME_COLLISION_SKIP, - "SKIP", + "Make Unique", + "Import each USD material as a unique Blender material"}, + {USD_MTL_NAME_COLLISION_REFERENCE_EXISTING, + "REFERENCE_EXISTING", 0, - "Skip", - "Keep the existing material and discard the imported material"}, + "Reference Existing", + "If a material with the same name already exists, reference that instead of importing"}, {0, NULL, 0, NULL, NULL}, }; @@@ -219,296 -123,101 +219,316 @@@ static int wm_usd_export_exec(bContext const bool vi
[Bf-blender-cvs] [0869c6b46db] universal-scene-description: Revert "USD import: temp fix for broken UDIMS."
Commit: 0869c6b46db7811421a4172fd106e5bf89de6dec Author: Michael Kowalski Date: Sat Jul 16 20:46:31 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB0869c6b46db7811421a4172fd106e5bf89de6dec Revert "USD import: temp fix for broken UDIMS." This reverts commit 7aa4b6f9. An alternate fix was applied in the latest master branch. === M source/blender/blenkernel/BKE_image.h M source/blender/blenkernel/intern/image.cc M source/blender/editors/include/ED_image.h M source/blender/editors/space_image/image_ops.c M source/blender/editors/space_image/image_sequence.c === diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 0417f335d11..42d0e66cf49 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -378,11 +378,6 @@ typedef enum { UDIM_TILE_FORMAT_UVTILE = 2 } eUDIM_TILE_FORMAT; -/** - * Checks if the filename portion of the path contains a UDIM token. - */ -bool BKE_image_is_filename_tokenized(char *filepath); - /** * Ensures that `filename` contains a UDIM token if we find a supported format pattern. * \note This must only be the name component (without slashes). diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index 478afcb057c..dfa820519a5 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -2927,7 +2927,6 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal) MEM_freeN(tile); } base_tile->next = nullptr; -base_tile->tile_number = 1001; ima->tiles.last = base_tile; } @@ -3109,12 +3108,7 @@ bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, char filename[FILE_MAXFILE], dirname[FILE_MAXDIR]; BLI_split_dirfile(filepath, dirname, filename, sizeof(dirname), sizeof(filename)); - /* If a tokenized path was provided, allow single-file sequences. Otherwise - * tokenize it here and attempt to find 2 or more files in the sequence. */ - bool allow_single = BKE_image_is_filename_tokenized(filename); - if (!allow_single) { -BKE_image_ensure_tile_token(filename); - } + BKE_image_ensure_tile_token(filename); eUDIM_TILE_FORMAT tile_format; char *udim_pattern = BKE_image_get_tile_strformat(filename, _format); @@ -3148,10 +3142,10 @@ bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, BLI_filelist_free(dirs, dirs_num); MEM_SAFE_FREE(udim_pattern); - /* Ensure that all discovered UDIMs are valid and that there's at least 2 files in total if - * allow_single is false (T97366). */ - bool valid_count = allow_single || max_udim > min_udim; - if (all_valid_udim && min_udim <= IMA_UDIM_MAX && valid_count) { + /* Ensure that all discovered UDIMs are valid and that there's at least 2 files in total. + * Downstream code checks the range value to determine tiled-ness; it's important we match that + * expectation here too (T97366). */ + if (all_valid_udim && min_udim <= IMA_UDIM_MAX && max_udim > min_udim) { BLI_join_dirfile(filepath, FILE_MAX, dirname, filename); *r_tile_start = min_udim; @@ -3323,18 +3317,13 @@ bool BKE_image_fill_tile(struct Image *ima, return false; } -bool BKE_image_is_filename_tokenized(char *filepath) -{ - const char *filename = BLI_path_basename(filepath); - return strstr(filename, "") != nullptr || strstr(filename, "") != nullptr; -} - void BKE_image_ensure_tile_token(char *filename) { BLI_assert_msg(BLI_path_slash_find(filename) == nullptr, "Only the file-name component should be used!"); - if (BKE_image_is_filename_tokenized(filename)) { + /* Is there a '<' character in the filename? Assume tokens already present. */ + if (strstr(filename, "<") != nullptr) { return; } diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index 774115fa188..f79d3ce205d 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -173,7 +173,6 @@ typedef struct ImageFrameRange { int length; int offset; /* UDIM tiles. */ - bool udims_detected; ListBase udim_tiles; /* Temporary data. */ diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 68d342e2143..aa77aab2283 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -1274,8 +1274,8 @@ static Image *image_open_single(Main *bmain, BKE_image_free_views(ima); } -if (ima->source == IMA
[Bf-blender-cvs] [1d5d49775c7] universal-scene-description: USD import: fix light intensity scaling.
Commit: 1d5d49775c7e9c5890bbbe62cb96efb3368bd3cb Author: Michael Kowalski Date: Tue Jun 14 23:56:43 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB1d5d49775c7e9c5890bbbe62cb96efb3368bd3cb USD import: fix light intensity scaling. Updated light intensity calculations on import to preserve values on round trip Blender -> USD -> Blender. === M source/blender/io/usd/intern/usd_reader_light.cc M source/blender/io/usd/intern/usd_reader_stage.cc === diff --git a/source/blender/io/usd/intern/usd_reader_light.cc b/source/blender/io/usd/intern/usd_reader_light.cc index 2fac35735b6..d4699d15bd3 100644 --- a/source/blender/io/usd/intern/usd_reader_light.cc +++ b/source/blender/io/usd/intern/usd_reader_light.cc @@ -279,6 +279,11 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime break; } + const float meters_per_unit = static_cast( + pxr::UsdGeomGetStageMetersPerUnit(prim_.GetStage())); + + const float radius_scale = meters_per_unit * usd_world_scale_; + float intensity; if (get_authored_value(light_api.GetIntensityAttr(), motionSampleTime, ) || prim_.GetAttribute(usdtokens::intensity).Get(, motionSampleTime)) { @@ -286,18 +291,14 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime float intensity_scale = this->import_params_.light_intensity_scale; if (import_params_.convert_light_from_nits) { - /* It's important that we perform the light unit conversion before applying any scaling to - * the light size, so we can use the USD's meters per unit value. */ - const float meters_per_unit = static_cast( - pxr::UsdGeomGetStageMetersPerUnit(prim_.GetStage())); - intensity_scale *= nits_to_energy_scale_factor(blight, meters_per_unit * usd_world_scale_); + intensity_scale *= nits_to_energy_scale_factor(blight, radius_scale); } blight->energy = intensity * intensity_scale; } if ((blight->type == LA_SPOT || blight->type == LA_LOCAL) && import_params_.scale_light_radius) { -blight->area_size *= settings_->scale; +blight->area_size *= radius_scale; } USDXformReader::read_object_data(bmain, motionSampleTime); diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc index 4ba86c822dc..6bd47704945 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.cc +++ b/source/blender/io/usd/intern/usd_reader_stage.cc @@ -77,7 +77,7 @@ USDPrimReader *USDStageReader::create_reader_if_allowed(const pxr::UsdPrim #else if (params_.import_lights && prim.IsA()) { #endif -return new USDLightReader(prim, params_, settings_); +return new USDLightReader(prim, params_, settings_, xf_cache); } if (params_.import_volumes && prim.IsA()) { return new USDVolumeReader(prim, params_, settings_); @@ -116,7 +116,7 @@ USDPrimReader *USDStageReader::create_reader(const pxr::UsdPrim , #else if (prim.IsA()) { #endif -return new USDLightReader(prim, params_, settings_); +return new USDLightReader(prim, params_, settings_, xf_cache); } if (prim.IsA()) { return new USDVolumeReader(prim, params_, settings_); ___ 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
[Bf-blender-cvs] [add1da52ad7] master: Fix T97362: forward slashes in USD texture paths
Commit: add1da52ad783e33e8abb0a790ddc97dd89dab92 Author: Michael Kowalski Date: Fri Jun 10 15:07:45 2022 -0400 Branches: master https://developer.blender.org/rBadd1da52ad783e33e8abb0a790ddc97dd89dab92 Fix T97362: forward slashes in USD texture paths Ensuring that relative paths to textures in exported USDs use forward slash separators, for cross-platform compatibility. === M source/blender/io/usd/intern/usd_writer_material.cc === diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 857896b9330..6862f3835cf 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -590,6 +590,7 @@ static std::string get_tex_image_asset_path(bNode *node, BLI_split_dir_part(stage_path.c_str(), dir_path, FILE_MAX); BLI_path_join(exp_path, FILE_MAX, dir_path, "textures", file_path, nullptr); } +BLI_str_replace_char(exp_path, '\\', '/'); return exp_path; } @@ -608,7 +609,7 @@ static std::string get_tex_image_asset_path(bNode *node, if (!BLI_path_is_rel(rel_path)) { return path; } - +BLI_str_replace_char(rel_path, '\\', '/'); return rel_path + 2; } ___ 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
[Bf-blender-cvs] [f6268f921ab] master: USD import: Handle material name collisions
Commit: f6268f921ab007bf2feb7809aff4cde07c20 Author: Michael Kowalski Date: Fri Jun 10 10:12:41 2022 -0400 Branches: master https://developer.blender.org/rBf6268f921ab007bf2feb7809aff4cde07c20 USD import: Handle material name collisions This is a partial fix for T90535. Added Material Name Collision USD import menu option, to specify the behavior when USD materials in different namespaces have the same name. The Material Name Collision menu options are - Make Unique: Import each USD material as a unique Blender material. - Reference Existing: If a material with the same name already exists, reference that instead of importing. Previously, the default behavior was to always keep the existing material. This was causing an issue in the ALab scene, where dozens of different USD materials all have the same name, usdpreviewsurface1, so that only one instance of these materials would be imported. Reviewed by: Sybren Differential Revision: https://developer.blender.org/D14869 === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/usd/intern/usd_reader_prim.h M source/blender/io/usd/usd.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 45d658d5b25..a59cdf60243 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -57,6 +57,20 @@ const EnumPropertyItem rna_enum_usd_export_evaluation_mode_items[] = { {0, NULL, 0, NULL, NULL}, }; +const EnumPropertyItem rna_enum_usd_mtl_name_collision_mode_items[] = { +{USD_MTL_NAME_COLLISION_MAKE_UNIQUE, + "MAKE_UNIQUE", + 0, + "Make Unique", + "Import each USD material as a unique Blender material"}, +{USD_MTL_NAME_COLLISION_REFERENCE_EXISTING, + "REFERENCE_EXISTING", + 0, + "Reference Existing", + "If a material with the same name already exists, reference that instead of importing"}, +{0, NULL, 0, NULL, NULL}, +}; + /* Stored in the wmOperator's customdata field to indicate it should run as a background job. * This is set when the operator is invoked, and not set when it is only executed. */ enum { AS_BACKGROUND_JOB = 1 }; @@ -371,6 +385,9 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) const float light_intensity_scale = RNA_float_get(op->ptr, "light_intensity_scale"); + const eUSDMtlNameCollisionMode mtl_name_collision_mode = RNA_enum_get(op->ptr, + "mtl_name_collision_mode"); + /* TODO(makowalski): Add support for sequences. */ const bool is_sequence = false; int offset = 0; @@ -409,7 +426,8 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op) .use_instancing = use_instancing, .import_usd_preview = import_usd_preview, .set_material_blend = set_material_blend, - .light_intensity_scale = light_intensity_scale}; + .light_intensity_scale = light_intensity_scale, + .mtl_name_collision_mode = mtl_name_collision_mode}; const bool ok = USD_import(C, filename, , as_background_job); @@ -452,6 +470,7 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op) uiItemR(col, ptr, "relative_path", 0, NULL, ICON_NONE); uiItemR(col, ptr, "create_collection", 0, NULL, ICON_NONE); uiItemR(box, ptr, "light_intensity_scale", 0, NULL, ICON_NONE); + uiItemR(box, ptr, "mtl_name_collision_mode", 0, NULL, ICON_NONE); box = uiLayoutBox(layout); col = uiLayoutColumnWithHeading(box, true, IFACE_("Experimental")); @@ -575,6 +594,14 @@ void WM_OT_usd_import(struct wmOperatorType *ot) "Scale for the intensity of imported lights", 0.0001f, 1000.0f); + + RNA_def_enum( + ot->srna, + "mtl_name_collision_mode", + rna_enum_usd_mtl_name_collision_mode_items, + USD_MTL_NAME_COLLISION_MAKE_UNIQUE, + "Material Name Collision", + "Behavior when the name of an imported material conflicts with an existing material"); } #endif /* WITH_USD */ diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 2c86bfff4da..368d0e1bab9 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -62,11 +62,56 @@ static void build_mat_map(const Main *bmain, std::map * } } +static pxr::UsdShadeMaterial compute_bound_material(con
[Bf-blender-cvs] [9d399488710] universal-scene-description: USD export: ensure packed texture file extension.
Commit: 9d39948871019716db24fc6bb8a87d8f9db5d5f5 Author: Michael Kowalski Date: Mon Jun 6 12:26:02 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB9d39948871019716db24fc6bb8a87d8f9db5d5f5 USD export: ensure packed texture file extension. Updated in-memory texture path generation logic to ensure the path has a valid extension for the image format. Also moved duplicate code for identifying in-memory textures into a common function. === M source/blender/io/usd/intern/usd_writer_material.cc === diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index e416c8f22f3..1cbd014fb42 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -354,17 +354,16 @@ static void create_uvmap_shader(const USDExporterContext _export_context, } } +static bool is_in_memory_texture(Image *ima) +{ + return BKE_image_is_dirty(ima) || ima->source == IMA_SRC_GENERATED || + BKE_image_has_packedfile(ima); +} + /* Generate a file name for an in-memory image that doesn't have a * filepath already defined. */ static std::string get_in_memory_texture_filename(Image *ima) { - bool is_dirty = BKE_image_is_dirty(ima); - bool is_generated = ima->source == IMA_SRC_GENERATED; - bool is_packed = BKE_image_has_packedfile(ima); - if (!(is_generated || is_dirty || is_packed)) { -return ""; - } - /* Determine the correct file extension from the image format. */ ImBuf *imbuf = BKE_image_acquire_ibuf(ima, nullptr, nullptr); if (!imbuf) { @@ -375,8 +374,13 @@ static std::string get_in_memory_texture_filename(Image *ima) BKE_image_format_from_imbuf(, imbuf); char file_name[FILE_MAX]; - /* Use the image name for the file name. */ - strcpy(file_name, ima->id.name + 2); + if (strlen(ima->filepath) > 0) { +BLI_split_file_part(ima->filepath, file_name, FILE_MAX); + } + else { +/* Use the image name for the file name. */ +strcpy(file_name, ima->id.name + 2); + } BKE_image_path_ensure_ext_from_imformat(file_name, ); @@ -2215,16 +2219,13 @@ std::string get_tex_image_asset_path(bNode *node, std::string path; - if (strlen(ima->filepath) > 0) { + if (is_in_memory_texture(ima)) { +path = get_in_memory_texture_filename(ima); + } + else if (strlen(ima->filepath) > 0) { /* Get absolute path. */ path = get_tex_image_asset_path(ima); } - else if (export_params.export_textures) { -/* Image has no filepath, but since we are exporting textures, - * check if this is an in-memory texture for which we can - * generate a file name. */ -path = get_in_memory_texture_filename(ima); - } return get_tex_image_asset_path(path, stage, export_params); } @@ -2407,13 +2408,9 @@ void export_texture(bNode *node, BLI_dir_create_recursive(tex_dir_path); - const bool is_dirty = BKE_image_is_dirty(ima); - const bool is_generated = ima->source == IMA_SRC_GENERATED; - const bool is_packed = BKE_image_has_packedfile(ima); - std::string dest_dir(tex_dir_path); - if (is_generated || is_dirty || is_packed) { + if (is_in_memory_texture(ima)) { export_in_memory_texture(ima, dest_dir, allow_overwrite); } else if (ima->source == IMA_SRC_TILED) { ___ 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
[Bf-blender-cvs] [06022f7891f] universal-scene-description: USD export: Convert uv to st by default.
Commit: 06022f7891f0c3690a90f1c78c16c7c50944e65f Author: Michael Kowalski Date: Sat May 14 18:54:53 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB06022f7891f0c3690a90f1c78c16c7c50944e65f USD export: Convert uv to st by default. Enabling the "Convert uv to st" export option by default. === M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index eae096b2456..deab62e 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -697,7 +697,7 @@ void WM_OT_usd_export(struct wmOperatorType *ot) RNA_def_boolean( ot->srna, "convert_uv_to_st", - false, + true, "Convert uv to st", "Export the active uv map as USD primvar named 'st'"); ___ 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
[Bf-blender-cvs] [7aa4b6f93fd] universal-scene-description: USD import: temp fix for broken UDIMS.
Commit: 7aa4b6f93fdacd4c0d3c5ce5b05d644a785b7ca9 Author: Michael Kowalski Date: Sat May 14 18:12:10 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB7aa4b6f93fdacd4c0d3c5ce5b05d644a785b7ca9 USD import: temp fix for broken UDIMS. Applying patch authored by Jesse Yurkovich to support single file UDIMs, while this code is still under review, to temporarily prevent a regression for those testing USD features. If the patch is rejected or rewritten, it might be necessary to back out this commit or merge it with the latest changes. === M source/blender/blenkernel/BKE_image.h M source/blender/blenkernel/intern/image.cc M source/blender/editors/include/ED_image.h M source/blender/editors/space_image/image_ops.c M source/blender/editors/space_image/image_sequence.c === diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 42d0e66cf49..0417f335d11 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -378,6 +378,11 @@ typedef enum { UDIM_TILE_FORMAT_UVTILE = 2 } eUDIM_TILE_FORMAT; +/** + * Checks if the filename portion of the path contains a UDIM token. + */ +bool BKE_image_is_filename_tokenized(char *filepath); + /** * Ensures that `filename` contains a UDIM token if we find a supported format pattern. * \note This must only be the name component (without slashes). diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index dfa820519a5..478afcb057c 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -2927,6 +2927,7 @@ void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal) MEM_freeN(tile); } base_tile->next = nullptr; +base_tile->tile_number = 1001; ima->tiles.last = base_tile; } @@ -3108,7 +3109,12 @@ bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, char filename[FILE_MAXFILE], dirname[FILE_MAXDIR]; BLI_split_dirfile(filepath, dirname, filename, sizeof(dirname), sizeof(filename)); - BKE_image_ensure_tile_token(filename); + /* If a tokenized path was provided, allow single-file sequences. Otherwise + * tokenize it here and attempt to find 2 or more files in the sequence. */ + bool allow_single = BKE_image_is_filename_tokenized(filename); + if (!allow_single) { +BKE_image_ensure_tile_token(filename); + } eUDIM_TILE_FORMAT tile_format; char *udim_pattern = BKE_image_get_tile_strformat(filename, _format); @@ -3142,10 +3148,10 @@ bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, BLI_filelist_free(dirs, dirs_num); MEM_SAFE_FREE(udim_pattern); - /* Ensure that all discovered UDIMs are valid and that there's at least 2 files in total. - * Downstream code checks the range value to determine tiled-ness; it's important we match that - * expectation here too (T97366). */ - if (all_valid_udim && min_udim <= IMA_UDIM_MAX && max_udim > min_udim) { + /* Ensure that all discovered UDIMs are valid and that there's at least 2 files in total if + * allow_single is false (T97366). */ + bool valid_count = allow_single || max_udim > min_udim; + if (all_valid_udim && min_udim <= IMA_UDIM_MAX && valid_count) { BLI_join_dirfile(filepath, FILE_MAX, dirname, filename); *r_tile_start = min_udim; @@ -3317,13 +3323,18 @@ bool BKE_image_fill_tile(struct Image *ima, return false; } +bool BKE_image_is_filename_tokenized(char *filepath) +{ + const char *filename = BLI_path_basename(filepath); + return strstr(filename, "") != nullptr || strstr(filename, "") != nullptr; +} + void BKE_image_ensure_tile_token(char *filename) { BLI_assert_msg(BLI_path_slash_find(filename) == nullptr, "Only the file-name component should be used!"); - /* Is there a '<' character in the filename? Assume tokens already present. */ - if (strstr(filename, "<") != nullptr) { + if (BKE_image_is_filename_tokenized(filename)) { return; } diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index f79d3ce205d..774115fa188 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -173,6 +173,7 @@ typedef struct ImageFrameRange { int length; int offset; /* UDIM tiles. */ + bool udims_detected; ListBase udim_tiles; /* Temporary data. */ diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index aa77aab2283..68d342e2143 100644 --- a/source/blender/editors/space_image/
[Bf-blender-cvs] [69c2c9de0ff] universal-scene-description: USD import: preview surface fallback.
Commit: 69c2c9de0ff6c68e8e4fdb554ad16eb1ec43af98 Author: Michael Kowalski Date: Sat May 14 16:05:32 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB69c2c9de0ff6c68e8e4fdb554ad16eb1ec43af98 USD import: preview surface fallback. Added logic to fall back on importing USD Preview Surface shaders, if possible, if importing MDL is specified but an MDL couldn't be imported. === 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 835a40db860..1ebd88cfbc4 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -392,12 +392,23 @@ Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial _mater bool has_mdl = false; #ifdef WITH_PYTHON /* Invoke UMM to convert to MDL. */ -umm_import_mdl_material(mtl, usd_material, true /* Verbose */, _mdl); +bool mdl_imported = umm_import_mdl_material(mtl, usd_material, true /* Verbose */, _mdl); #endif -if (!has_mdl && usd_preview) { - /* The material has no MDL shader, so fall back on importing UsdPreviewSuface. */ - std::string message = "Material has no MDL shader " + mtl_name + -", importing USD Preview Surface shaders instead"; +if (!(has_mdl && mdl_imported) && usd_preview) { + /* The material has no MDL shader or we couldn't convert the MDL, + * so fall back on importing UsdPreviewSuface. */ + std::string message; + + if (!has_mdl) { +message += "No MDL shader for material "; + } + else if (!mdl_imported) { +message += "Couldn't import MDL shader for material "; + } + + message += mtl_name; + message += ", importing USD Preview Surface shaders instead"; + WM_reportf(RPT_INFO, message.c_str()); import_usd_preview(mtl, usd_preview); } ___ 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
[Bf-blender-cvs] [900ddd763a5] universal-scene-description: USD import: read all color primvars.
Commit: 900ddd763a5f0b1df7848fc31b490b98ef8aac5e Author: Michael Kowalski Date: Wed May 11 21:37:42 2022 -0400 Branches: universal-scene-description https://developer.blender.org/rB900ddd763a5f0b1df7848fc31b490b98ef8aac5e USD import: read all color primvars. Now converting all color primvars to custom mesh data, if the Color Attributes import option is enabled. Also, now enabling the Color Attributes option by default. === M source/blender/editors/io/io_usd.c M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/usd/intern/usd_reader_mesh.h === diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 684c7c45ef9..eae096b2456 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -1165,7 +1165,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "read_mesh_uvs", true, "UV Coordinates", "Read mesh UV coordinates"); RNA_def_boolean( - ot->srna, "read_mesh_colors", false, "Color Attributes", "Read mesh color attributes"); + ot->srna, "read_mesh_colors", true, "Color Attributes", "Read mesh color attributes"); RNA_def_string(ot->srna, "prim_path_mask", diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 8de320807f8..34b07167483 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -27,6 +27,8 @@ #include "MEM_guardedalloc.h" +#include "WM_api.h" + #include #include #include @@ -438,58 +440,85 @@ void USDMeshReader::read_colors(Mesh *mesh, const double motionSampleTime) return; } - /* Early out if we read the display color before and if this attribute isn't animated. */ - if (primvar_varying_map_.find(usdtokens::displayColor) != primvar_varying_map_.end() && - !primvar_varying_map_.at(usdtokens::displayColor)) { -return; - } + std::vector primvars = mesh_prim_.GetPrimvars(); - pxr::UsdGeomPrimvar color_primvar = mesh_prim_.GetDisplayColorPrimvar(); + /* Convert all color primvars to custom layer data. */ + for (pxr::UsdGeomPrimvar pv : primvars) { - if (!color_primvar.HasValue()) { -return; - } +pxr::SdfValueTypeName type = pv.GetTypeName(); - pxr::TfToken interp = color_primvar.GetInterpolation(); +if (!ELEM(type, + pxr::SdfValueTypeNames->Color3hArray, + pxr::SdfValueTypeNames->Color3fArray, + pxr::SdfValueTypeNames->Color3dArray)) { + continue; +} + +pxr::TfToken name = pv.GetPrimvarName(); + +/* Skip if we read this primvar before and it isn't animated. */ +if (primvar_varying_map_.find(name) != primvar_varying_map_.end() && +!primvar_varying_map_.at(name)) { +continue; +} + +read_colors(mesh, pv, motionSampleTime); + } +} - if (interp == pxr::UsdGeomTokens->varying) { -std::cerr << "WARNING: Unsupported varying interpolation for display colors\n" << std::endl; +void USDMeshReader::read_colors(Mesh *mesh, +pxr::UsdGeomPrimvar _primvar, +double motionSampleTime) +{ + if (!(mesh && color_primvar && color_primvar.HasValue())) { return; } - if (primvar_varying_map_.find(usdtokens::displayColor) == primvar_varying_map_.end()) { + if (primvar_varying_map_.find(color_primvar.GetPrimvarName()) == primvar_varying_map_.end()) { bool might_be_time_varying = color_primvar.ValueMightBeTimeVarying(); -primvar_varying_map_.insert(std::make_pair(usdtokens::displayColor, might_be_time_varying)); +primvar_varying_map_.insert(std::make_pair(color_primvar.GetPrimvarName(), might_be_time_varying)); if (might_be_time_varying) { is_time_varying_ = true; } } - pxr::VtArray display_colors; + pxr::VtArray usd_colors; - if (!color_primvar.ComputeFlattened(_colors, motionSampleTime)) { -std::cerr << "WARNING: Couldn't compute display colors\n" << std::endl; + if (!color_primvar.ComputeFlattened(_colors, motionSampleTime)) { +WM_reportf(RPT_WARNING, + "USD Import: couldn't compute values for color primvar '%s'", + color_primvar.GetName().GetText()); return; } - if ((interp == pxr::UsdGeomTokens->faceVarying && display_colors.size() != mesh->totloop) || - (interp == pxr::UsdGeomTokens->vertex && display_colors.size() != mesh->totvert) || - (interp == pxr::UsdGeomTokens->constant && display_colors.size() != 1)