Implement GetDoubleSided and GetCullStyle for BlenderSceneDelegate #38

Merged
Bogdan Nagirniak merged 3 commits from BLEN-408 into hydra-render 2023-05-10 14:03:18 +02:00
6 changed files with 31 additions and 3 deletions
Showing only changes of commit a929df2082 - Show all commits

View File

@ -23,6 +23,7 @@ extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; /* BSD - Blender Scene Delegat
class BlenderSceneDelegate : public pxr::HdSceneDelegate { class BlenderSceneDelegate : public pxr::HdSceneDelegate {
friend ObjectData; /* has access to instances */ friend ObjectData; /* has access to instances */
friend MeshData; /* has access to materials */ friend MeshData; /* has access to materials */
friend MaterialData; /* has access to objects and instancers */
public: public:
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW }; enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };

View File

@ -227,6 +227,13 @@ void InstancerData::update_as_parent()
prim_id, pxr::HdChangeTracker::AllDirty); prim_id, pxr::HdChangeTracker::AllDirty);
} }
void InstancerData::update_double_sided(MaterialData *mat_data)
{
for (auto &it : mesh_instances_) {
it.second.data->update_double_sided(mat_data);
}
}
pxr::SdfPath InstancerData::object_prim_id(Object *object) const pxr::SdfPath InstancerData::object_prim_id(Object *object) const
{ {
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */ /* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */

View File

@ -43,6 +43,7 @@ class InstancerData : public ObjectData {
void check_remove(std::set<std::string> &available_objects); void check_remove(std::set<std::string> &available_objects);
void available_materials(std::set<pxr::SdfPath> &paths) const; void available_materials(std::set<pxr::SdfPath> &paths) const;
void update_as_parent(); void update_as_parent();
void update_double_sided(MaterialData *mat_data);
private: private:
pxr::SdfPath object_prim_id(Object *object) const; pxr::SdfPath object_prim_id(Object *object) const;

View File

@ -125,7 +125,15 @@ void MaterialData::update()
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
pxr::HdMaterial::AllDirty); pxr::HdMaterial::AllDirty);
if (prev_double_sided != double_sided) { if (prev_double_sided != double_sided) {
for (auto &it : scene_delegate_->objects_) {
MeshData *m_data = dynamic_cast<MeshData *>(it.second.get());
if (m_data) {
m_data->update_double_sided(this);
}
}
for (auto &it : scene_delegate_->instancers_) {
it.second->update_double_sided(this);
}
} }
} }

View File

@ -119,6 +119,7 @@ bool MeshData::update_visibility()
{ {
bool ret = ObjectData::update_visibility(); bool ret = ObjectData::update_visibility();
if (ret) { if (ret) {
ID_LOG(2, "");
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
prim_id, pxr::HdChangeTracker::DirtyVisibility); prim_id, pxr::HdChangeTracker::DirtyVisibility);
} }
@ -172,6 +173,15 @@ bool MeshData::double_sided() const
return true; return true;
} }
void MeshData::update_double_sided(MaterialData *mat_data)
{
if (mat_data_ == mat_data) {
ID_LOG(2, "");
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
prim_id, pxr::HdChangeTracker::DirtyDoubleSided);
}
}
void MeshData::write_mesh(Mesh *mesh) void MeshData::write_mesh(Mesh *mesh)
{ {
face_vertex_counts_.clear(); face_vertex_counts_.clear();

View File

@ -29,6 +29,7 @@ class MeshData : public ObjectData {
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
pxr::SdfPath material_id() const; pxr::SdfPath material_id() const;
bool double_sided() const; bool double_sided() const;
void update_double_sided(MaterialData *mat_data);
pxr::HdCullStyle cull_style = pxr::HdCullStyleBackUnlessDoubleSided; pxr::HdCullStyle cull_style = pxr::HdCullStyleBackUnlessDoubleSided;