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
4 changed files with 37 additions and 32 deletions
Showing only changes of commit 42233ebc7a - Show all commits

View File

@ -34,7 +34,6 @@ void BlenderSceneDelegate::set_material(MeshData &mesh_data)
if (!mat_data) { if (!mat_data) {
materials[id] = MaterialData::create(this, material); materials[id] = MaterialData::create(this, material);
mat_data = material_data(id); mat_data = material_data(id);
mat_data->export_mtlx();
mat_data->insert(); mat_data->insert();
} }
mesh_data.material_id = id; mesh_data.material_id = id;
@ -44,7 +43,6 @@ void BlenderSceneDelegate::update_material(Material *material)
{ {
MaterialData *mat_data = material_data(MaterialData::prim_id(this, material)); MaterialData *mat_data = material_data(MaterialData::prim_id(this, material));
if (mat_data) { if (mat_data) {
mat_data->export_mtlx();
mat_data->update(IdData::DirtyBits::ALL_DIRTY); mat_data->update(IdData::DirtyBits::ALL_DIRTY);
} }
} }
@ -61,8 +59,7 @@ void BlenderSceneDelegate::update_world()
} }
else { else {
if (world) { if (world) {
world_data = WorldData::create(this, world, context); world_data->update(world);
world_data->update(IdData::DirtyBits::ALL_DIRTY);
} }
else { else {
world_data->remove(); world_data->remove();

View File

@ -41,11 +41,13 @@ MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *mater
: IdData(scene_delegate, (ID *)material) : IdData(scene_delegate, (ID *)material)
{ {
p_id = prim_id(scene_delegate, material); p_id = prim_id(scene_delegate, material);
CLOG_INFO(LOG_BSD, 2, "%s - %s", id->name, p_id.GetText());
} }
void MaterialData::init() void MaterialData::init()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", id->name); CLOG_INFO(LOG_BSD, 2, "%s", id->name);
export_mtlx();
} }
pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const
@ -72,7 +74,6 @@ pxr::VtValue MaterialData::material_resource()
HdMtlxConvertToMaterialNetworkMap( HdMtlxConvertToMaterialNetworkMap(
path, shader_source_types, render_contexts, &material_network_map); path, shader_source_types, render_contexts, &material_network_map);
CLOG_INFO(LOG_BSD, 3, "%s", path.c_str());
return pxr::VtValue(material_network_map); return pxr::VtValue(material_network_map);
} }
return pxr::VtValue(); return pxr::VtValue();
@ -118,29 +119,23 @@ void MaterialData::export_mtlx()
void MaterialData::insert() void MaterialData::insert()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().InsertSprim( scene_delegate->GetRenderIndex().InsertSprim(
pxr::HdPrimTypeTokens->material, scene_delegate, p_id); pxr::HdPrimTypeTokens->material, scene_delegate, p_id);
CLOG_INFO(LOG_BSD, 2, "Add: %s id=%s", name().c_str(), p_id.GetString().c_str());
} }
void MaterialData::remove() void MaterialData::remove()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id); scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id);
CLOG_INFO(LOG_BSD, 2, "Remove: %s", name().c_str());
} }
void MaterialData::update(DirtyBits dirty_bits) void MaterialData::update(DirtyBits dirty_bits)
{ {
pxr::HdDirtyBits bits = pxr::HdMaterial::Clean; CLOG_INFO(LOG_BSD, 2, "%s", id->name);
switch (dirty_bits) { mtlx_path = pxr::SdfAssetPath("", "");
case DirtyBits::ALL_DIRTY: init();
bits = pxr::HdMaterial::AllDirty; scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, pxr::HdMaterial::AllDirty);
break;
default:
break;
}
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits);
CLOG_INFO(LOG_BSD, 2, "Update: %s, mtlx=%s", name().c_str(), mtlx_path.GetResolvedPath().c_str());
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -46,6 +46,7 @@ WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContex
: IdData(scene_delegate, (ID *)world), context(context) : IdData(scene_delegate, (ID *)world), context(context)
{ {
p_id = prim_id(scene_delegate); p_id = prim_id(scene_delegate);
CLOG_INFO(LOG_BSD, 2, "%s - %s", id->name, p_id.GetText());
} }
void WorldData::init() void WorldData::init()
@ -60,9 +61,20 @@ void WorldData::init()
/* TODO: Create nodes parsing system */ /* TODO: Create nodes parsing system */
bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL); bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL);
bNodeSocket input_socket = output_node->input_by_identifier("Surface"); blender::Span<bNodeSocket *> input_sockets = output_node->input_sockets();
bNodeLink const *link = input_socket.directly_linked_links()[0]; bNodeSocket *input_socket = nullptr;
if (input_socket.directly_linked_links().is_empty()) {
for (auto socket : input_sockets) {
if (STREQ(socket->name, "Surface")) {
input_socket = socket;
break;
}
}
if (!input_socket) {
return;
}
bNodeLink const *link = input_socket->directly_linked_links()[0];
if (input_socket->directly_linked_links().is_empty()) {
return; return;
} }
@ -136,29 +148,29 @@ pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const
void WorldData::insert() void WorldData::insert()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().InsertSprim( scene_delegate->GetRenderIndex().InsertSprim(
pxr::HdPrimTypeTokens->domeLight, scene_delegate, p_id); pxr::HdPrimTypeTokens->domeLight, scene_delegate, p_id);
CLOG_INFO(LOG_BSD, 2, "Add: id=%s", p_id.GetText());
} }
void WorldData::remove() void WorldData::remove()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id); scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id);
CLOG_INFO(LOG_BSD, 2, "Remove");
} }
void WorldData::update(DirtyBits dirty_bits) void WorldData::update(DirtyBits dirty_bits)
{ {
pxr::HdDirtyBits bits = pxr::HdLight::Clean; CLOG_INFO(LOG_BSD, 2, "%s", id->name);
switch (dirty_bits) { data.clear();
case DirtyBits::ALL_DIRTY: init();
bits = pxr::HdLight::AllDirty; scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, pxr::HdLight::AllDirty);
break;
default:
break;
} }
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits);
CLOG_INFO(LOG_BSD, 2, "Update"); void WorldData::update(World *world)
{
id = (ID *)world;
update(DirtyBits::ALL_DIRTY);
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

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