Export volumes #58

Merged
Bogdan Nagirniak merged 10 commits from BLEN-384 into hydra-render 2023-07-04 09:57:33 +02:00
3 changed files with 22 additions and 36 deletions
Showing only changes of commit fed6beb58d - Show all commits

View File

@ -205,7 +205,7 @@ pxr::HdVolumeFieldDescriptorVector BlenderSceneDelegate::GetVolumeFieldDescripto
{ {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", volume_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", volume_id.GetText());
VolumeData *v_data = volume_data(volume_id); VolumeData *v_data = volume_data(volume_id);
return v_data->volume_field_descriptors(); return v_data->field_descriptors();
} }
void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)

View File

@ -34,8 +34,23 @@ void VolumeData::init()
return; return;
} }
filepath_ = BKE_volume_grids_frame_filepath(volume); filepath_ = BKE_volume_grids_frame_filepath(volume);
if (volume->runtime.grids) {
const int num_grids = BKE_volume_num_grids(volume);
if (num_grids) {
for (const int i : IndexRange(num_grids)) {
const VolumeGrid *grid = BKE_volume_grid_get_for_read(volume, i);
const std::string grid_name = BKE_volume_grid_name(grid);
field_descriptors_.emplace_back(pxr::TfToken(grid_name),
pxr::UsdVolImagingTokens->openvdbAsset,
prim_id.AppendElementString("VF_" + grid_name));
}
}
}
write_transform(); write_transform();
write_materials(); write_materials();
BKE_volume_unload(volume); BKE_volume_unload(volume);
} }
@ -46,7 +61,7 @@ void VolumeData::insert()
ID_LOG(1, ""); ID_LOG(1, "");
for (auto &desc : volume_field_descriptors()) { for (auto &desc : field_descriptors_) {
scene_delegate_->GetRenderIndex().InsertBprim( scene_delegate_->GetRenderIndex().InsertBprim(
desc.fieldPrimType, scene_delegate_, desc.fieldId); desc.fieldPrimType, scene_delegate_, desc.fieldId);
ID_LOG(1, "Volume field %s", desc.fieldId.GetText()); ID_LOG(1, "Volume field %s", desc.fieldId.GetText());
@ -55,10 +70,7 @@ void VolumeData::insert()
void VolumeData::remove() void VolumeData::remove()
{ {
/* NOTE: Is it possible to manipulate a list of fields in Blender? for (auto &desc : field_descriptors_) {
* Also something can happen to file.
* Probably we need to store a field list in class. */
for (auto &desc : volume_field_descriptors()) {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", desc.fieldId.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", desc.fieldId.GetText());

log level 1 for remove

log level 1 for remove
scene_delegate_->GetRenderIndex().RemoveBprim(desc.fieldPrimType, desc.fieldId); scene_delegate_->GetRenderIndex().RemoveBprim(desc.fieldPrimType, desc.fieldId);
} }
@ -120,36 +132,9 @@ bool VolumeData::update_visibility()
return ret; return ret;
} }
pxr::HdVolumeFieldDescriptorVector VolumeData::volume_field_descriptors() const pxr::HdVolumeFieldDescriptorVector VolumeData::field_descriptors() const
{ {
Volume *volume = (Volume *)((Object *)id)->data; return field_descriptors_;
Main *main = CTX_data_main(scene_delegate_->context);
if (!volume->runtime.grids) {
return pxr::HdVolumeFieldDescriptorVector();
}
if (!BKE_volume_is_loaded(volume) && !BKE_volume_load(volume, main)) {
return pxr::HdVolumeFieldDescriptorVector();
}
const int num_grids = BKE_volume_num_grids(volume);
if (!num_grids) {
return pxr::HdVolumeFieldDescriptorVector();
}
pxr::HdVolumeFieldDescriptorVector volume_field_descriptors;
for (const int i : IndexRange(num_grids)) {
const VolumeGrid *grid = BKE_volume_grid_get_for_read(volume, i);
const std::string grid_name = BKE_volume_grid_name(grid);
volume_field_descriptors.emplace_back(pxr::TfToken(grid_name),
pxr::UsdVolImagingTokens->openvdbAsset,
prim_id.AppendElementString("VF_" + grid_name));
}
BKE_volume_unload(volume);
return volume_field_descriptors;
} }
pxr::SdfPath VolumeData::material_id() const pxr::SdfPath VolumeData::material_id() const

View File

@ -22,7 +22,7 @@ class VolumeData : public ObjectData {
pxr::VtValue get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const; pxr::VtValue get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const;
bool update_visibility() override; bool update_visibility() override;
pxr::HdVolumeFieldDescriptorVector volume_field_descriptors() const; pxr::HdVolumeFieldDescriptorVector field_descriptors() const;
pxr::SdfPath material_id() const; pxr::SdfPath material_id() const;
void available_materials(Set<pxr::SdfPath> &paths) const; void available_materials(Set<pxr::SdfPath> &paths) const;
@ -30,6 +30,7 @@ class VolumeData : public ObjectData {
void write_materials(); void write_materials();
std::string filepath_; std::string filepath_;
pxr::HdVolumeFieldDescriptorVector field_descriptors_;
MaterialData *mat_data_ = nullptr; MaterialData *mat_data_ = nullptr;
}; };