Add possibility to render USD file for testing purposes #49

Merged
Bogdan Nagirniak merged 4 commits from BLEN-428 into hydra-render 2023-06-02 13:07:31 +02:00
3 changed files with 35 additions and 0 deletions

View File

@ -61,6 +61,15 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context)
scene_delegate_->populate(depsgraph, context); scene_delegate_->populate(depsgraph, context);
} }
void Engine::sync_usd(pxr::UsdStageRefPtr stage)
{
if (!usd_delegate_) {
usd_delegate_ = std::make_unique<pxr::UsdImagingDelegate>(
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) void Engine::set_sync_setting(const std::string &key, const pxr::VtValue &val)
{ {
scene_delegate_->set_setting(key, val); scene_delegate_->set_setting(key, val);

View File

@ -10,6 +10,8 @@
#include <pxr/imaging/hd/pluginRenderDelegateUniqueHandle.h> #include <pxr/imaging/hd/pluginRenderDelegateUniqueHandle.h>
#include <pxr/imaging/hdx/freeCameraSceneDelegate.h> #include <pxr/imaging/hdx/freeCameraSceneDelegate.h>
#include <pxr/imaging/hgi/hgi.h> #include <pxr/imaging/hgi/hgi.h>
#include <pxr/usd/usd/stage.h>
#include <pxr/usdImaging/usdImaging/delegate.h>
#include "RE_engine.h" #include "RE_engine.h"
@ -29,6 +31,7 @@ class Engine {
virtual ~Engine() = default; virtual ~Engine() = default;
void sync(Depsgraph *depsgraph, bContext *context); void sync(Depsgraph *depsgraph, bContext *context);
void sync_usd(pxr::UsdStageRefPtr stage);
virtual void render(Depsgraph *depsgraph) = 0; virtual void render(Depsgraph *depsgraph) = 0;
void set_sync_setting(const std::string &key, const pxr::VtValue &val); void set_sync_setting(const std::string &key, const pxr::VtValue &val);
@ -50,6 +53,7 @@ class Engine {
std::unique_ptr<RenderTaskDelegate> render_task_delegate_; std::unique_ptr<RenderTaskDelegate> render_task_delegate_;
std::unique_ptr<pxr::HdxFreeCameraSceneDelegate> free_camera_delegate_; std::unique_ptr<pxr::HdxFreeCameraSceneDelegate> free_camera_delegate_;
std::unique_ptr<SimpleLightTaskDelegate> simple_light_task_delegate_; std::unique_ptr<SimpleLightTaskDelegate> simple_light_task_delegate_;
std::unique_ptr<pxr::UsdImagingDelegate> usd_delegate_;
std::unique_ptr<pxr::HdEngine> engine_; std::unique_ptr<pxr::HdEngine> engine_;
}; };

View File

@ -3,8 +3,11 @@
#include <Python.h> #include <Python.h>
#include <boost/python/extract.hpp>
#include <pxr/base/plug/plugin.h> #include <pxr/base/plug/plugin.h>
#include <pxr/base/plug/registry.h> #include <pxr/base/plug/registry.h>
#include <pxr/usd/usd/stage.h>
#include <pxr/usdImaging/usdImagingGL/engine.h> #include <pxr/usdImaging/usdImagingGL/engine.h>
#include "BKE_appdir.h" #include "BKE_appdir.h"
@ -157,6 +160,24 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args)
Py_RETURN_NONE; 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<pxr::UsdStageRefPtr> 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) static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args)
{ {
PyObject *pyengine, *pydepsgraph; PyObject *pyengine, *pydepsgraph;
@ -253,6 +274,7 @@ static PyMethodDef methods[] = {
{"engine_create", engine_create_func, METH_VARARGS, ""}, {"engine_create", engine_create_func, METH_VARARGS, ""},
{"engine_free", engine_free_func, METH_VARARGS, ""}, {"engine_free", engine_free_func, METH_VARARGS, ""},
{"engine_sync", engine_sync_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_render", engine_render_func, METH_VARARGS, ""},
{"engine_view_draw", engine_view_draw_func, METH_VARARGS, ""}, {"engine_view_draw", engine_view_draw_func, METH_VARARGS, ""},
{"engine_set_sync_setting", engine_set_sync_setting_func, METH_VARARGS, ""}, {"engine_set_sync_setting", engine_set_sync_setting_func, METH_VARARGS, ""},