BLEN-359: Implement updates for instances in viewport #20

Merged
Bogdan Nagirniak merged 20 commits from BLEN-359_1 into hydra-render 2023-04-05 11:47:37 +02:00
2 changed files with 29 additions and 41 deletions
Showing only changes of commit 3251d36305 - Show all commits

View File

@ -1,6 +1,8 @@
/* SPDX-License-Identifier: Apache-2.0 /* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */ * Copyright 2011-2022 Blender Foundation */
#include <bitset>
#include "DEG_depsgraph_query.h" #include "DEG_depsgraph_query.h"
#include "DNA_scene_types.h" #include "DNA_scene_types.h"
@ -22,14 +24,6 @@ BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
{ {
} }
void BlenderSceneDelegate::update_material(Material *material)
{
MaterialData *mat_data = material_data(MaterialData::prim_id(this, material));
if (mat_data) {
mat_data->update();
}
}
void BlenderSceneDelegate::update_world() void BlenderSceneDelegate::update_world()
{ {
Scene *scene = DEG_get_input_scene(depsgraph); Scene *scene = DEG_get_input_scene(depsgraph);
@ -154,7 +148,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
} }
if (!object_data(id)) { if (!object_data(id)) {
add_update_object(object, true, true, true); add_update_object(object);
} }
} }
ITER_END; ITER_END;
@ -193,10 +187,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
} }
} }
void BlenderSceneDelegate::add_update_object(Object *object, void BlenderSceneDelegate::add_update_object(Object *object)
bool geometry,
bool transform,
bool shading)
{ {
pxr::SdfPath id = ObjectData::prim_id(this, object); pxr::SdfPath id = ObjectData::prim_id(this, object);
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
@ -214,7 +205,7 @@ void BlenderSceneDelegate::add_update_instance(DupliObject *dupli)
{ {
pxr::SdfPath id = ObjectData::prim_id(this, dupli->ob); pxr::SdfPath id = ObjectData::prim_id(this, dupli->ob);
if (!object_data(id)) { if (!object_data(id)) {
add_update_object(dupli->ob, true, true, true); add_update_object(dupli->ob);
} }
MeshData *m_data = mesh_data(id); MeshData *m_data = mesh_data(id);
@ -269,7 +260,6 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
bool do_update_collection = false; bool do_update_collection = false;
bool do_update_visibility = false; bool do_update_visibility = false;
bool do_update_world = false; bool do_update_world = false;
bool transform, geometry, shading;
DEGIDIterData data = {0}; DEGIDIterData data = {0};
data.graph = depsgraph; data.graph = depsgraph;
@ -277,11 +267,7 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
ITER_BEGIN ( ITER_BEGIN (
DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) { DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) {
transform = (id->recalc & ID_RECALC_TRANSFORM) != 0; CLOG_INFO(LOG_BSD, 2, "Update: %s [%s]", id->name, std::bitset<32>(id->recalc).to_string().c_str());
shading = (id->recalc & (ID_RECALC_SHADING | ID_RECALC_ANIMATION)) != 0;
geometry = (id->recalc & ID_RECALC_GEOMETRY) != 0;
CLOG_INFO(LOG_BSD, 1, "Update: %s [%d%d%d]", id->name, transform, geometry, shading);
switch (GS(id->name)) { switch (GS(id->name)) {
case ID_OB: { case ID_OB: {
@ -289,39 +275,42 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
if (!ObjectData::supported(object)) { if (!ObjectData::supported(object)) {
break; break;
} }
geometry |= (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) != 0; add_update_object(object);
add_update_object(object, geometry, transform, shading);
} break; } break;
case ID_MA: case ID_MA: {
if (shading) { MaterialData *mat_data = material_data(MaterialData::prim_id(this, (Material *)id));
Material *material = (Material *)id; if (mat_data) {
update_material(material); mat_data->update();
} }
break; } break;
case ID_GR: //case ID_GR:
if (transform && geometry) { // if (id->recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) {
// do_update_collection = true;
// }
// break;
case ID_SCE: {
if (id->recalc & ID_RECALC_BASE_FLAGS) {
do_update_visibility = true;
}
if (id->recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) {
do_update_collection = true; do_update_collection = true;
} }
break; if (id->recalc & ID_RECALC_AUDIO_VOLUME) {
case ID_SCE:
if (!geometry && !transform && !shading) {
Scene *scene = (Scene *)id; Scene *scene = (Scene *)id;
do_update_visibility = true;
if ((scene->world && !world_data) || (!scene->world && world_data)) { if ((scene->world && !world_data) || (!scene->world && world_data)) {
do_update_world = true; do_update_world = true;
} }
} }
break; } break;
case ID_WO: case ID_WO: {
if (shading) { if (id->recalc & ID_RECALC_SHADING) {
do_update_world = true; do_update_world = true;
} }
break; } break;
default: default:
break; break;

View File

@ -61,9 +61,8 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
LightData *light_data(pxr::SdfPath const &id); LightData *light_data(pxr::SdfPath const &id);
MaterialData *material_data(pxr::SdfPath const &id); MaterialData *material_data(pxr::SdfPath const &id);
void add_update_object(Object *object, bool geometry, bool transform, bool shading); void add_update_object(Object *object);
void add_update_instance(DupliObject *dupli); void add_update_instance(DupliObject *dupli);
void update_material(Material *material);
void update_world(); void update_world();
void update_collection(bool remove, bool visibility); void update_collection(bool remove, bool visibility);