Fix visibility of instancer object #40

Closed
Georgiy Markelov wants to merge 21 commits from BLEN-405 into hydra-render

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
12 changed files with 82 additions and 14 deletions
Showing only changes of commit 740a821f22 - Show all commits

View File

@ -21,7 +21,7 @@
namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_RENDER_HYDRA; /* EN - Engine */
extern struct CLG_LogRef *LOG_RENDER_HYDRA;
class Engine {
public:

View File

@ -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());

View File

@ -3,6 +3,7 @@
#pragma once
#include <pxr/base/gf/vec2f.h>
#include <pxr/imaging/hd/sceneDelegate.h>
#include "BKE_context.h"
@ -18,11 +19,12 @@
namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; /* BSD - Blender Scene Delegate */
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;
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 +45,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,

View File

@ -5,7 +5,7 @@
#include <pxr/base/tf/token.h>
#include <pxr/base/vt/value.h>
#include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/usd/sdf/path.h>
#include "DNA_ID.h"
@ -39,7 +39,11 @@ template<class T> const T IdData::get_data(pxr::TfToken const &key) const
}
#define ID_LOG(level, msg, ...) \
CLOG_INFO( \
LOG_RENDER_HYDRA_SCENE, level, "%s (%s): " msg, prim_id.GetText(), id->name, __VA_ARGS__);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, \
level, \
"%s (%s): " msg, \
prim_id.GetText(), \
id->name, \
##__VA_ARGS__);
} // namespace blender::render::hydra

View File

@ -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> */
@ -246,7 +253,7 @@ pxr::SdfPath InstancerData::light_prim_id(LightInstance const &inst, int index)
int InstancerData::light_prim_id_index(pxr::SdfPath const &id) const
{
int index;
sscanf_s(id.GetName().c_str(), "L_%x", &index);
sscanf(id.GetName().c_str(), "L_%x", &index);
return index;
}

View File

@ -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;

View File

@ -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

View File

@ -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_;

View File

@ -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();

View File

@ -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);

View File

@ -22,6 +22,8 @@
namespace mx = MaterialX;
namespace blender::render::hydra {
void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path,
pxr::TfTokenVector const &shader_source_types,
pxr::TfTokenVector const &render_contexts,
@ -77,3 +79,5 @@ void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path,
}
}
}
} // namespace blender::render::hydra

View File

@ -4,13 +4,13 @@
#pragma once
#include <pxr/base/tf/token.h>
#include <pxr/pxr.h>
#include <pxr/imaging/hd/material.h>
#include <string>
struct pxr::HdMaterialNetworkMap;
namespace blender::render::hydra {
void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path,
pxr::TfTokenVector const &shader_source_types,
pxr::TfTokenVector const &render_contexts,
pxr::HdMaterialNetworkMap *out);
} // namespace blender::render::hydra