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
9 changed files with 85 additions and 67 deletions
Showing only changes of commit 8336945eaf - Show all commits

View File

@ -219,32 +219,29 @@ void BlenderSceneDelegate::add_update_object(Object *object,
obj_data = object_data(id);
obj_data->update_visibility(view3d);
obj_data->insert();
MeshData *m_data = dynamic_cast<MeshData *>(obj_data);
if (m_data) {
set_material(*m_data);
}
return;
}
if (geometry) {
objects[id] = ObjectData::create(this, object);
obj_data = object_data(id);
obj_data->update_visibility(view3d);
MeshData *m_data = dynamic_cast<MeshData *>(obj_data);
if (m_data) {
set_material(*m_data);
}
obj_data->update(IdData::DirtyBits::ALL_DIRTY);
return;
}
//if (geometry) {
// objects[id] = ObjectData::create(this, object);
// obj_data = object_data(id);
// obj_data->update_visibility(view3d);
// MeshData *m_data = dynamic_cast<MeshData *>(obj_data);
// if (m_data) {
// set_material(*m_data);
// }
// obj_data->update(IdData::DirtyBits::ALL_DIRTY);
// return;
//}
if (transform) {
obj_data->update(IdData::DirtyBits::DIRTY_TRANSFORM);
}
//if (transform) {
// obj_data->update(IdData::DirtyBits::DIRTY_TRANSFORM);
//}
if (shading) {
obj_data->update(IdData::DirtyBits::DIRTY_MATERIAL);
}
//if (shading) {
// obj_data->update(IdData::DirtyBits::DIRTY_MATERIAL);
//}
}
void BlenderSceneDelegate::add_update_instance(DupliObject *dupli)

View File

@ -18,6 +18,7 @@ namespace blender::render::hydra {
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
: ObjectData(scene_delegate, object)
{
CLOG_INFO(LOG_BSD, 2, "%s id=%s", id->name, p_id.GetText());
}
void LightData::init()
@ -139,38 +140,44 @@ pxr::VtValue LightData::get_data(pxr::TfToken const &key) const
return ret;
}
bool LightData::update_visibility(View3D *view3d)
{
bool ret = ObjectData::update_visibility(view3d);
if (ret) {
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id,
pxr::HdLight::DirtyParams);
}
return ret;
}
void LightData::insert()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().InsertSprim(prim_type(), scene_delegate, p_id);
CLOG_INFO(LOG_BSD, 2, "Add: %s id=%s", name().c_str(), p_id.GetString().c_str());
}
void LightData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().RemoveSprim(prim_type(), p_id);
CLOG_INFO(LOG_BSD, 2, "Remove: %s", name().c_str());
}
void LightData::update(DirtyBits dirty_bits)
{
/* TODO: prim_type was changed we have to do remove..add light */
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
pxr::HdDirtyBits bits = pxr::HdLight::Clean;
switch (dirty_bits) {
case DirtyBits::DIRTY_TRANSFORM:
bits = pxr::HdLight::DirtyTransform;
break;
case DirtyBits::DIRTY_VISIBILITY:
bits = pxr::HdLight::DirtyParams;
break;
case DirtyBits::ALL_DIRTY:
if (id->recalc & ID_RECALC_GEOMETRY) {
data.clear();
init();
bits = pxr::HdLight::AllDirty;
break;
default:
break;
}
else if (id->recalc & ID_RECALC_TRANSFORM) {
bits = pxr::HdLight::DirtyTransform;
}
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits);
CLOG_INFO(LOG_BSD, 2, "Update: [%d] %s", dirty_bits, name().c_str());
}
} // namespace blender::render::hydra

View File

@ -20,6 +20,7 @@ class LightData : public ObjectData {
void remove() override;
void update(DirtyBits dirty_bits) override;
pxr::VtValue get_data(pxr::TfToken const &key) const override;
bool update_visibility(View3D *view3d) override;
private:
std::map<pxr::TfToken, pxr::VtValue> data;

View File

@ -41,7 +41,7 @@ MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *mater
: IdData(scene_delegate, (ID *)material)
{
p_id = prim_id(scene_delegate, material);
CLOG_INFO(LOG_BSD, 2, "%s - %s", id->name, p_id.GetText());
CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id->name, p_id.GetText());
}
void MaterialData::init()

View File

