forked from blender/blender
Make object visibility and instancing creation to be calculated via depsgraph #57
@ -19,6 +19,8 @@ BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||
Engine *engine)
|
||||
: HdSceneDelegate(parent_index, delegate_id), engine(engine)
|
||||
{
|
||||
instancer_data_ = std::make_unique<InstancerData>(
|
||||
this, nullptr, GetDelegateID().AppendElementString("Instancer"));
|
||||
}
|
||||
|
||||
pxr::HdMeshTopology BlenderSceneDelegate::GetMeshTopology(pxr::SdfPath const &id)
|
||||
@ -205,7 +207,7 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
||||
check_updates();
|
||||
}
|
||||
else {
|
||||
add_new_objects();
|
||||
update_collection();
|
||||
update_world();
|
||||
}
|
||||
}
|
||||
@ -422,7 +424,6 @@ void BlenderSceneDelegate::update_world()
|
||||
void BlenderSceneDelegate::check_updates()
|
||||
{
|
||||
bool do_update_collection = false;
|
||||
bool do_update_visibility = false;
|
||||
bool do_update_world = false;
|
||||
|
||||
DEGIDIterData data = {0};
|
||||
@ -440,14 +441,7 @@ void BlenderSceneDelegate::check_updates()
|
||||
|
||||
switch (GS(id->name)) {
|
||||
case ID_OB: {
|
||||
Object *object = (Object *)id;
|
||||
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);
|
||||
do_update_collection = true;
|
||||
} break;
|
||||
|
||||
case ID_MA: {
|
||||
@ -466,10 +460,9 @@ void BlenderSceneDelegate::check_updates()
|
||||
case ID_SCE: {
|
||||
if (id->recalc & ID_RECALC_COPY_ON_WRITE && !(id->recalc & ID_RECALC_SELECT)) {
|
||||
do_update_collection = true;
|
||||
do_update_visibility = true;
|
||||
}
|
||||
if (id->recalc & ID_RECALC_BASE_FLAGS) {
|
||||
do_update_visibility = true;
|
||||
do_update_collection = true;
|
||||
}
|
||||
if (id->recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) {
|
||||
do_update_collection = true;
|
||||
@ -491,10 +484,7 @@ void BlenderSceneDelegate::check_updates()
|
||||
update_world();
|
||||
}
|
||||
if (do_update_collection) {
|
||||
remove_unused_objects();
|
||||
}
|
||||
if (do_update_visibility) {
|
||||
update_visibility();
|
||||
update_collection();
|
||||
}
|
||||
}
|
||||
|
||||
@ -527,20 +517,19 @@ void BlenderSceneDelegate::add_new_objects()
|
||||
}
|
||||
ITER_END;
|
||||
|
||||
instancer_data_ = std::make_unique<InstancerData>(
|
||||
this, nullptr, GetDelegateID().AppendElementString("Instancer"));
|
||||
instancer_data_->init();
|
||||
instancer_data_->insert();
|
||||
}
|
||||
|
||||
void BlenderSceneDelegate::remove_unused_objects()
|
||||
void BlenderSceneDelegate::update_collection()
|
||||
{
|
||||
/* Get available objects */
|
||||
/* Add or update available objects */
|
||||
Set<std::string> available_objects;
|
||||
|
||||
DEGObjectIterSettings settings = {0};
|
||||
settings.depsgraph = depsgraph;
|
||||
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
|
||||
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
|
||||
DEG_ITER_OBJECT_FLAG_VISIBLE;
|
||||
DEGObjectIterData data = {0};
|
||||
data.settings = &settings;
|
||||
data.graph = settings.depsgraph;
|
||||
@ -553,24 +542,23 @@ void BlenderSceneDelegate::remove_unused_objects()
|
||||
Object *,
|
||||
object)
|
||||
{
|
||||
if (ObjectData::is_supported(object)) {
|
||||
available_objects.add(object_prim_id(object).GetName());
|
||||
if (!ObjectData::is_supported(object)) {
|
||||
continue;
|
||||
}
|
||||
available_objects.add(instancer_prim_id(object).GetName());
|
||||
}
|
||||
ITER_END;
|
||||
available_objects.add(object_prim_id(object).GetName());
|
||||
|
||||
/* Remove unused instancers */
|
||||
instancers_.remove_if([&](auto item) {
|
||||
bool ret = !available_objects.contains(item.key.GetName());
|
||||
if (ret) {
|
||||
item.value->remove();
|
||||
pxr::SdfPath id = object_prim_id(object);
|
||||
ObjectData *obj_data = object_data(id);
|
||||
if (obj_data) {
|
||||
obj_data->update();
|
||||
}
|
||||
else {
|
||||
item.value->check_remove(available_objects);
|
||||
obj_data = objects_.lookup_or_add(id, ObjectData::create(this, object, id)).get();
|
||||
obj_data->init();
|
||||
obj_data->insert();
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
ITER_END;
|
||||
|
||||
/* Remove unused objects */
|
||||
objects_.remove_if([&](auto item) {
|
||||
@ -593,9 +581,7 @@ void BlenderSceneDelegate::remove_unused_objects()
|
||||
c_data->available_materials(available_materials);
|
||||
}
|
||||
}
|
||||
for (auto &val : instancers_.values()) {
|
||||
val->available_materials(available_materials);
|
||||
}
|
||||
instancer_data_->available_materials(available_materials);
|
||||
|
||||
materials_.remove_if([&](auto item) {
|
||||
bool ret = !available_materials.contains(item.key);
|
||||
|
@ -91,7 +91,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
void update_world();
|
||||
void check_updates();
|
||||
void add_new_objects();
|
||||
void remove_unused_objects();
|
||||
void update_collection();
|
||||
void update_visibility();
|
||||
|
||||
ObjectDataMap objects_;
|
||||
|
@ -76,8 +76,9 @@ std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *
|
||||
}
|
||||
else {
|
||||
Main *main = CTX_data_main(context);
|
||||
file_path.reserve(FILE_MAX);
|
||||
BKE_image_user_file_path_ex(main, iuser, image, file_path.data(), false, true);
|
||||
char str[FILE_MAX];
|
||||
BKE_image_user_file_path_ex(main, iuser, image, str, false, true);
|
||||
file_path = str;
|
||||
|
||||
if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) {
|
||||
file_path = cache_image_file(image, context, iuser, true);
|
||||
|
@ -111,19 +111,16 @@ void LightData::remove()
|
||||
|
||||
void LightData::update()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
|
||||
Object *object = (Object *)id;
|
||||
Light *light = (Light *)object->data;
|
||||
if (prim_type(light) != prim_type_) {
|
||||
remove();
|
||||
init();
|
||||
insert();
|
||||
return;
|
||||
}
|
||||
|
||||
pxr::HdDirtyBits bits = pxr::HdLight::Clean;
|
||||
if (id->recalc & ID_RECALC_GEOMETRY || light->id.recalc & ID_RECALC_GEOMETRY) {
|
||||
if (prim_type(light) != prim_type_) {
|
||||
remove();
|
||||
init();
|
||||
insert();
|
||||
return;
|
||||
}
|
||||
init();
|
||||
bits = pxr::HdLight::AllDirty;
|
||||
}
|
||||
@ -133,6 +130,7 @@ void LightData::update()
|
||||
}
|
||||
if (bits != pxr::HdChangeTracker::Clean) {
|
||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits);
|
||||
ID_LOG(1, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,12 +299,15 @@ void MeshData::write_materials()
|
||||
}
|
||||
|
||||
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
|
||||
m.mat_data = scene_delegate_->materials_
|
||||
.lookup_or_add(p_id,
|
||||
std::make_unique<MaterialData>(scene_delegate_, mat, p_id))
|
||||
.get();
|
||||
m.mat_data->init();
|
||||
m.mat_data->insert();
|
||||
m.mat_data = scene_delegate_->material_data(p_id);
|
||||
if (!m.mat_data) {
|
||||
m.mat_data = scene_delegate_->materials_
|
||||
.lookup_or_add(p_id,
|
||||
std::make_unique<MaterialData>(scene_delegate_, mat, p_id))
|
||||
.get();
|
||||
m.mat_data->init();
|
||||
m.mat_data->insert();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,23 +67,11 @@ bool ObjectData::is_supported(Object *object)
|
||||
bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
{
|
||||
eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph);
|
||||
int vis = BKE_object_visibility(object, deg_mode);
|
||||
bool ret = vis & OB_VISIBLE_SELF;
|
||||
bool ret = BKE_object_visibility(object, deg_mode) & OB_VISIBLE_SELF;
|
||||
if (deg_mode == DAG_EVAL_VIEWPORT) {
|
||||
ret &= BKE_object_is_visible_in_viewport(scene_delegate->view3d, object);
|
||||
}
|
||||
else {
|
||||
if (ret) {
|
||||
/* If some of parent object is instancer, then currenct object
|
||||
* is invisible in Final render */
|
||||
for (Object *ob = object->parent; ob != nullptr; ob = ob->parent) {
|
||||
if (ob->transflag & OB_DUPLI) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Note: visibility for final render we are taking from depsgraph */
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user