Code improvements and fixes #26

Merged
Bogdan Nagirniak merged 8 commits from code_improvements_fixes into hydra-render 2023-04-21 07:48:50 +02:00
8 changed files with 47 additions and 47 deletions
Showing only changes of commit b9f0befc8a - Show all commits

View File

@ -116,7 +116,7 @@ bool InstancerData::update_visibility()
return ret;
}
pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(pxr::HdInterpolation interpolation)
pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(pxr::HdInterpolation interpolation) const
{
pxr::HdPrimvarDescriptorVector primvars;
if (interpolation == pxr::HdInterpolationInstance) {
@ -126,17 +126,17 @@ pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(pxr::HdInterpo
return primvars;
}
pxr::VtIntArray InstancerData::indices(pxr::SdfPath const &id)
pxr::VtIntArray InstancerData::indices(pxr::SdfPath const &id) const
{
return instances_[id].indices;
return instances_.find(id)->second.indices;
}
ObjectData *InstancerData::object_data(pxr::SdfPath const &id)
ObjectData *InstancerData::object_data(pxr::SdfPath const &id) const
{
return instances_[id].obj_data.get();
return instances_.find(id)->second.obj_data.get();
}
pxr::SdfPathVector InstancerData::prototypes()
pxr::SdfPathVector InstancerData::prototypes() const
{
pxr::SdfPathVector paths;
for (auto &it : instances_) {
@ -184,7 +184,7 @@ void InstancerData::check_remove(std::set<std::string> &available_objects)
}
}
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths)
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const
{
for (auto &it : instances_) {
pxr::SdfPath mat_id = ((MeshData *)it.second.obj_data.get())->material_id();

View File

@ -32,13 +32,13 @@ class InstancerData : public ObjectData {
pxr::GfMatrix4d transform() override;
bool update_visibility() override;
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation);
pxr::VtIntArray indices(pxr::SdfPath const &id);
ObjectData *object_data(pxr::SdfPath const &id);
pxr::SdfPathVector prototypes();
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
pxr::VtIntArray indices(pxr::SdfPath const &id) const;
ObjectData *object_data(pxr::SdfPath const &id) const;
pxr::SdfPathVector prototypes() const;
void check_update(Object *object);
void check_remove(std::set<std::string> &available_objects);
void available_materials(std::set<pxr::SdfPath> &paths);
void available_materials(std::set<pxr::SdfPath> &paths) const;
private:
pxr::SdfPath object_prim_id(Object *object) const;

View File

@ -94,7 +94,7 @@ void LightData::insert()
void LightData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText());
scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, prim_id);
}

View File

@ -77,24 +77,39 @@ void MaterialData::init()
mtlx_path_ = pxr::SdfAssetPath(path, path);
ID_LOG(2, "mtlx=%s", mtlx_path_.GetResolvedPath().c_str());
/* Calculate material network map */
if (!path.empty()) {
pxr::HdRenderDelegate *render_delegate = scene_delegate_->GetRenderIndex().GetRenderDelegate();
pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes();
pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts();
pxr::HdMaterialNetworkMap network_map;
hdmtlx_convert_to_materialnetworkmap(path, shader_source_types, render_contexts, &network_map);
material_network_map_ = network_map;
}
else {
material_network_map_ = pxr::VtValue();
}
}
void MaterialData::insert()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
ID_LOG(2, "");
scene_delegate_->GetRenderIndex().InsertSprim(
pxr::HdPrimTypeTokens->material, scene_delegate_, prim_id);
}
void MaterialData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText());
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, prim_id);
}
void MaterialData::update()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
ID_LOG(2, "");
init();
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
pxr::HdMaterial::AllDirty);
@ -112,23 +127,8 @@ pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const
return ret;
}
pxr::VtValue MaterialData::get_material_resource()
pxr::VtValue MaterialData::get_material_resource() const
{
if (material_network_map_.IsEmpty()) {
const std::string &path = mtlx_path_.GetResolvedPath();
if (!path.empty()) {
pxr::HdRenderDelegate *render_delegate =
scene_delegate_->GetRenderIndex().GetRenderDelegate();
pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes();
pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts();
pxr::HdMaterialNetworkMap network_map;
hdmtlx_convert_to_materialnetworkmap(
path, shader_source_types, render_contexts, &network_map);
material_network_map_ = network_map;
}
}
return material_network_map_;
}

View File

@ -29,7 +29,7 @@ class MaterialData : public IdData {
void update() override;
pxr::VtValue get_data(pxr::TfToken const &key) const override;
pxr::VtValue get_material_resource();
pxr::VtValue get_material_resource() const;
private:
pxr::SdfAssetPath mtlx_path_;

View File

@ -48,7 +48,7 @@ void MeshData::insert()
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
ID_LOG(2, "");
scene_delegate_->GetRenderIndex().InsertRprim(
pxr::HdPrimTypeTokens->mesh, scene_delegate_, prim_id);
}
@ -59,7 +59,7 @@ void MeshData::remove()
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText());
scene_delegate_->GetRenderIndex().RemoveRprim(prim_id);
}
@ -95,7 +95,7 @@ void MeshData::update()
remove();
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
ID_LOG(2, "");
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(prim_id, bits);
}
@ -127,7 +127,7 @@ bool MeshData::update_visibility()
return ret;
}
pxr::HdMeshTopology MeshData::mesh_topology()
pxr::HdMeshTopology MeshData::mesh_topology() const
{
return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->none,
pxr::HdTokens->rightHanded,
@ -135,7 +135,7 @@ pxr::HdMeshTopology MeshData::mesh_topology()
face_vertex_indices_);
}
pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation)
pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation) const
{
pxr::HdPrimvarDescriptorVector primvars;
if (interpolation == pxr::HdInterpolationVertex) {
@ -157,7 +157,7 @@ pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolatio
return primvars;
}
pxr::SdfPath MeshData::material_id()
pxr::SdfPath MeshData::material_id() const
{
if (!mat_data_) {
return pxr::SdfPath();
@ -216,11 +216,11 @@ void MeshData::write_material()
mat_data_ = nullptr;
return;
}
pxr::SdfPath id = scene_delegate_->material_prim_id(mat);
mat_data_ = scene_delegate_->material_data(id);
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
mat_data_ = scene_delegate_->material_data(p_id);
if (!mat_data_) {
scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat, id);
mat_data_ = scene_delegate_->material_data(id);
scene_delegate_->materials_[p_id] = MaterialData::create(scene_delegate_, mat, p_id);
mat_data_ = scene_delegate_->material_data(p_id);
}
}

View File

@ -25,9 +25,9 @@ class MeshData : public ObjectData {
pxr::VtValue get_data(pxr::TfToken const &key) const override;
bool update_visibility() override;
pxr::HdMeshTopology mesh_topology();
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation);
pxr::SdfPath material_id();
pxr::HdMeshTopology mesh_topology() const;
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
pxr::SdfPath material_id() const;
protected:
void write_mesh(Mesh *mesh);

View File

@ -127,7 +127,7 @@ void WorldData::insert()
void WorldData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText());
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, prim_id);
}