@ -18,6 +18,7 @@ namespace blender::render::hydra {
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object)
: ObjectData(scene_delegate, object)
{
CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id->name, p_id.GetText());
}
pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const
@ -38,6 +39,16 @@ pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const
return ret;
}
bool MeshData::update_visibility(View3D *view3d)
{
bool ret = ObjectData::update_visibility(view3d);
if (ret) {
scene_delegate->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
p_id, pxr::HdChangeTracker::DirtyVisibility);
}
return ret;
}
Material *MeshData::material()
{
Object *object = (Object *)id;
@ -205,6 +216,8 @@ void MeshData::init()
}
BKE_object_to_mesh_clear(object);
}
scene_delegate->set_material(*this);
}
void MeshData::insert()
@ -213,8 +226,8 @@ void MeshData::insert()
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().InsertRprim(pxr::HdPrimTypeTokens->mesh, scene_delegate, p_id);
CLOG_INFO(LOG_BSD, 2, "Add: %s id=%s", name().c_str(), p_id.GetString().c_str());
}
void MeshData::remove()
@ -223,12 +236,36 @@ void MeshData::remove()
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().RemoveRprim(p_id);
CLOG_INFO(LOG_BSD, 2, "Remove: %s", name().c_str());
}
void MeshData::update(DirtyBits dirty_bits)
{
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
Object *object = (Object *)id;
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
material_id = pxr::SdfPath::EmptyPath();
instancer_id = pxr::SdfPath::EmptyPath();
face_vertex_counts.clear();
face_vertex_indices.clear();
vertices.clear();
normals.clear();
uvs.clear();
init();
bits = pxr::HdChangeTracker::AllDirty;
}
else {
if (id->recalc & ID_RECALC_SHADING) {
scene_delegate->set_material(*this);
bits |= pxr::HdChangeTracker::DirtyMaterialId;
}
if (id->recalc & ID_RECALC_TRANSFORM) {
bits |= pxr::HdChangeTracker::DirtyTransform;
}
}
if (!scene_delegate->GetRenderIndex().HasRprim(p_id)) {
/* Trying to insert prim */
insert();
@ -240,26 +277,8 @@ void MeshData::update(DirtyBits dirty_bits)
remove();
return;
}
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
switch (dirty_bits) {
case DirtyBits::DIRTY_TRANSFORM:
bits = pxr::HdChangeTracker::DirtyTransform;
break;
case DirtyBits::DIRTY_VISIBILITY:
bits = pxr::HdChangeTracker::DirtyVisibility;
break;
case DirtyBits::DIRTY_MATERIAL:
bits = pxr::HdChangeTracker::DirtyMaterialId;
break;
case DirtyBits::ALL_DIRTY:
bits = pxr::HdChangeTracker::AllDirty;
break;
default:
break;
}
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().GetChangeTracker().MarkRprimDirty(p_id, bits);
CLOG_INFO(LOG_BSD, 2, "Update: [%d] %s", dirty_bits, name().c_str());
}
} // namespace blender::render::hydra

View File

@ -20,8 +20,8 @@ class MeshData : public ObjectData {
void insert() override;
void remove() override;
void update(DirtyBits dirty_bits) override;
pxr::VtValue get_data(pxr::TfToken const &key) const override;
bool update_visibility(View3D *view3d) override;
Material *material();
pxr::HdMeshTopology mesh_topology();

View File

@ -70,11 +70,6 @@ ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object)
p_id = prim_id(scene_delegate, object);
}
int ObjectData::type()
{
return ((Object *)id)->type;
}
pxr::GfMatrix4d ObjectData::transform()
{
return gf_matrix_from_transform(((Object *)id)->object_to_world);

View File

@ -22,9 +22,8 @@ class ObjectData : public IdData {
ObjectData(BlenderSceneDelegate *scene_delegate, Object *object);
int type();
pxr::GfMatrix4d transform();
bool update_visibility(View3D *view3d);
virtual bool update_visibility(View3D *view3d);
bool visible;
};

View File

@ -46,7 +46,7 @@ WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContex
: IdData(scene_delegate, (ID *)world), context(context)
{
p_id = prim_id(scene_delegate);
CLOG_INFO(LOG_BSD, 2, "%s - %s", id->name, p_id.GetText());
CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id->name, p_id.GetText());
}
void WorldData::init()