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 25 deletions
Showing only changes of commit e04a3c6340 - Show all commits

View File

@ -48,30 +48,17 @@ SdfPath InstancerData::prim_id(BlenderSceneDelegate *scene_delegate, Object *obj
InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *object)
: MeshData(scene_delegate, object), parent_obj(object)
{
id = nullptr;
p_id = prim_id(scene_delegate, object);
instancer_id = p_id.AppendElementString("Instancer");
CLOG_INFO(LOG_BSD, 2, "%s, instancer_id=%s", id->name, instancer_id.GetText());
id = nullptr;
CLOG_INFO(LOG_BSD, 2, "%s, instancer_id=%s", ((ID *)parent_obj)->name, instancer_id.GetText());
}
void InstancerData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name);
id = nullptr;
transforms.clear();
ListBase *lb = object_duplilist(scene_delegate->depsgraph, scene_delegate->scene, parent_obj);
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
if (!id) {
/* TODO: We create instances only for object in first dupli.
Instances should be created for all objects */
id = (ID *)dupli->ob;
}
transforms.push_back(gf_matrix_from_transform(dupli->mat));
CLOG_INFO(LOG_BSD, 2, "Instance %s (%s) %d", id->name, ((ID *)dupli->ob)->name, dupli->random_id);
}
free_object_duplilist(lb);
set_instances();
MeshData::init();
}
@ -126,6 +113,27 @@ bool InstancerData::is_base(Object *object) const
return (ID *)object == id;
}
bool InstancerData::set_instances()
{
ID *prev_id = id;
id = nullptr;
transforms.clear();
ListBase *lb = object_duplilist(scene_delegate->depsgraph, scene_delegate->scene, parent_obj);
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
if (!id) {
/* TODO: We create instances only for object in first dupli.
Instances should be created for all objects */
id = (ID *)dupli->ob;
}
transforms.push_back(gf_matrix_from_transform(dupli->mat));
CLOG_INFO(
LOG_BSD, 2, "Instance %s (%s) %d", id->name, ((ID *)dupli->ob)->name, dupli->random_id);
}
free_object_duplilist(lb);
return id != prev_id;
}
void InstancerData::insert()
{
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name);
@ -166,16 +174,10 @@ void InstancerData::update()
if ((recalc & ID_RECALC_GEOMETRY) || (((ID *)parent_obj->data)->recalc & ID_RECALC_GEOMETRY)) {
init();
bits = pxr::HdChangeTracker::AllDirty;
bits |= pxr::HdChangeTracker::AllDirty;
}
else if (recalc & ID_RECALC_TRANSFORM) {
transforms.clear();
ListBase *lb = object_duplilist(scene_delegate->depsgraph, scene_delegate->scene, parent_obj);
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
transforms.push_back(gf_matrix_from_transform(dupli->mat));
}
free_object_duplilist(lb);
else if (recalc & ID_RECALC_TRANSFORM || id->recalc & ID_RECALC_TRANSFORM) {
set_instances();
bits |= pxr::HdChangeTracker::DirtyTransform;
}
if (bits != pxr::HdChangeTracker::Clean) {

View File

@ -35,6 +35,8 @@ class InstancerData : public MeshData {
private:
Object *parent_obj;
pxr::VtMatrix4dArray transforms;
bool set_instances();
};
} // namespace blender::render::hydra