forked from blender/blender
Add possibility to render USD file for testing purposes #49
@ -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<pxr::HdxFreeCameraSceneDelegate>(
|
||||
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
|
||||
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this);
|
||||
render_task_delegate_ = std::make_unique<RenderTaskDelegate>(
|
||||
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<BlenderSceneDelegate>(
|
||||
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<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)
|
||||
{
|
||||
scene_delegate_->set_setting(key, val);
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <pxr/imaging/hd/engine.h>
|
||||
#include <pxr/imaging/hd/pluginRenderDelegateUniqueHandle.h>
|
||||
#include <pxr/imaging/hdx/freeCameraSceneDelegate.h>
|
||||
#include <pxr/usdImaging/usdImaging/delegate.h>
|
||||
#include <pxr/usd/usd/stage.h>
|
||||
#include <pxr/imaging/hgi/hgi.h>
|
||||
|
||||
#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<RenderTaskDelegate> render_task_delegate_;
|
||||
std::unique_ptr<pxr::HdxFreeCameraSceneDelegate> free_camera_delegate_;
|
||||
std::unique_ptr<SimpleLightTaskDelegate> simple_light_task_delegate_;
|
||||
std::unique_ptr<pxr::UsdImagingDelegate> usd_delegate_;
|
||||
std::unique_ptr<pxr::HdEngine> engine_;
|
||||
};
|
||||
|
||||
|
@ -3,9 +3,12 @@
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <boost/python/extract.hpp>
|
||||
|
||||
#include <pxr/base/plug/plugin.h>
|
||||
#include <pxr/base/plug/registry.h>
|
||||
#include <pxr/usdImaging/usdImagingGL/engine.h>
|
||||
#include <pxr/usd/usd/stage.h>
|
||||
|
||||
#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<pxr::UsdStageRefPtr> 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<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)
|
||||
{
|
||||
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, ""},
|
||||
|
Loading…
Reference in New Issue
Block a user