forked from blender/blender
Implement GetDoubleSided and GetCullStyle for BlenderSceneDelegate #38
@ -122,6 +122,18 @@ bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id)
|
||||
return object_data(id)->visible;
|
||||
}
|
||||
|
||||
bool BlenderSceneDelegate::GetDoubleSided(pxr::SdfPath const &id)
|
||||
{
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText());
|
||||
return mesh_data(id)->double_sided();
|
||||
}
|
||||
|
||||
pxr::HdCullStyle BlenderSceneDelegate::GetCullStyle(pxr::SdfPath const &id)
|
||||
{
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText());
|
||||
return mesh_data(id)->cull_style;
|
||||
}
|
||||
|
||||
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
|
||||
{
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", prim_id.GetText());
|
||||
|
@ -21,8 +21,9 @@ namespace blender::render::hydra {
|
||||
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; /* BSD - Blender Scene Delegate */
|
||||
|
||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
friend ObjectData; /* has access to instances */
|
||||
friend MeshData; /* has access to materials */
|
||||
friend ObjectData; /* has access to instances */
|
||||
friend MeshData; /* has access to materials */
|
||||
friend MaterialData; /* has access to objects and instancers */
|
||||
|
||||
public:
|
||||
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
|
||||
@ -43,6 +44,8 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprim_id) override;
|
||||
pxr::VtValue GetMaterialResource(pxr::SdfPath const &material_id) override;
|
||||
bool GetVisible(pxr::SdfPath const &id) override;
|
||||
bool GetDoubleSided(pxr::SdfPath const &id) override;
|
||||
pxr::HdCullStyle GetCullStyle(pxr::SdfPath const &id) override;
|
||||
pxr::SdfPath GetInstancerId(pxr::SdfPath const &prim_id) override;
|
||||
pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancer_id) override;
|
||||
pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancer_id,
|
||||
|
@ -228,6 +228,13 @@ void InstancerData::update_as_parent()
|
||||
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
|
||||
{
|
||||
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
||||
|
@ -43,6 +43,7 @@ class InstancerData : public ObjectData {
|
||||
void check_remove(std::set<std::string> &available_objects);
|
||||
void available_materials(std::set<pxr::SdfPath> &paths) const;
|
||||
void update_as_parent();
|
||||
void update_double_sided(MaterialData *mat_data);
|
||||
|
||||
private:
|
||||
pxr::SdfPath object_prim_id(Object *object) const;
|
||||
|
@ -30,7 +30,7 @@ MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate,
|
||||
void MaterialData::init()
|
||||
{
|
||||
ID_LOG(2, "");
|
||||
|
||||
double_sided = (((Material *)id)->blend_flag & MA_BL_CULL_BACKFACE) == 0;
|
||||
material_network_map_ = pxr::VtValue();
|
||||
|
||||
/* Call of python function hydra.export_mtlx() */
|
||||
@ -120,9 +120,21 @@ void MaterialData::remove()
|
||||
void MaterialData::update()
|
||||
{
|
||||
ID_LOG(2, "");
|
||||
bool prev_double_sided = double_sided;
|
||||
init();
|
||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
|
||||
pxr::HdMaterial::AllDirty);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const
|
||||
|
@ -27,6 +27,8 @@ class MaterialData : public IdData {
|
||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||
pxr::VtValue get_material_resource() const;
|
||||
|
||||
bool double_sided = true;
|
||||
|
||||
private:
|
||||
pxr::SdfAssetPath mtlx_path_;
|
||||
pxr::VtValue material_network_map_;
|
||||
|
@ -74,7 +74,7 @@ void MeshData::update()
|
||||
else {
|
||||
if (id->recalc & ID_RECALC_SHADING) {
|
||||
write_material();
|
||||
bits |= pxr::HdChangeTracker::DirtyMaterialId;
|
||||
bits |= pxr::HdChangeTracker::DirtyMaterialId | pxr::HdChangeTracker::DirtyDoubleSided;
|
||||
}
|
||||
if (id->recalc & ID_RECALC_TRANSFORM) {
|
||||
write_transform();
|
||||
@ -119,6 +119,7 @@ bool MeshData::update_visibility()
|
||||
{
|
||||
bool ret = ObjectData::update_visibility();
|
||||
if (ret) {
|
||||
ID_LOG(2, "");
|
||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
|
||||
prim_id, pxr::HdChangeTracker::DirtyVisibility);
|
||||
}
|
||||
@ -164,6 +165,23 @@ pxr::SdfPath MeshData::material_id() const
|
||||
return mat_data_->prim_id;
|
||||
}
|
||||
|
||||
bool MeshData::double_sided() const
|
||||
{
|
||||
if (mat_data_) {
|
||||
return mat_data_->double_sided;
|
||||
}
|
||||
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)
|
||||
{
|
||||
face_vertex_counts_.clear();
|
||||
|
@ -28,6 +28,10 @@ class MeshData : public ObjectData {
|
||||
pxr::HdMeshTopology mesh_topology() const;
|
||||
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
|
||||
pxr::SdfPath material_id() const;
|
||||
bool double_sided() const;
|
||||
void update_double_sided(MaterialData *mat_data);
|
||||
|
||||
pxr::HdCullStyle cull_style = pxr::HdCullStyleBackUnlessDoubleSided;
|
||||
|
||||
private:
|
||||
void write_mesh(Mesh *mesh);
|
||||
|
Loading…
Reference in New Issue
Block a user