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
11 changed files with 16 additions and 37 deletions
Showing only changes of commit 3976164cca - Show all commits

View File

@ -33,8 +33,6 @@ void BlenderSceneDelegate::set_material(MeshData &mesh_data)
MaterialData *mat_data = material_data(id);
if (!mat_data) {
materials[id] = MaterialData::create(this, material);
mat_data = material_data(id);
mat_data->insert();
}
mesh_data.material_id = id;
}
@ -43,7 +41,7 @@ void BlenderSceneDelegate::update_material(Material *material)
{
MaterialData *mat_data = material_data(MaterialData::prim_id(this, material));
if (mat_data) {
mat_data->update(IdData::DirtyBits::ALL_DIRTY);
mat_data->update();
}
}
@ -54,7 +52,6 @@ void BlenderSceneDelegate::update_world()
if (!world_data) {
if (world) {
world_data = WorldData::create(this, world, context);
world_data->insert();
}
}
else {
@ -133,7 +130,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
/* Check and update visibility */
for (auto &obj : objects) {
if (obj.second->update_visibility(view3d)) {
obj.second->update(IdData::DirtyBits::DIRTY_VISIBILITY);
obj.second->update();
};
}
}
@ -218,30 +215,10 @@ void BlenderSceneDelegate::add_update_object(Object *object,
objects[id] = ObjectData::create(this, object);
obj_data = object_data(id);
obj_data->update_visibility(view3d);
obj_data->insert();
return;
}
obj_data->update(IdData::DirtyBits::ALL_DIRTY);
//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 (shading) {
// obj_data->update(IdData::DirtyBits::DIRTY_MATERIAL);
//}
obj_data->update();
}
void BlenderSceneDelegate::add_update_instance(DupliObject *dupli)

View File

@ -18,11 +18,10 @@ class IdData {
IdData(BlenderSceneDelegate *scene_delegate, ID *id);
virtual ~IdData() = default;
enum class DirtyBits { DIRTY_TRANSFORM = 1, DIRTY_VISIBILITY, DIRTY_MATERIAL, ALL_DIRTY };
virtual void init() = 0;
virtual void insert() = 0;
virtual void remove() = 0;
virtual void update(DirtyBits dirty_bits) = 0;
virtual void update() = 0;
virtual pxr::VtValue get_data(pxr::TfToken const &key) const;
template<class T> const T get_data(pxr::TfToken const &key) const;

View File

@ -162,7 +162,7 @@ void LightData::remove()
scene_delegate->GetRenderIndex().RemoveSprim(prim_type(), p_id);
}
void LightData::update(DirtyBits dirty_bits)
void LightData::update()
{
/* TODO: prim_type was changed we have to do remove..add light */

View File

@ -18,7 +18,7 @@ class LightData : public ObjectData {
void init() override;
void insert() override;
void remove() override;
void update(DirtyBits dirty_bits) override;
void update() override;
pxr::VtValue get_data(pxr::TfToken const &key) const override;
bool update_visibility(View3D *view3d) override;

View File

@ -25,6 +25,7 @@ std::unique_ptr<MaterialData> MaterialData::create(BlenderSceneDelegate *scene_d
{
auto data = std::make_unique<MaterialData>(scene_delegate, material);
data->init();
data->insert();
return data;
}
@ -130,7 +131,7 @@ void MaterialData::remove()
scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id);
}
void MaterialData::update(DirtyBits dirty_bits)
void MaterialData::update()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
mtlx_path = pxr::SdfAssetPath("", "");

View File

@ -24,7 +24,7 @@ class MaterialData : IdData {
void init() override;
void insert() override;
void remove() override;
void update(DirtyBits dirty_bits) override;
void update() override;
pxr::VtValue get_data(pxr::TfToken const &key) const override;
pxr::VtValue material_resource();

View File

@ -240,7 +240,7 @@ void MeshData::remove()
scene_delegate->GetRenderIndex().RemoveRprim(p_id);
}
void MeshData::update(DirtyBits dirty_bits)
void MeshData::update()
{
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
Object *object = (Object *)id;

View File

@ -19,7 +19,7 @@ class MeshData : public ObjectData {
void init() override;
void insert() override;
void remove() override;
void update(DirtyBits dirty_bits) override;
void update() override;
pxr::VtValue get_data(pxr::TfToken const &key) const override;
bool update_visibility(View3D *view3d) override;

View File

@ -51,6 +51,7 @@ std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_deleg
}
if (data) {
data->init();
data->insert();
}
return data;
}

View File

@ -34,6 +34,7 @@ std::unique_ptr<WorldData> WorldData::create(BlenderSceneDelegate *scene_delegat
{
auto data = std::make_unique<WorldData>(scene_delegate, world, context);
data->init();
data->insert();
return data;
}
@ -159,7 +160,7 @@ void WorldData::remove()
scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id);
}
void WorldData::update(DirtyBits dirty_bits)
void WorldData::update()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
data.clear();
@ -170,7 +171,7 @@ void WorldData::update(DirtyBits dirty_bits)
void WorldData::update(World *world)
{
id = (ID *)world;
update(DirtyBits::ALL_DIRTY);
update();
}
} // namespace blender::render::hydra

View File

@ -30,7 +30,7 @@ class WorldData : public IdData {
void init() override;
void insert() override;
void remove() override;
void update(DirtyBits dirty_bits) override;
void update() override;
void update(World *world);
pxr::GfMatrix4d transform();