forked from blender/blender
Implement Viewport render with material preview #56
@ -205,11 +205,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
||||
check_updates();
|
||||
}
|
||||
else {
|
||||
if (view3d) {
|
||||
use_scene_lights_ = V3D_USES_SCENE_LIGHTS(view3d);
|
||||
shading_flag_ = view3d->shading.flag;
|
||||
lookdev_light_ = view3d->shading.lookdev_light;
|
||||
}
|
||||
set_light_shading_settings(view3d);
|
||||
set_world_shading_settings(view3d);
|
||||
add_new_objects();
|
||||
update_world();
|
||||
}
|
||||
@ -429,32 +426,19 @@ void BlenderSceneDelegate::check_updates()
|
||||
bool do_update_visibility = false;
|
||||
bool do_update_world = false;
|
||||
|
||||
if (shading_flag_ != view3d->shading.flag || lookdev_light_ != view3d->shading.lookdev_light) {
|
||||
shading_flag_ = view3d->shading.flag;
|
||||
lookdev_light_ = view3d->shading.lookdev_light;
|
||||
if (set_world_shading_settings(view3d))
|
||||
{
|
||||
do_update_world = true;
|
||||
}
|
||||
|
||||
bool use_scene_lights_changed = false;
|
||||
|
||||
if (use_scene_lights_ != V3D_USES_SCENE_LIGHTS(view3d)) {
|
||||
use_scene_lights_ = V3D_USES_SCENE_LIGHTS(view3d);
|
||||
use_scene_lights_changed = true;
|
||||
}
|
||||
if (use_scene_lights_changed) {
|
||||
if (use_scene_lights_) {
|
||||
if (set_light_shading_settings(view3d)) {
|
||||
if (shading_settings.use_scene_lights) {
|
||||
add_new_objects(true);
|
||||
}
|
||||
else {
|
||||
do_update_collection = true;
|
||||
}
|
||||
}
|
||||
if (LOOK_DEV_STUDIO_LIGHT_ENABLED(view3d) &&
|
||||
(world_data_->rotation != view3d->shading.studiolight_rot_z ||
|
||||
world_data_->intensity != view3d->shading.studiolight_intensity))
|
||||
{
|
||||
do_update_world = true;
|
||||
}
|
||||
|
||||
DEGIDIterData data = {0};
|
||||
data.graph = depsgraph;
|
||||
@ -684,4 +668,38 @@ void BlenderSceneDelegate::update_visibility()
|
||||
ITER_END;
|
||||
}
|
||||
|
||||
bool BlenderSceneDelegate::set_light_shading_settings(View3D const *view3d)
|
||||
{
|
||||
bool ret = false;
|
||||
if (view3d) {
|
||||
if (shading_settings.use_scene_lights != V3D_USES_SCENE_LIGHTS(view3d))
|
||||
{
|
||||
shading_settings.use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool BlenderSceneDelegate::set_world_shading_settings(View3D const *view3d)
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Outdated
Review
```
if (!view3d) {
return false;
}
.....
return !(shading_settings == prev_settings);
```
|
||||
{
|
||||
bool ret = false;
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
simplify by using add
simplify by using add `operator==()` and copy constructor to ShadingSettings
```
ShadingSettings prev_settings(shading_settings);
shading_settings. ....
return shading_settings != prev_settings;
```
|
||||
if (view3d) {
|
||||
if (shading_settings.shading_flag != view3d->shading.flag ||
|
||||
shading_settings.lookdev_light != view3d->shading.lookdev_light ||
|
||||
shading_settings.rotation != view3d->shading.studiolight_rot_z ||
|
||||
shading_settings.intensity != view3d->shading.studiolight_intensity
|
||||
)
|
||||
{
|
||||
shading_settings.shading_flag = view3d->shading.flag;
|
||||
shading_settings.lookdev_light = view3d->shading.lookdev_light;
|
||||
shading_settings.rotation = view3d->shading.studiolight_rot_z;
|
||||
shading_settings.intensity = view3d->shading.studiolight_intensity;
|
||||
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -37,6 +37,14 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
Map<pxr::TfToken, pxr::VtValue> render_tokens;
|
||||
};
|
||||
|
||||
struct ShadingSettings {
|
||||
bool use_scene_lights = false;
|
||||
short shading_flag;
|
||||
std::string lookdev_light;
|
||||
float rotation;
|
||||
float intensity;
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
```
bool use_scene_lights = true;
bool use_scene_world = true;
std::string studiolight_name;
float studiolight_rotation;
floatstudiolight_intensity;
```
|
||||
};
|
||||
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
move implementation to blender_scene_delegate.cc move implementation to blender_scene_delegate.cc
|
||||
BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||
pxr::SdfPath const &delegate_id,
|
||||
Engine *engine);
|
||||
@ -71,6 +79,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
Scene *scene = nullptr;
|
||||
Engine *engine;
|
||||
Settings settings;
|
||||
ShadingSettings shading_settings;
|
||||
|
||||
private:
|
||||
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
||||
@ -93,15 +102,13 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
void add_new_objects(bool only_lights = false);
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Move this new settings to internal Move this new settings to internal `struct ShadingSettings`
|
||||
void remove_unused_objects();
|
||||
void update_visibility();
|
||||
bool set_light_shading_settings(View3D const *view3d);
|
||||
bool set_world_shading_settings(View3D const *view3d);
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
remove parameter remove parameter `view3d`
|
||||
|
||||
ObjectDataMap objects_;
|
||||
MaterialDataMap materials_;
|
||||
InstancerDataMap instancers_;
|
||||
std::unique_ptr<WorldData> world_data_;
|
||||
|
||||
short shading_flag_;
|
||||
std::string lookdev_light_;
|
||||
bool use_scene_lights_ = false;
|
||||
};
|
||||
|
||||
#define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
should be removed should be removed
|
||||
|
@ -44,10 +44,6 @@ void WorldData::init()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
|
||||
if (scene_delegate_->view3d) {
|
||||
rotation = scene_delegate_->view3d->shading.studiolight_rot_z;
|
||||
intensity = scene_delegate_->view3d->shading.studiolight_intensity;
|
||||
}
|
||||
write_transform();
|
||||
|
||||
World *world = (World *)id;
|
||||
|
@ -31,8 +31,6 @@ class WorldData : public IdData {
|
||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||
|
||||
pxr::GfMatrix4d transform;
|
||||
float rotation;
|
||||
float intensity;
|
||||
|
||||
private:
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
move this to move this to `BlenderSceneDelegate::ShadingSettings`
|
||||
void write_transform();
|
||||
|
Loading…
Reference in New Issue
Block a user