From 4d86a22fa085c6516c306f69a6374cf5a74a9b53 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Mon, 29 May 2023 19:23:39 +0300 Subject: [PATCH 1/3] Add possibility to render USD file for testing purposes. Added Engine::sync_usd() + engine_sync_usd_func() in python.py --- source/blender/render/hydra/engine.cc | 15 +++++++++-- source/blender/render/hydra/engine.h | 4 +++ source/blender/render/hydra/python.cc | 38 +++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 10c50c6b248e..888a1ab206f4 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -43,8 +43,6 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) render_index_.reset(pxr::HdRenderIndex::New(render_delegate_.Get(), hd_drivers)); free_camera_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); - scene_delegate_ = std::make_unique( - render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this); render_task_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); if (render_delegate_name == "HdStormRendererPlugin") { @@ -58,9 +56,22 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) void Engine::sync(Depsgraph *depsgraph, bContext *context) { + if (!scene_delegate_) { + scene_delegate_ = std::make_unique( + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this); + } scene_delegate_->populate(depsgraph, context); } +void Engine::sync_usd(pxr::UsdStageRefPtr stage) +{ + if (!usd_delegate_) { + usd_delegate_ = std::make_unique( + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("usd")); + } + usd_delegate_->Populate(stage->GetPseudoRoot()); +} + void Engine::set_sync_setting(const std::string &key, const pxr::VtValue &val) { scene_delegate_->set_setting(key, val); diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 52e7c4f725a6..2755d8123ce0 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include "RE_engine.h" @@ -29,6 +31,7 @@ class Engine { virtual ~Engine() = default; void sync(Depsgraph *depsgraph, bContext *context); + void sync_usd(pxr::UsdStageRefPtr stage); virtual void render(Depsgraph *depsgraph) = 0; void set_sync_setting(const std::string &key, const pxr::VtValue &val); @@ -50,6 +53,7 @@ class Engine { std::unique_ptr render_task_delegate_; std::unique_ptr free_camera_delegate_; std::unique_ptr simple_light_task_delegate_; + std::unique_ptr usd_delegate_; std::unique_ptr engine_; }; diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 335bbd283730..b6e577245257 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -3,9 +3,12 @@ #include +#include + #include #include #include +#include #include "BKE_appdir.h" #include "BLI_fileops.h" @@ -96,6 +99,21 @@ static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args) return ret; } +static PyObject *test_func(PyObject * /*self*/, PyObject *args) +{ + PyObject *pystage; + if (!PyArg_ParseTuple(args, "O", &pystage)) { + Py_RETURN_NONE; + } + + boost::python::extract e(pystage); + pxr::UsdStagePtr stage = e(); + std::string str; + stage->ExportToString(&str); + printf("%s", str.c_str()); + Py_RETURN_NONE; +} + static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) { PyObject *pyengine; @@ -163,6 +181,24 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args) Py_RETURN_NONE; } +static PyObject *engine_sync_usd_func(PyObject * /*self*/, PyObject *args) +{ + PyObject *pyengine, *pystage; + if (!PyArg_ParseTuple(args, "OO", &pyengine, &pystage)) { + Py_RETURN_NONE; + } + + Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); + + boost::python::extract extract(pystage); + pxr::UsdStagePtr stage = extract(); + + engine->sync_usd(stage); + + CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine); + Py_RETURN_NONE; +} + static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args) { PyObject *pyengine, *pydepsgraph; @@ -255,10 +291,12 @@ static PyMethodDef methods[] = { {"init", init_func, METH_VARARGS, ""}, {"register_plugins", register_plugins_func, METH_VARARGS, ""}, {"get_render_plugins", get_render_plugins_func, METH_VARARGS, ""}, + {"test", test_func, METH_VARARGS, ""}, {"engine_create", engine_create_func, METH_VARARGS, ""}, {"engine_free", engine_free_func, METH_VARARGS, ""}, {"engine_sync", engine_sync_func, METH_VARARGS, ""}, + {"engine_sync_usd", engine_sync_usd_func, METH_VARARGS, ""}, {"engine_render", engine_render_func, METH_VARARGS, ""}, {"engine_view_draw", engine_view_draw_func, METH_VARARGS, ""}, {"engine_set_sync_setting", engine_set_sync_setting_func, METH_VARARGS, ""}, -- 2.30.2 From e475738fc3ffe5fd7ebad1c082750707542d386b Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 31 May 2023 19:38:05 +0300 Subject: [PATCH 2/3] Removed test_func + make format --- source/blender/render/hydra/engine.h | 4 ++-- source/blender/render/hydra/python.cc | 18 +----------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 2755d8123ce0..dd3af2dfea29 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -9,9 +9,9 @@ #include #include #include -#include -#include #include +#include +#include #include "RE_engine.h" diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index b6e577245257..716b9dee2ce5 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -7,8 +7,8 @@ #include #include -#include #include +#include #include "BKE_appdir.h" #include "BLI_fileops.h" @@ -99,21 +99,6 @@ static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args) return ret; } -static PyObject *test_func(PyObject * /*self*/, PyObject *args) -{ - PyObject *pystage; - if (!PyArg_ParseTuple(args, "O", &pystage)) { - Py_RETURN_NONE; - } - - boost::python::extract e(pystage); - pxr::UsdStagePtr stage = e(); - std::string str; - stage->ExportToString(&str); - printf("%s", str.c_str()); - Py_RETURN_NONE; -} - static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) { PyObject *pyengine; @@ -291,7 +276,6 @@ static PyMethodDef methods[] = { {"init", init_func, METH_VARARGS, ""}, {"register_plugins", register_plugins_func, METH_VARARGS, ""}, {"get_render_plugins", get_render_plugins_func, METH_VARARGS, ""}, - {"test", test_func, METH_VARARGS, ""}, {"engine_create", engine_create_func, METH_VARARGS, ""}, {"engine_free", engine_free_func, METH_VARARGS, ""}, -- 2.30.2 From 5770b079159611a2fbdfd44b7c3c7d8084e9322c Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Fri, 2 Jun 2023 13:39:01 +0300 Subject: [PATCH 3/3] Fixed crash in RPR delegate: moved scene_delegate creation to Engine constructor back. --- source/blender/render/hydra/engine.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 888a1ab206f4..d4cd901dbdc4 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -43,6 +43,8 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) render_index_.reset(pxr::HdRenderIndex::New(render_delegate_.Get(), hd_drivers)); free_camera_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); + scene_delegate_ = std::make_unique( + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this); render_task_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); if (render_delegate_name == "HdStormRendererPlugin") { @@ -56,10 +58,6 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) void Engine::sync(Depsgraph *depsgraph, bContext *context) { - if (!scene_delegate_) { - scene_delegate_ = std::make_unique( - render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this); - } scene_delegate_->populate(depsgraph, context); } -- 2.30.2