forked from blender/blender
Export volumes #58
@ -63,6 +63,10 @@ pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken cons
|
||||
if (c_data) {
|
||||
return c_data->get_data(id, key);
|
||||
}
|
||||
VolumeData *vol_data = volume_data(id);
|
||||
if (vol_data) {
|
||||
return vol_data->get_data(id, key);
|
||||
}
|
||||
ObjectData *obj_data = object_data(id);
|
||||
if (obj_data) {
|
||||
return obj_data->get_data(key);
|
||||
@ -193,10 +197,10 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &
|
||||
}
|
||||
|
||||
pxr::HdVolumeFieldDescriptorVector BlenderSceneDelegate::GetVolumeFieldDescriptors(
|
||||
pxr::SdfPath const &volume_Id)
|
||||
pxr::SdfPath const &volume_id)
|
||||
{
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", volume_Id.GetText());
|
||||
VolumeData *v_data = volume_data(volume_Id);
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", volume_id.GetText());
|
||||
VolumeData *v_data = volume_data(volume_id);
|
||||
return v_data->volume_field_descriptors();
|
||||
}
|
||||
|
||||
@ -280,7 +284,7 @@ pxr::SdfPath BlenderSceneDelegate::world_prim_id() const
|
||||
|
||||
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const
|
||||
{
|
||||
pxr::SdfPath p_id = (id.GetName().find("SM_") == 0) ? id.GetParentPath() : id;
|
||||
pxr::SdfPath p_id = (id.GetName().find("SM_") == 0 || id.GetName().find("field_") == 0) ? id.GetParentPath() : id;
|
||||
auto obj_data = objects_.lookup_ptr(p_id);
|
||||
if (obj_data) {
|
||||
return obj_data->get();
|
||||
|
@ -62,7 +62,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
pxr::SdfPath const &prototype_id) override;
|
||||
pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancer_id) override;
|
||||
pxr::HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(
|
||||
pxr::SdfPath const &volume_Id) override;
|
||||
pxr::SdfPath const &volume_id) override;
|
||||
|
||||
void populate(Depsgraph *depsgraph, bContext *context);
|
||||
void clear();
|
||||
|
@ -3,9 +3,15 @@
|
||||
|
||||
#include <pxr/imaging/hd/tokens.h>
|
||||
#include <pxr/imaging/hd/volume.h>
|
||||
#include <pxr/imaging/hd/bprim.h>
|
||||
#include <pxr/imaging/hd/volumeFieldSchema.h>
|
||||
#include <pxr/usd/usdHydra/tokens.h>
|
||||
#include <pxr/usd/usdVol/tokens.h>
|
||||
#include <pxr/usdImaging/usdVolImaging/tokens.h>
|
||||
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_volume.h"
|
||||
#include "DNA_volume_types.h"
|
||||
#include "BLI_index_range.hh"
|
||||
|
||||
#include "blender_scene_delegate.h"
|
||||
#include "volume.h"
|
||||
@ -22,12 +28,19 @@ VolumeData::VolumeData(BlenderSceneDelegate *scene_delegate,
|
||||
void VolumeData::init()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
scene_delegate_->GetRenderIndex().InsertRprim(
|
||||
pxr::HdPrimTypeTokens->volume, scene_delegate_, prim_id);
|
||||
write_transform();
|
||||
}
|
||||
|
||||
void VolumeData::insert()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
scene_delegate_->GetRenderIndex().InsertRprim(
|
||||
pxr::HdPrimTypeTokens->volume, scene_delegate_, prim_id);
|
||||
|
||||
for (auto &desc : volume_field_descriptors()) {
|
||||
scene_delegate_->GetRenderIndex().InsertBprim(
|
||||
desc.fieldPrimType, scene_delegate_, desc.fieldId);
|
||||
}
|
||||
}
|
||||
|
||||
void VolumeData::remove()
|
||||
@ -40,6 +53,25 @@ void VolumeData::update()
|
||||
|
||||
pxr::VtValue VolumeData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const
|
||||
{
|
||||
Volume *volume = (Volume *)((Object *)this->id)->data;
|
||||
Main *main = CTX_data_main(scene_delegate_->context);
|
||||
BKE_volume_load(volume, main);
|
||||
if (key == pxr::HdVolumeFieldSchemaTokens->filePath) {
|
||||
auto path = BKE_volume_grids_frame_filepath(volume);
|
||||
|
||||
return pxr::VtValue(pxr::SdfAssetPath(path, path));
|
||||
}
|
||||
if (key == pxr::HdVolumeFieldSchemaTokens->fieldName) {
|
||||
std::string name = id.GetName();
|
||||
auto a = name.substr(name.find("_") + 1);
|
||||
return pxr::VtValue(pxr::TfToken(name.substr(name.find("_") + 1)));
|
||||
}
|
||||
if (key == pxr::HdVolumeFieldSchemaTokens->fieldIndex) {
|
||||
return pxr::VtValue(0);
|
||||
}
|
||||
if (key == pxr::UsdHydraTokens->textureMemory) {
|
||||
return pxr::VtValue(0.0f);
|
||||
}
|
||||
BKE_volume_unload(volume);
|
||||
Bogdan Nagirniak
commented
log level 1 for remove log level 1 for remove
|
||||
return pxr::VtValue();
|
||||
}
|
||||
|
||||
@ -52,12 +84,30 @@ pxr::HdVolumeFieldDescriptorVector VolumeData::volume_field_descriptors() const
|
||||
{
|
||||
pxr::HdVolumeFieldDescriptorVector volume_field_descriptors;
|
||||
Volume *volume = (Volume *)((Object *)id)->data;
|
||||
Main *main = CTX_data_main(scene_delegate_->context);
|
||||
if (!BKE_volume_load(volume, main)) {
|
||||
return pxr::HdVolumeFieldDescriptorVector();
|
||||
}
|
||||
|
||||
//pxr::HdVolumeFieldDescriptor density = pxr::HdVolumeFieldDescriptor(pxr::TfToken("density"),)
|
||||
//TfToken fieldName;
|
||||
//TfToken fieldPrimType;
|
||||
//SdfPath fieldId;
|
||||
const int num_grids = BKE_volume_num_grids(volume);
|
||||
if (!num_grids) {
|
||||
return pxr::HdVolumeFieldDescriptorVector();
|
||||
}
|
||||
|
||||
const std::string grid_path = BKE_volume_grids_frame_filepath(volume);
|
||||
|
||||
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);
|
||||
|
||||
pxr::HdVolumeFieldDescriptor desc = pxr::HdVolumeFieldDescriptor(
|
||||
pxr::TfToken(grid_name),
|
||||
pxr::UsdVolImagingTokens->openvdbAsset,
|
||||
prim_id.AppendElementString("field_" + grid_name));
|
||||
volume_field_descriptors.push_back(desc);
|
||||
}
|
||||
|
||||
BKE_volume_unload(volume);
|
||||
return volume_field_descriptors;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
Yes, move volume_field_descriptors to private field
VolumeData::field_descriptors_