forked from blender/blender
Added back set_sync_settings #86
@ -32,6 +32,12 @@ class CustomHydraRenderEngine(bpy.types.HydraRenderEngine):
|
|||||||
'aovToken:Depth': "depth",
|
'aovToken:Depth': "depth",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Settings used by the synchronization process.
|
||||||
|
def get_sync_settings(self, engine_type):
|
||||||
|
return {
|
||||||
|
'lightToken:object:visibility:camera': False,
|
||||||
|
}
|
||||||
|
|
||||||
# RenderEngine methods for update, render and draw are implemented in
|
# RenderEngine methods for update, render and draw are implemented in
|
||||||
# HydraRenderEngine. Optionally extra work can be done before or after
|
# HydraRenderEngine. Optionally extra work can be done before or after
|
||||||
# by implementing the methods like this.
|
# by implementing the methods like this.
|
||||||
|
@ -1269,6 +1269,13 @@ class HydraRenderEngine(RenderEngine):
|
|||||||
import _bpy_hydra
|
import _bpy_hydra
|
||||||
_bpy_hydra.engine_free(self.engine_ptr)
|
_bpy_hydra.engine_free(self.engine_ptr)
|
||||||
|
|
||||||
|
def get_sync_settings(self, engine_type: str):
|
||||||
|
"""
|
||||||
|
Provide specific settings for Hydra scene delegate. Available settings:
|
||||||
|
"lightToken:<token name>": <token value>
|
||||||
|
"""
|
||||||
|
return {}
|
||||||
|
|
||||||
def get_render_settings(self, engine_type: str):
|
def get_render_settings(self, engine_type: str):
|
||||||
"""
|
"""
|
||||||
Provide render settings for `HdRenderDelegate`.
|
Provide render settings for `HdRenderDelegate`.
|
||||||
@ -1285,6 +1292,9 @@ class HydraRenderEngine(RenderEngine):
|
|||||||
if not self.engine_ptr:
|
if not self.engine_ptr:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
for key, val in self.get_sync_settings(engine_type).items():
|
||||||
|
_bpy_hydra.engine_set_sync_setting(self.engine_ptr, key, val)
|
||||||
|
|
||||||
_bpy_hydra.engine_update(self.engine_ptr, depsgraph, None)
|
_bpy_hydra.engine_update(self.engine_ptr, depsgraph, None)
|
||||||
|
|
||||||
for key, val in self.get_render_settings('PREVIEW' if self.is_preview else 'FINAL').items():
|
for key, val in self.get_render_settings('PREVIEW' if self.is_preview else 'FINAL').items():
|
||||||
@ -1305,6 +1315,9 @@ class HydraRenderEngine(RenderEngine):
|
|||||||
if not self.engine_ptr:
|
if not self.engine_ptr:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
for key, val in self.get_sync_settings('VIEWPORT').items():
|
||||||
|
_bpy_hydra.engine_set_sync_setting(self.engine_ptr, key, val)
|
||||||
|
|
||||||
_bpy_hydra.engine_update(self.engine_ptr, depsgraph, context)
|
_bpy_hydra.engine_update(self.engine_ptr, depsgraph, context)
|
||||||
|
|
||||||
for key, val in self.get_render_settings('VIEWPORT').items():
|
for key, val in self.get_render_settings('VIEWPORT').items():
|
||||||
|
@ -234,6 +234,16 @@ void HydraSceneDelegate::clear()
|
|||||||
view3d = nullptr;
|
view3d = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HydraSceneDelegate::set_sync_setting(const std::string &key, const pxr::VtValue &val)
|
||||||
|
{
|
||||||
|
if (STRPREFIX(key.c_str(), "lightToken:")) {
|
||||||
|
sync_settings.light_tokens.add_overwrite(pxr::TfToken(key.substr(key.find(":") + 1)), val);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
CLOG_WARN(LOG_HYDRA_SCENE, "Unsupported sync setting: %s", key.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pxr::SdfPath HydraSceneDelegate::prim_id(ID *id, const char *prefix) const
|
pxr::SdfPath HydraSceneDelegate::prim_id(ID *id, const char *prefix) const
|
||||||
{
|
{
|
||||||
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
||||||
|
@ -37,6 +37,11 @@ class HydraSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
friend MaterialData; /* has access to objects and instancers */
|
friend MaterialData; /* has access to objects and instancers */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
struct SyncSettings {
|
||||||
|
/* Is used by render addons to provide specific settings for objects.
|
||||||
|
* Currently it is used for lights only */
|
||||||
|
Map<pxr::TfToken, pxr::VtValue> light_tokens;
|
||||||
|
};
|
||||||
struct ShadingSettings {
|
struct ShadingSettings {
|
||||||
bool use_scene_lights = true;
|
bool use_scene_lights = true;
|
||||||
bool use_scene_world = true;
|
bool use_scene_world = true;
|
||||||
@ -51,6 +56,7 @@ class HydraSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
View3D *view3d = nullptr;
|
View3D *view3d = nullptr;
|
||||||
Main *bmain = nullptr;
|
Main *bmain = nullptr;
|
||||||
Scene *scene = nullptr;
|
Scene *scene = nullptr;
|
||||||
|
SyncSettings sync_settings;
|
||||||
ShadingSettings shading_settings;
|
ShadingSettings shading_settings;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -86,6 +92,7 @@ class HydraSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
|
|
||||||
void populate(Depsgraph *depsgraph, View3D *v3d);
|
void populate(Depsgraph *depsgraph, View3D *v3d);
|
||||||
void clear();
|
void clear();
|
||||||
|
void set_sync_setting(const std::string &key, const pxr::VtValue &val);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
||||||
|
@ -140,6 +140,11 @@ pxr::VtValue LightData::get_data(pxr::TfToken const &key) const
|
|||||||
return pxr::VtValue(it->second);
|
return pxr::VtValue(it->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pxr::VtValue *ret_ptr = scene_delegate_->sync_settings.light_tokens.lookup_ptr(key);
|
||||||
|
if (ret_ptr) {
|
||||||
|
return *ret_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
return pxr::VtValue();
|
return pxr::VtValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +108,13 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::set_sync_setting(const std::string &key, const pxr::VtValue &val)
|
||||||
|
{
|
||||||
|
if (hydra_scene_delegate_) {
|
||||||
|
hydra_scene_delegate_->set_sync_setting(key, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::set_render_setting(const std::string &key, const pxr::VtValue &val)
|
void Engine::set_render_setting(const std::string &key, const pxr::VtValue &val)
|
||||||
{
|
{
|
||||||
render_delegate_->SetRenderSetting(pxr::TfToken(key), val);
|
render_delegate_->SetRenderSetting(pxr::TfToken(key), val);
|
||||||
|
@ -58,6 +58,7 @@ class Engine {
|
|||||||
void sync(Depsgraph *depsgraph, bContext *context);
|
void sync(Depsgraph *depsgraph, bContext *context);
|
||||||
virtual void render() = 0;
|
virtual void render() = 0;
|
||||||
|
|
||||||
|
void set_sync_setting(const std::string &key, const pxr::VtValue &val);
|
||||||
virtual void set_render_setting(const std::string &key, const pxr::VtValue &val);
|
virtual void set_render_setting(const std::string &key, const pxr::VtValue &val);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -146,6 +146,22 @@ static pxr::VtValue get_setting_val(PyObject *pyval)
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *engine_set_sync_setting_func(PyObject * /*self*/, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *pyengine, *pyval;
|
||||||
|
char *key;
|
||||||
|
if (!PyArg_ParseTuple(args, "OsO", &pyengine, &key, &pyval)) {
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Engine *engine = static_cast<Engine *>(PyLong_AsVoidPtr(pyengine));
|
||||||
|
|
||||||
|
CLOG_INFO(LOG_HYDRA_RENDER, 3, "Engine %p: %s", engine, key);
|
||||||
|
engine->set_sync_setting(key, get_setting_val(pyval));
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *engine_set_render_setting_func(PyObject * /*self*/, PyObject *args)
|
static PyObject *engine_set_render_setting_func(PyObject * /*self*/, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *pyengine, *pyval;
|
PyObject *pyengine, *pyval;
|
||||||
@ -183,6 +199,7 @@ static PyMethodDef methods[] = {
|
|||||||
{"engine_update", engine_update_func, METH_VARARGS, ""},
|
{"engine_update", engine_update_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_render_setting", engine_set_render_setting_func, METH_VARARGS, ""},
|
{"engine_set_render_setting", engine_set_render_setting_func, METH_VARARGS, ""},
|
||||||
|
|
||||||
{"cache_or_get_image_file", cache_or_get_image_file_func, METH_VARARGS, ""},
|
{"cache_or_get_image_file", cache_or_get_image_file_func, METH_VARARGS, ""},
|
||||||
|
Loading…
Reference in New Issue
Block a user