From 7b569f754d67309ac959e351554593825a5ab6ea Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 2 Jun 2023 13:39:24 +0300 Subject: [PATCH 01/14] removed pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); --- source/blender/render/hydra/final_engine.cc | 2 -- source/blender/render/hydra/preview_engine.cc | 1 - source/blender/render/hydra/viewport_engine.cc | 1 - 3 files changed, 4 deletions(-) diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index bdbade2ebb70..605efa1b71b0 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -21,7 +21,6 @@ void FinalEngine::render(Depsgraph *depsgraph) { /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ - pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine_->Execute(render_index_.get(), &tasks_); } @@ -143,7 +142,6 @@ void FinalEngineGL::render(Depsgraph *depsgraph) { /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ - pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine_->Execute(render_index_.get(), &tasks_); } diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 955147f497fd..5bd8dd244eb5 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -11,7 +11,6 @@ void PreviewEngine::render(Depsgraph *depsgraph) { /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ - pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine_->Execute(render_index_.get(), &tasks_); } diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index e666e181cc03..14e68ad5fe38 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -255,7 +255,6 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) { /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ - pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine_->Execute(render_index_.get(), &tasks); if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) { -- 2.30.2 From d2e8ff041f35ef1081f581d8c3d2cd455017bd11 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 2 Jun 2023 15:01:24 +0300 Subject: [PATCH 02/14] removed ret --- .../render/hydra/scene_delegate/curves.cc | 9 +++---- .../render/hydra/scene_delegate/instancer.cc | 5 ++-- .../render/hydra/scene_delegate/light.cc | 27 +++++++------------ .../render/hydra/scene_delegate/material.cc | 9 +++---- .../render/hydra/scene_delegate/mesh.cc | 9 +++---- .../render/hydra/scene_delegate/world.cc | 5 ++-- 6 files changed, 26 insertions(+), 38 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/curves.cc b/source/blender/render/hydra/scene_delegate/curves.cc index 7b13c093d7e3..32796afc48d5 100644 --- a/source/blender/render/hydra/scene_delegate/curves.cc +++ b/source/blender/render/hydra/scene_delegate/curves.cc @@ -69,17 +69,16 @@ void CurvesData::update() pxr::VtValue CurvesData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const { - pxr::VtValue ret; if (key == pxr::HdTokens->points) { - ret = vertices_; + return pxr::VtValue(vertices_); } else if (key == pxr::HdPrimvarRoleTokens->textureCoordinate) { - ret = uvs_; + return pxr::VtValue(uvs_); } else if (key == pxr::HdTokens->widths) { - ret = widths_; + return pxr::VtValue(widths_); } - return ret; + return pxr::VtValue(); } bool CurvesData::update_visibility() diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index db4384df1e9a..1966ccebaac0 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -102,11 +102,10 @@ void InstancerData::update() pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const { ID_LOG(3, "%s", key.GetText()); - pxr::VtValue ret; if (key == pxr::HdInstancerTokens->instanceTransform) { - ret = mesh_transforms_; + return pxr::VtValue(mesh_transforms_); } - return ret; + return pxr::VtValue(); } bool InstancerData::update_visibility() diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index df8a83567c27..f3603a75329f 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -138,23 +138,22 @@ void LightData::update() pxr::VtValue LightData::get_data(pxr::TfToken const &key) const { - pxr::VtValue ret; auto it = data_.find(key); if (it != data_.end()) { - ret = it->second; + return pxr::VtValue(it->second); } else { std::string n = key.GetString(); if (boost::algorithm::contains(n, "object:visibility:")) { if (boost::algorithm::ends_with(n, "camera") || boost::algorithm::ends_with(n, "shadow")) { - ret = false; + return pxr::VtValue(false); } else { - ret = true; + return pxr::VtValue(true); } } } - return ret; + return pxr::VtValue(); } bool LightData::update_visibility() @@ -169,38 +168,32 @@ bool LightData::update_visibility() pxr::TfToken LightData::prim_type(Light *light) { - pxr::TfToken ret; switch (light->type) { case LA_LOCAL: case LA_SPOT: - ret = pxr::HdPrimTypeTokens->sphereLight; - break; + return pxr::TfToken(pxr::HdPrimTypeTokens->sphereLight); case LA_SUN: - ret = pxr::HdPrimTypeTokens->distantLight; - break; + return pxr::TfToken(pxr::HdPrimTypeTokens->distantLight); case LA_AREA: switch (light->area_shape) { case LA_AREA_SQUARE: case LA_AREA_RECT: - ret = pxr::HdPrimTypeTokens->rectLight; - break; + return pxr::TfToken(pxr::HdPrimTypeTokens->rectLight); case LA_AREA_DISK: case LA_AREA_ELLIPSE: - ret = pxr::HdPrimTypeTokens->diskLight; - break; + return pxr::TfToken(pxr::HdPrimTypeTokens->diskLight); default: - ret = pxr::HdPrimTypeTokens->rectLight; + return pxr::TfToken(pxr::HdPrimTypeTokens->rectLight); } break; default: - ret = pxr::HdPrimTypeTokens->sphereLight; + return pxr::TfToken(pxr::HdPrimTypeTokens->sphereLight); } - return ret; } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 827f31660d97..6bb9bb275296 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -74,14 +74,13 @@ void MaterialData::update() pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const { - pxr::VtValue ret; if (key == scene_delegate_->settings.mx_filename_key) { - if (!mtlx_path_.GetResolvedPath().empty()) { - ret = mtlx_path_; - } ID_LOG(3, "%s", key.GetText()); + if (!mtlx_path_.GetResolvedPath().empty()) { + return pxr::VtValue(mtlx_path_); + } } - return ret; + return pxr::VtValue(); } pxr::VtValue MaterialData::get_material_resource() const diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 36f6050dfd71..6630924a94ab 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -86,17 +86,16 @@ void MeshData::update() pxr::VtValue MeshData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const { - pxr::VtValue ret; if (key == pxr::HdTokens->points) { - ret = vertices_; + return pxr::VtValue(vertices_); } else if (key == pxr::HdTokens->normals) { - ret = submesh(id).normals; + return pxr::VtValue(submesh(id).normals); } else if (key == pxr::HdPrimvarRoleTokens->textureCoordinate) { - ret = submesh(id).uvs; + return pxr::VtValue(submesh(id).uvs); } - return ret; + return pxr::VtValue(); } bool MeshData::update_visibility() diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 7b70f8697e4a..728ed7efb4b3 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -131,12 +131,11 @@ void WorldData::update(World *world) pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const { - pxr::VtValue ret; auto it = data_.find(key); if (it != data_.end()) { - ret = it->second; + return pxr::VtValue(it->second); } - return ret; + return pxr::VtValue(); } void WorldData::write_transform() -- 2.30.2 From f474677e5fad3eb18c36781de7b1ceaf9e409177 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 2 Jun 2023 16:16:01 +0300 Subject: [PATCH 03/14] fix widths for curves --- .../blender/render/hydra/scene_delegate/curves.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/curves.cc b/source/blender/render/hydra/scene_delegate/curves.cc index 32796afc48d5..8bb3b5d0c90f 100644 --- a/source/blender/render/hydra/scene_delegate/curves.cc +++ b/source/blender/render/hydra/scene_delegate/curves.cc @@ -109,6 +109,10 @@ pxr::HdPrimvarDescriptorVector CurvesData::primvar_descriptors( if (!vertices_.empty()) { primvars.emplace_back(pxr::HdTokens->points, interpolation, pxr::HdPrimvarRoleTokens->point); } + if (!widths_.empty()) { + primvars.emplace_back(pxr::HdTokens->widths, interpolation, + pxr::HdPrimvarRoleTokens->none); + } } else if (interpolation == pxr::HdInterpolationFaceVarying) { if (!uvs_.empty()) { @@ -117,11 +121,6 @@ pxr::HdPrimvarDescriptorVector CurvesData::primvar_descriptors( pxr::HdPrimvarRoleTokens->textureCoordinate); } } - else if (interpolation == pxr::HdInterpolationConstant) { - if (!widths_.empty()) { - primvars.emplace_back(pxr::HdTokens->widths, interpolation, pxr::HdPrimvarRoleTokens->none); - } - } return primvars; } @@ -159,14 +158,12 @@ void CurvesData::write_curves(Curves *curves) curve_vertex_counts_.push_back(num_points); /* Set radius similar to Cycles if isn't set */ - widths_.push_back(radii ? radii[i] : 0.01f); - for (int j = 0; j < num_points; j++) { int ind = first_point_index + j; + widths_.push_back(radii ? radii[ind] * 2 : 0.01f); vertices_.push_back(pxr::GfVec3f(positions[ind][0], positions[ind][1], positions[ind][2])); } } - write_uv_maps(curves); } -- 2.30.2 From e614f8a04fdbba7de00903fdf3fe7745450989ea Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 2 Jun 2023 16:31:01 +0300 Subject: [PATCH 04/14] fixed material for curves --- source/blender/render/hydra/scene_delegate/curves.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/curves.cc b/source/blender/render/hydra/scene_delegate/curves.cc index 8bb3b5d0c90f..ba9f7cfd406c 100644 --- a/source/blender/render/hydra/scene_delegate/curves.cc +++ b/source/blender/render/hydra/scene_delegate/curves.cc @@ -185,7 +185,7 @@ void CurvesData::write_material() Object *object = (Object *)id; Material *mat = nullptr; if (BKE_object_material_count_eval(object) > 0) { - mat = BKE_object_material_get_eval(object, object->actcol); + mat = BKE_object_material_get_eval(object, 0); } if (!mat) { -- 2.30.2 From 4fa69acdd9347f822e93c8937d44e1a8b75634e2 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 5 Jun 2023 12:09:11 +0300 Subject: [PATCH 05/14] fix image caching --- .../render/hydra/scene_delegate/image.cc | 21 +++++++++---------- .../render/hydra/scene_delegate/instancer.cc | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index 02f88d66ae84..614c24ec735d 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -21,16 +21,15 @@ static std::string cache_image_file(Image *image, ImageUser *iuser, bool check_exist) { - std::string file_path(FILE_MAX, 0); + char file_path[FILE_MAX]; char file_name[32]; - snprintf(file_name, 32, "img_%016llx.hdr", (uintptr_t)image); - BLI_path_join(file_path.data(), - file_path.capacity(), + snprintf(file_name, sizeof(file_name), "img_%016llx.hdr", (uintptr_t)image); + BLI_path_join(file_path, sizeof(file_path), BKE_tempdir_session(), "hydra_image_cache", file_name); - if (check_exist && BLI_exists(file_path.c_str())) { + if (check_exist && BLI_exists(file_path)) { return file_path; } @@ -38,16 +37,16 @@ static std::string cache_image_file(Image *image, ImageSaveOptions opts; opts.im_format.imtype = R_IMF_IMTYPE_RADHDR; - if (BKE_image_save_options_init(&opts, main, scene_delegate->scene, image, iuser, true, false)) { - STRNCPY(opts.filepath, file_path.c_str()); - ReportList reports; - if (!BKE_image_save(&reports, main, image, iuser, &opts)) { - file_path = ""; + if (BKE_image_save_options_init(&opts, main, scene_delegate->scene, image, iuser, false, false)) + { + STRNCPY(opts.filepath, file_path); + if (!BKE_image_save(nullptr, main, image, iuser, &opts)) { + memset(file_path, 0, sizeof(file_path)); }; } BKE_image_save_options_free(&opts); - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s -> %s", image->id.name, file_path.c_str()); + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s -> %s", image->id.name, file_path); return file_path; } diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 1966ccebaac0..9202432b7a04 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -126,7 +126,7 @@ bool InstancerData::update_visibility() char name[16]; for (auto &l_inst : light_instances_.values()) { for (int i = 0; i < l_inst.count; ++i) { - snprintf(name, 16, "L_%08x", i); + snprintf(name, sizeof(name), "L_%08x", i); change_tracker.MarkRprimDirty(l_inst.data->prim_id.AppendElementString(name), pxr::HdChangeTracker::DirtyVisibility); } -- 2.30.2 From 803d3d8d5b9655f5a0758f02bd818aa37e437a42 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 5 Jun 2023 13:53:46 +0300 Subject: [PATCH 06/14] Added check for Unicode --- source/blender/render/hydra/scene_delegate/material.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 6bb9bb275296..123a0f7bc818 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -2,6 +2,7 @@ * Copyright 2011-2022 Blender Foundation */ #include +#include #include #include @@ -110,7 +111,7 @@ void MaterialData::export_mtlx() std::string path; - if (!PyErr_Occurred()) { + if (!PyErr_Occurred() && PyUnicode_Check(result)) { path = PyUnicode_AsUTF8(result); Py_DECREF(result); } -- 2.30.2 From 45ac760ff17998bfc16b02cfbe09a2a1e5d89de1 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 5 Jun 2023 14:00:42 +0300 Subject: [PATCH 07/14] removed bypass to avoid BKE_object_to_mesh --- .../blender/render/hydra/scene_delegate/mesh.cc | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 6630924a94ab..8f0030267d89 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -26,18 +26,11 @@ void MeshData::init() ID_LOG(2, ""); Object *object = (Object *)id; - if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT && - BLI_listbase_is_empty(&object->modifiers)) - { - write_submeshes((Mesh *)object->data); - } - else { - Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); - if (mesh) { - write_submeshes(mesh); - } - BKE_object_to_mesh_clear(object); + Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); + if (mesh) { + write_submeshes(mesh); } + BKE_object_to_mesh_clear(object); write_transform(); write_materials(); -- 2.30.2 From f3d62f30984b04a80f644ae4600702a000486866 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 5 Jun 2023 17:33:11 +0300 Subject: [PATCH 08/14] fix interpolation for curves --- source/blender/render/hydra/scene_delegate/curves.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/curves.cc b/source/blender/render/hydra/scene_delegate/curves.cc index ba9f7cfd406c..333739d26731 100644 --- a/source/blender/render/hydra/scene_delegate/curves.cc +++ b/source/blender/render/hydra/scene_delegate/curves.cc @@ -114,7 +114,7 @@ pxr::HdPrimvarDescriptorVector CurvesData::primvar_descriptors( pxr::HdPrimvarRoleTokens->none); } } - else if (interpolation == pxr::HdInterpolationFaceVarying) { + else if (interpolation == pxr::HdInterpolationConstant) { if (!uvs_.empty()) { primvars.emplace_back(pxr::HdPrimvarRoleTokens->textureCoordinate, interpolation, -- 2.30.2 From ec7212792f25b35123844effb66335a2a7803c9e Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 6 Jun 2023 15:58:36 +0300 Subject: [PATCH 09/14] fix review comments --- .../render/hydra/scene_delegate/blender_scene_delegate.cc | 6 +++--- source/blender/render/hydra/scene_delegate/curves.cc | 1 + source/blender/render/hydra/scene_delegate/instancer.cc | 8 ++++---- source/blender/render/hydra/scene_delegate/mesh.cc | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index a11d8be990cf..5e305a0f0ee2 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -241,9 +241,9 @@ void BlenderSceneDelegate::set_setting(const std::string &key, const pxr::VtValu pxr::SdfPath BlenderSceneDelegate::prim_id(ID *id, const char *prefix) const { /* Making id of object in form like _ */ - char str[32]; - snprintf(str, 32, "%s_%016llx", prefix, (uintptr_t)id); - return GetDelegateID().AppendElementString(str); + char name[32]; + snprintf(name, sizeof(name), "%s_%016llx", prefix, (uintptr_t)id); + return GetDelegateID().AppendElementString(name); } pxr::SdfPath BlenderSceneDelegate::object_prim_id(Object *object) const diff --git a/source/blender/render/hydra/scene_delegate/curves.cc b/source/blender/render/hydra/scene_delegate/curves.cc index 333739d26731..87b1d0a28a8b 100644 --- a/source/blender/render/hydra/scene_delegate/curves.cc +++ b/source/blender/render/hydra/scene_delegate/curves.cc @@ -184,6 +184,7 @@ void CurvesData::write_material() { Object *object = (Object *)id; Material *mat = nullptr; + /* TODO: Using only first material. Add support for multimaterial. */ if (BKE_object_material_count_eval(object) > 0) { mat = BKE_object_material_get_eval(object, 0); } diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 9202432b7a04..7631ada451f6 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -319,15 +319,15 @@ bool InstancerData::is_instance_visible(Object *object) pxr::SdfPath InstancerData::object_prim_id(Object *object) const { /* Making id of object in form like _ */ - char str[32]; - snprintf(str, 32, "O_%016llx", (uint64_t)object); - return prim_id.AppendElementString(str); + char name[32]; + snprintf(name, sizeof(name), "O_%016llx", (uint64_t)object); + return prim_id.AppendElementString(name); } pxr::SdfPath InstancerData::light_prim_id(LightInstance const &inst, int index) const { char name[16]; - snprintf(name, 16, "L_%08x", index); + snprintf(name, sizeof(name), "L_%08x", index); return inst.data->prim_id.AppendElementString(name); } diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 8f0030267d89..7e478e25de5c 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -186,7 +186,7 @@ pxr::SdfPathVector MeshData::submesh_paths() const pxr::SdfPath MeshData::submesh_prim_id(int index) const { char name[16]; - snprintf(name, 16, "SM_%04x", index); + snprintf(name, sizeof(name), "SM_%04x", index); return prim_id.AppendElementString(name); } -- 2.30.2 From 20add010e178c175d6dffdd89d402ed4711defb5 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 6 Jun 2023 16:00:26 +0300 Subject: [PATCH 10/14] fix review comments --- source/blender/render/hydra/scene_delegate/material.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 123a0f7bc818..0f6d100761d2 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -111,8 +111,10 @@ void MaterialData::export_mtlx() std::string path; - if (!PyErr_Occurred() && PyUnicode_Check(result)) { - path = PyUnicode_AsUTF8(result); + if (!PyErr_Occurred()) { + if (PyUnicode_Check(result)) { + path = PyUnicode_AsUTF8(result); + } Py_DECREF(result); } else { -- 2.30.2 From 16a21ae611f460caf7751ae037785c88e419744d Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 7 Jun 2023 17:20:00 +0300 Subject: [PATCH 11/14] pxr::PlugRegistry::GetInstance().RegisterPlugins --- source/blender/render/hydra/python.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 9ef8f00b3478..56f2914ea3ff 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -20,10 +20,6 @@ namespace blender::render::hydra { static PyObject *init_func(PyObject * /*self*/, PyObject *args) { CLOG_INFO(LOG_RENDER_HYDRA, 1, "Init"); - - pxr::PlugRegistry::GetInstance().RegisterPlugins(std::string(BKE_appdir_program_dir()) + - "/blender.shared/usd"); - Py_RETURN_NONE; } -- 2.30.2 From e2c32ec7e3196bbe228a699b86d8f923ea8c3932 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 8 Jun 2023 11:35:37 +0300 Subject: [PATCH 12/14] removed init and get_render_plugins --- scripts/modules/bpy_hydra.py | 4 +-- source/blender/render/hydra/python.cc | 43 --------------------------- 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/scripts/modules/bpy_hydra.py b/scripts/modules/bpy_hydra.py index 3dcc3207927c..1329c74b344c 100644 --- a/scripts/modules/bpy_hydra.py +++ b/scripts/modules/bpy_hydra.py @@ -38,7 +38,6 @@ __all__ = ( "HydraRenderEngine", "export_mtlx", "register_plugins", - "get_render_plugins", ) import os @@ -48,7 +47,7 @@ from pathlib import Path import bpy import _bpy_hydra -from _bpy_hydra import register_plugins, get_render_plugins +from _bpy_hydra import register_plugins class HydraRenderEngine(bpy.types.RenderEngine): @@ -68,7 +67,6 @@ class HydraRenderEngine(bpy.types.RenderEngine): @classmethod def register(cls): - _bpy_hydra.init() root_folder = "blender.shared" if platform.system() == 'Windows' else "lib" os.environ['PXR_MTLX_STDLIB_SEARCH_PATHS'] = os.pathsep.join([ str(Path(bpy.app.binary_path).parent / f"{root_folder}/materialx/libraries"), diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 56f2914ea3ff..ea3cf9b0a5e9 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -17,12 +17,6 @@ namespace blender::render::hydra { -static PyObject *init_func(PyObject * /*self*/, PyObject *args) -{ - CLOG_INFO(LOG_RENDER_HYDRA, 1, "Init"); - Py_RETURN_NONE; -} - static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args) { PyObject *pyplugin_dirs; @@ -57,41 +51,6 @@ static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args) Py_RETURN_NONE; } -static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args) -{ - pxr::PlugRegistry ®istry = pxr::PlugRegistry::GetInstance(); - pxr::TfTokenVector plugin_ids = pxr::UsdImagingGLEngine::GetRendererPlugins(); - PyObject *ret = PyTuple_New(plugin_ids.size()); - PyObject *val; - for (int i = 0; i < plugin_ids.size(); ++i) { - PyObject *descr = PyDict_New(); - - PyDict_SetItemString(descr, "id", val = PyUnicode_FromString(plugin_ids[i].GetText())); - Py_DECREF(val); - - PyDict_SetItemString( - descr, - "name", - val = PyUnicode_FromString( - pxr::UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str())); - Py_DECREF(val); - - std::string plugin_name = plugin_ids[i]; - plugin_name = plugin_name.substr(0, plugin_name.size() - 6); - plugin_name[0] = tolower(plugin_name[0]); - std::string path = ""; - pxr::PlugPluginPtr plugin = registry.GetPluginWithName(plugin_name); - if (plugin) { - path = plugin->GetPath(); - } - PyDict_SetItemString(descr, "path", val = PyUnicode_FromString(path.c_str())); - Py_DECREF(val); - - PyTuple_SetItem(ret, i, descr); - } - return ret; -} - static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) { PyObject *pyengine; @@ -242,9 +201,7 @@ static PyObject *engine_set_render_setting_func(PyObject * /*self*/, PyObject *a } static PyMethodDef methods[] = { - {"init", init_func, METH_VARARGS, ""}, {"register_plugins", register_plugins_func, METH_VARARGS, ""}, - {"get_render_plugins", get_render_plugins_func, METH_VARARGS, ""}, {"engine_create", engine_create_func, METH_VARARGS, ""}, {"engine_free", engine_free_func, METH_VARARGS, ""}, -- 2.30.2 From b19e1e0646fc953801fed4f432f6f38e9edc24d2 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 8 Jun 2023 11:36:00 +0300 Subject: [PATCH 13/14] make format --- source/blender/render/hydra/scene_delegate/curves.cc | 3 +-- source/blender/render/hydra/scene_delegate/image.cc | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/curves.cc b/source/blender/render/hydra/scene_delegate/curves.cc index 87b1d0a28a8b..a36d4e26f8ea 100644 --- a/source/blender/render/hydra/scene_delegate/curves.cc +++ b/source/blender/render/hydra/scene_delegate/curves.cc @@ -110,8 +110,7 @@ pxr::HdPrimvarDescriptorVector CurvesData::primvar_descriptors( primvars.emplace_back(pxr::HdTokens->points, interpolation, pxr::HdPrimvarRoleTokens->point); } if (!widths_.empty()) { - primvars.emplace_back(pxr::HdTokens->widths, interpolation, - pxr::HdPrimvarRoleTokens->none); + primvars.emplace_back(pxr::HdTokens->widths, interpolation, pxr::HdPrimvarRoleTokens->none); } } else if (interpolation == pxr::HdInterpolationConstant) { diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index 614c24ec735d..ca5cbf615399 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -24,10 +24,8 @@ static std::string cache_image_file(Image *image, char file_path[FILE_MAX]; char file_name[32]; snprintf(file_name, sizeof(file_name), "img_%016llx.hdr", (uintptr_t)image); - BLI_path_join(file_path, sizeof(file_path), - BKE_tempdir_session(), - "hydra_image_cache", - file_name); + BLI_path_join( + file_path, sizeof(file_path), BKE_tempdir_session(), "hydra_image_cache", file_name); if (check_exist && BLI_exists(file_path)) { return file_path; -- 2.30.2 From d8f2587fcba8aff634ae71c7ac3ba050ed0bc414 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 8 Jun 2023 11:47:50 +0300 Subject: [PATCH 14/14] fix after merge --- source/blender/render/hydra/scene_delegate/image.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index 0312e8865fc2..61447978ceaf 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -38,9 +38,12 @@ static std::string cache_image_file(Image *image, if (BKE_image_save_options_init(&opts, main, scene_delegate->scene, image, iuser, false, false)) { STRNCPY(opts.filepath, file_path); - if (!BKE_image_save(nullptr, main, image, iuser, &opts)) { + if (BKE_image_save(nullptr, main, image, iuser, &opts)) { + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path); + } + else { memset(file_path, 0, sizeof(file_path)); - }; + } } BKE_image_save_options_free(&opts); -- 2.30.2