Export volumes #58

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

View File

@ -126,6 +126,10 @@ pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id)
if (c_data) { if (c_data) {
return c_data->material_id(); return c_data->material_id();
} }
VolumeData *v_data = volume_data(rprim_id);
if (v_data) {
return v_data->material_id();
}
return pxr::SdfPath(); return pxr::SdfPath();
} }
@ -600,6 +604,10 @@ void BlenderSceneDelegate::remove_unused_objects()
if (c_data) { if (c_data) {
c_data->available_materials(available_materials); c_data->available_materials(available_materials);
} }
VolumeData *v_data = dynamic_cast<VolumeData *>(val.get());
if (v_data) {
v_data->available_materials(available_materials);
}
} }
for (auto &val : instancers_.values()) { for (auto &val : instancers_.values()) {
val->available_materials(available_materials); val->available_materials(available_materials);

View File

@ -29,6 +29,7 @@ class Engine;
class BlenderSceneDelegate : public pxr::HdSceneDelegate { class BlenderSceneDelegate : public pxr::HdSceneDelegate {
friend ObjectData; /* has access to instances */ friend ObjectData; /* has access to instances */
friend CurvesData; /* has access to materials */ friend CurvesData; /* has access to materials */
friend VolumeData; /* has access to materials */
friend MeshData; /* has access to materials */ friend MeshData; /* has access to materials */
friend MaterialData; /* has access to objects and instancers */ friend MaterialData; /* has access to objects and instancers */

View File

@ -9,6 +9,7 @@
#include <pxr/usdImaging/usdVolImaging/tokens.h> #include <pxr/usdImaging/usdVolImaging/tokens.h>
#include "BKE_volume.h" #include "BKE_volume.h"
#include "BKE_material.h"
#include "DNA_volume_types.h" #include "DNA_volume_types.h"
#include "BLI_index_range.hh" #include "BLI_index_range.hh"
@ -34,6 +35,7 @@ void VolumeData::init()
} }
filepath_ = BKE_volume_grids_frame_filepath(volume); filepath_ = BKE_volume_grids_frame_filepath(volume);
write_transform(); write_transform();
write_materials();
BKE_volume_unload(volume); BKE_volume_unload(volume);
} }
@ -66,6 +68,27 @@ void VolumeData::remove()
void VolumeData::update() void VolumeData::update()
{ {
Object *object = (Object *)id;
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
init();
bits = pxr::HdChangeTracker::AllDirty;
}
if (id->recalc & ID_RECALC_SHADING) {
write_materials();
bits |= pxr::HdChangeTracker::DirtyMaterialId | pxr::HdChangeTracker::DirtyDoubleSided;
}
if (id->recalc & ID_RECALC_TRANSFORM) {
write_transform();
bits |= pxr::HdChangeTracker::DirtyTransform;
}
if (bits == pxr::HdChangeTracker::Clean) {
return;
}
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(prim_id, bits);
ID_LOG(1, "");
} }
pxr::VtValue VolumeData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const pxr::VtValue VolumeData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const
@ -131,4 +154,43 @@ pxr::HdVolumeFieldDescriptorVector VolumeData::volume_field_descriptors() const
return volume_field_descriptors; return volume_field_descriptors;
} }
pxr::SdfPath VolumeData::material_id() const
{
if (!mat_data_) {
return pxr::SdfPath();
}
return mat_data_->prim_id;
}
void VolumeData::available_materials(Set<pxr::SdfPath> &paths) const
{
if (mat_data_ && !mat_data_->prim_id.IsEmpty()) {
paths.add(mat_data_->prim_id);
}
}
void VolumeData::write_materials()
{
Object *object = (Object *)id;
Material *mat = nullptr;
/* TODO: Using only first material. Add support for multimaterial. */
if (BKE_object_material_count_eval(object) > 0) {
mat = BKE_object_material_get_eval(object, 0);
}
if (!mat) {
mat_data_ = nullptr;
return;
}
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
mat_data_ = scene_delegate_->material_data(p_id);
if (!mat_data_) {
scene_delegate_->materials_.add_new(
p_id, std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
mat_data_ = scene_delegate_->material_data(p_id);
mat_data_->init();
mat_data_->insert();
}
}
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -23,9 +23,14 @@ class VolumeData : public ObjectData {
bool update_visibility() override; bool update_visibility() override;
pxr::HdVolumeFieldDescriptorVector volume_field_descriptors() const; pxr::HdVolumeFieldDescriptorVector volume_field_descriptors() const;
pxr::SdfPath material_id() const;
void available_materials(Set<pxr::SdfPath> &paths) const;
private: private:
void write_materials();
std::string filepath_; std::string filepath_;
MaterialData *mat_data_ = nullptr;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra