Support multimaterials on one mesh #44

Merged
Bogdan Nagirniak merged 11 commits from BLEN-417 into hydra-render 2023-05-24 07:07:39 +02:00
4 changed files with 19 additions and 8 deletions
Showing only changes of commit 8a310c67fe - Show all commits

View File

@ -138,7 +138,7 @@ pxr::HdCullStyle BlenderSceneDelegate::GetCullStyle(pxr::SdfPath const &id)
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", prim_id.GetText());
InstancerData *i_data = instancer_data(prim_id.GetParentPath());
InstancerData *i_data = instancer_data(prim_id, true);
if (i_data) {
return i_data->prim_id;
}
@ -387,7 +387,6 @@ void BlenderSceneDelegate::check_updates()
data.only_updated = true;
ITER_BEGIN (DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id)
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
2,
"Update: %s [%s]",

View File

@ -109,9 +109,9 @@ bool InstancerData::update_visibility()
pxr::GfMatrix4d InstancerData::get_transform(pxr::SdfPath const &id) const
{
if (id.GetPathElementCount() == 4) {
const auto &inst = light_instances_.find(id.GetParentPath())->second;
return inst.transforms[light_prim_id_index(id)];
auto l_it = light_instances_.find(id.GetParentPath());
if (l_it != light_instances_.end()) {
return l_it->second.transforms[light_prim_id_index(id)];
}
/* Mesh instance transform must be identity */
@ -131,12 +131,12 @@ pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(
pxr::VtIntArray InstancerData::indices(pxr::SdfPath const &id) const
{
return mesh_instances_.find(id)->second.indices;
return mesh_instances_.find(id.GetParentPath())->second.indices;
}
ObjectData *InstancerData::object_data(pxr::SdfPath const &id) const
{
auto m_it = mesh_instances_.find(id);
auto m_it = mesh_instances_.find(id.GetParentPath());
if (m_it != mesh_instances_.end()) {
return m_it->second.data.get();
}
@ -151,7 +151,9 @@ pxr::SdfPathVector InstancerData::prototypes() const
{
pxr::SdfPathVector paths;
for (auto &it : mesh_instances_) {
paths.push_back(it.first);
for (auto &p : it.second.data->submesh_paths()) {
paths.push_back(p);
}
}
return paths;
}

View File

@ -182,6 +182,15 @@ void MeshData::available_materials(std::set<pxr::SdfPath> &paths) const
}
}
pxr::SdfPathVector MeshData::submesh_paths() const
{
pxr::SdfPathVector ret;
for (int i = 0; i < submeshes_.size(); ++i) {
ret.push_back(submesh_prim_id(i));
}
return ret;
}
pxr::SdfPath MeshData::submesh_prim_id(int index) const
{
char name[16];

View File

@ -40,6 +40,7 @@ class MeshData : public ObjectData {
bool double_sided(pxr::SdfPath const &id) const;
void update_double_sided(MaterialData *mat_data);
void available_materials(std::set<pxr::SdfPath> &paths) const;
pxr::SdfPathVector submesh_paths() const;
pxr::HdCullStyle cull_style = pxr::HdCullStyleBackUnlessDoubleSided;