diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 10c50c6b248e..d4cd901dbdc4 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -61,6 +61,15 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context) 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..dd3af2dfea29 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -10,6 +10,8 @@ #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 9ef8f00b3478..0cdddd8a2452 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -3,8 +3,11 @@ #include +#include + #include #include +#include #include #include "BKE_appdir.h" @@ -157,6 +160,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; @@ -253,6 +274,7 @@ static PyMethodDef methods[] = { {"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, ""},