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) {
materials[id] = MaterialData::create(this, material);
mat_data = material_data(id);
mat_data->export_mtlx();
mat_data->insert();
}
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));
if (mat_data) {
mat_data->export_mtlx();
mat_data->update(IdData::DirtyBits::ALL_DIRTY);
}
}
@ -61,8 +59,7 @@ void BlenderSceneDelegate::update_world()
}
else {
if (world) {
world_data = WorldData::create(this, world, context);
world_data->update(IdData::DirtyBits::ALL_DIRTY);
world_data->update(world);
}
else {
world_data->remove();

View File

@ -41,11 +41,13 @@ 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());
}
void MaterialData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
export_mtlx();
}
pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const
@ -72,7 +74,6 @@ pxr::VtValue MaterialData::material_resource()
HdMtlxConvertToMaterialNetworkMap(
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();
@ -118,29 +119,23 @@ void MaterialData::export_mtlx()
void MaterialData::insert()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().InsertSprim(
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()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
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)
{
pxr::HdDirtyBits bits = pxr::HdMaterial::Clean;
switch (dirty_bits) {
case DirtyBits::ALL_DIRTY:
bits = 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());
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
mtlx_path = pxr::SdfAssetPath("", "");
init();
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, pxr::HdMaterial::AllDirty);
}
} // 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)
{
p_id = prim_id(scene_delegate);
CLOG_INFO(LOG_BSD, 2, "%s - %s", id->name, p_id.GetText());
}
void WorldData::init()
@ -60,9 +61,20 @@ void WorldData::init()
/* TODO: Create nodes parsing system */
bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL);
bNodeSocket input_socket = output_node->input_by_identifier("Surface");
bNodeLink const *link = input_socket.directly_linked_links()[0];
if (input_socket.directly_linked_links().is_empty()) {
blender::Span<bNodeSocket *> input_sockets = output_node->input_sockets();
bNodeSocket *input_socket = nullptr;
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;
}
@ -136,29 +148,29 @@ pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const
void WorldData::insert()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().InsertSprim(
pxr::HdPrimTypeTokens->domeLight, scene_delegate, p_id);
CLOG_INFO(LOG_BSD, 2, "Add: id=%s", p_id.GetText());
}
void WorldData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id);
CLOG_INFO(LOG_BSD, 2, "Remove");
}
void WorldData::update(DirtyBits dirty_bits)
{
pxr::HdDirtyBits bits = pxr::HdLight::Clean;
switch (dirty_bits) {
case DirtyBits::ALL_DIRTY:
bits = pxr::HdLight::AllDirty;
break;
default:
break;
}
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits);
CLOG_INFO(LOG_BSD, 2, "Update");
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
data.clear();
init();
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, pxr::HdLight::AllDirty);
}
void WorldData::update(World *world)
{
id = (ID *)world;
update(DirtyBits::ALL_DIRTY);
}
} // namespace blender::render::hydra

View File

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