forked from blender/blender
Implement Viewport render with material preview #56
@ -338,7 +338,9 @@ void BlenderSceneDelegate::update_objects(Object *object)
|
|||||||
if (!ObjectData::is_supported(object)) {
|
if (!ObjectData::is_supported(object)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!V3D_USES_SCENE_LIGHTS(view3d) && object->type == OB_LAMP) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
pxr::SdfPath id = object_prim_id(object);
|
pxr::SdfPath id = object_prim_id(object);
|
||||||
ObjectData *obj_data = object_data(id);
|
ObjectData *obj_data = object_data(id);
|
||||||
if (obj_data) {
|
if (obj_data) {
|
||||||
@ -416,6 +418,36 @@ void BlenderSceneDelegate::update_world()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BlenderSceneDelegate::update_scene_lights() {
|
||||||
|
DEGObjectIterSettings settings = {0};
|
||||||
|
settings.depsgraph = depsgraph;
|
||||||
|
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
|
||||||
|
DEGObjectIterData data = {0};
|
||||||
|
data.settings = &settings;
|
||||||
|
data.graph = settings.depsgraph;
|
||||||
|
data.flag = settings.flags;
|
||||||
|
eEvaluationMode deg_mode = DEG_get_mode(depsgraph);
|
||||||
|
|
||||||
|
ITER_BEGIN (DEG_iterator_objects_begin,
|
||||||
|
DEG_iterator_objects_next,
|
||||||
|
DEG_iterator_objects_end,
|
||||||
|
&data,
|
||||||
|
Object *,
|
||||||
|
object)
|
||||||
|
{
|
||||||
|
if (object->type == OB_LAMP) {
|
||||||
|
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
|
||||||
|
2,
|
||||||
|
"Visibility: %s [%s]",
|
||||||
|
object->id.name,
|
||||||
|
std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str());
|
||||||
|
update_objects(object);
|
||||||
|
update_instancers(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ITER_END;
|
||||||
|
}
|
||||||
|
|
||||||
void BlenderSceneDelegate::check_updates()
|
void BlenderSceneDelegate::check_updates()
|
||||||
{
|
{
|
||||||
bool do_update_collection = false;
|
bool do_update_collection = false;
|
||||||
@ -426,7 +458,20 @@ void BlenderSceneDelegate::check_updates()
|
|||||||
shading_flag_ = view3d->shading.flag;
|
shading_flag_ = view3d->shading.flag;
|
||||||
do_update_world = true;
|
do_update_world = true;
|
||||||
}
|
}
|
||||||
|
bool use_scene_lights_changed = false;
|
||||||
|
auto a = V3D_USES_SCENE_LIGHTS(view3d);
|
||||||
|
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) {
|
||||||
|
update_scene_lights();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
remove_unused_objects();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (LOOK_DEV_STUDIO_LIGHT_ENABLED(view3d) &&
|
if (LOOK_DEV_STUDIO_LIGHT_ENABLED(view3d) &&
|
||||||
(world_data_->rotation != view3d->shading.studiolight_rot_z ||
|
(world_data_->rotation != view3d->shading.studiolight_rot_z ||
|
||||||
world_data_->intensity != view3d->shading.studiolight_intensity))
|
world_data_->intensity != view3d->shading.studiolight_intensity))
|
||||||
@ -578,6 +623,9 @@ void BlenderSceneDelegate::remove_unused_objects()
|
|||||||
/* Remove unused objects */
|
/* Remove unused objects */
|
||||||
objects_.remove_if([&](auto item) {
|
objects_.remove_if([&](auto item) {
|
||||||
bool ret = !available_objects.contains(item.key.GetName());
|
bool ret = !available_objects.contains(item.key.GetName());
|
||||||
|
if (!V3D_USES_SCENE_LIGHTS(view3d) && ((Object *)item.value->id)->type == OB_LAMP) {
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
if (ret) {
|
if (ret) {
|
||||||
item.value->remove();
|
item.value->remove();
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
void update_objects(Object *object);
|
void update_objects(Object *object);
|
||||||
void update_instancers(Object *object);
|
void update_instancers(Object *object);
|
||||||
void update_world();
|
void update_world();
|
||||||
|
void update_scene_lights();
|
||||||
void check_updates();
|
void check_updates();
|
||||||
void add_new_objects();
|
void add_new_objects();
|
||||||
void remove_unused_objects();
|
void remove_unused_objects();
|
||||||
@ -100,6 +101,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
std::unique_ptr<WorldData> world_data_;
|
std::unique_ptr<WorldData> world_data_;
|
||||||
|
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
|
|||||||
short shading_flag_;
|
short shading_flag_;
|
||||||
|
bool use_scene_lights = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
remove parameter remove parameter `view3d`
|
|||||||
#define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \
|
#define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \
|
||||||
|
@ -67,24 +67,23 @@ static std::string cache_image_file(Image *image,
|
|||||||
|
|
||||||
std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser)
|
std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser)
|
||||||
{
|
{
|
||||||
std::string file_path;
|
char file_path[FILE_MAX];
|
||||||
if (image->source == IMA_SRC_GENERATED) {
|
if (image->source == IMA_SRC_GENERATED) {
|
||||||
file_path = cache_image_file(image, context, iuser, false);
|
strcpy(file_path, cache_image_file(image, context, iuser, false).c_str());
|
||||||
}
|
}
|
||||||
else if (BKE_image_has_packedfile(image)) {
|
else if (BKE_image_has_packedfile(image)) {
|
||||||
file_path = cache_image_file(image, context, iuser, true);
|
strcpy(file_path, cache_image_file(image, context, iuser, true).c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Main *main = CTX_data_main(context);
|
Main *main = CTX_data_main(context);
|
||||||
file_path.reserve(FILE_MAX);
|
BKE_image_user_file_path_ex(main, iuser, image, file_path, false, true);
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Revert changes in this function and add
Revert changes in this function and add
```
char str[FILE_MAX];
BKE_image_user_file_path_ex(main, iuser, image, str, false, true);
file_path = str;
```
|
|||||||
BKE_image_user_file_path_ex(main, iuser, image, file_path.data(), false, true);
|
|
||||||
|
|
||||||
if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) {
|
if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) {
|
||||||
file_path = cache_image_file(image, context, iuser, true);
|
strcpy(file_path, cache_image_file(image, context, iuser, true).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str());
|
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path);
|
||||||
return file_path;
|
return file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user
Move this new settings to internal
struct ShadingSettings