Implement instancing for light objects #35

Merged
Bogdan Nagirniak merged 18 commits from BLEN-395 into hydra-render 2023-05-04 15:12:27 +02:00
2 changed files with 15 additions and 23 deletions
Showing only changes of commit 61f37c8d6a - Show all commits

View File

@ -32,49 +32,42 @@ pxr::HdMeshTopology BlenderSceneDelegate::GetMeshTopology(pxr::SdfPath const &id
pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText());
InstancerData *i_data = instancer_data(id, true);
if (i_data) {
return i_data->get_transform(id);
}
ObjectData *obj_data = object_data(id);
if (obj_data) {
return obj_data->transform;
}
if (id == world_prim_id()) {
return world_data_->transform;
}
return pxr::GfMatrix4d();
}
pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s, %s", id.GetText(), key.GetText());
ObjectData *obj_data = object_data(id);
if (obj_data) {
return obj_data->get_data(key);
}
MaterialData *mat_data = material_data(id);
if (mat_data) {
return mat_data->get_data(key);
}
InstancerData *i_data = instancer_data(id);
if (i_data) {
return i_data->get_data(key);
}
return pxr::VtValue();
}
pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id,
pxr::TfToken const &key)
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s, %s", id.GetText(), key.GetText());
LightData *l_data = light_data(id);
if (l_data) {
return l_data->get_data(key);
@ -89,27 +82,26 @@ pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(
pxr::SdfPath const &id, pxr::HdInterpolation interpolation)
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s, %d", id.GetText(), interpolation);
MeshData *m_data = mesh_data(id);
if (m_data) {
return m_data->primvar_descriptors(interpolation);
}
InstancerData *i_data = instancer_data(id);
if (i_data) {
return i_data->primvar_descriptors(interpolation);
}
return pxr::HdPrimvarDescriptorVector();
}
pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id)
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", rprim_id.GetText());
return mesh_data(rprim_id)->material_id();
}
pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id)
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText());
MaterialData *mat_data = material_data(id);
if (mat_data) {
return mat_data->get_material_resource();
@ -119,10 +111,10 @@ pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id)
bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id)
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText());
if (id == world_prim_id()) {
return true;
}
return object_data(id)->visible;
}
@ -181,11 +173,9 @@ void BlenderSceneDelegate::clear()
for (auto &it : objects_) {
it.second->remove();
}
for (auto &it : instancers_) {
it.second->remove();
}
for (auto &it : materials_) {
it.second->remove();
}

View File

@ -212,7 +212,7 @@ void InstancerData::set_instances()
for (auto &it : mesh_instances_) {
it.second.indices.clear();
}
int index = 0;
int mesh_index = 0, light_index = 0;
Instance *inst;
pxr::SdfPath p_id;
Object *ob;
@ -224,18 +224,20 @@ void InstancerData::set_instances()
if (!is_supported(ob)) {
continue;
}
p_id = object_prim_id(dupli->ob);
p_id = object_prim_id(dupli->ob);
if (ob->type == OB_LAMP) {
auto it = mesh_instances_.find(p_id);
if (it == mesh_instances_.end()) {
inst = &mesh_instances_[p_id];
auto it = light_instances_.find(p_id);
if (it == light_instances_.end()) {
inst = &light_instances_[p_id];
inst->obj_data = std::make_unique<LightData>(scene_delegate_, ob, p_id);
inst->obj_data->init();
}
else {
inst = &it->second;
}
mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat));
inst->indices.push_back(mesh_index);
}
else {
auto it = mesh_instances_.find(p_id);
@ -246,11 +248,11 @@ void InstancerData::set_instances()
else {
inst = &it->second;
}
}
mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat));
inst->indices.push_back(index);
ID_LOG(2, "%s %d", inst->obj_data->id->name, index);
++index;
inst->indices.push_back(mesh_index);
ID_LOG(2, "%s %d", inst->obj_data->id->name, mesh_index);
++mesh_index;
}
}
free_object_duplilist(lb);