forked from blender/blender
Export volumes #58
@ -284,7 +284,7 @@ pxr::SdfPath BlenderSceneDelegate::world_prim_id() const
|
|||||||
|
|
||||||
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const
|
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const
|
||||||
{
|
{
|
||||||
pxr::SdfPath p_id = (id.GetName().find("SM_") == 0 || id.GetName().find("field_") == 0) ? id.GetParentPath() : id;
|
pxr::SdfPath p_id = (id.GetName().find("SM_") == 0 || id.GetName().find("VF_") == 0) ? id.GetParentPath() : id;
|
||||||
auto obj_data = objects_.lookup_ptr(p_id);
|
auto obj_data = objects_.lookup_ptr(p_id);
|
||||||
if (obj_data) {
|
if (obj_data) {
|
||||||
return obj_data->get();
|
return obj_data->get();
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
* Copyright 2011-2022 Blender Foundation */
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
#include <pxr/imaging/hd/tokens.h>
|
#include <pxr/imaging/hd/tokens.h>
|
||||||
#include <pxr/imaging/hd/volume.h>
|
|
||||||
#include <pxr/imaging/hd/bprim.h>
|
#include <pxr/imaging/hd/bprim.h>
|
||||||
#include <pxr/imaging/hd/volumeFieldSchema.h>
|
#include <pxr/imaging/hd/volumeFieldSchema.h>
|
||||||
#include <pxr/usd/usdHydra/tokens.h>
|
#include <pxr/usd/usdHydra/tokens.h>
|
||||||
@ -28,6 +27,15 @@ VolumeData::VolumeData(BlenderSceneDelegate *scene_delegate,
|
|||||||
void VolumeData::init()
|
void VolumeData::init()
|
||||||
{
|
{
|
||||||
ID_LOG(1, "");
|
ID_LOG(1, "");
|
||||||
|
Volume *volume = (Volume *)((Object *)this->id)->data;
|
||||||
|
Main *main = CTX_data_main(scene_delegate_->context);
|
||||||
|
if (!BKE_volume_load(volume, main)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
filepath_ = BKE_volume_grids_frame_filepath(volume);
|
||||||
|
if (BKE_volume_is_loaded(volume)) {
|
||||||
|
BKE_volume_unload(volume);
|
||||||
|
}
|
||||||
write_transform();
|
write_transform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,18 +60,13 @@ void VolumeData::update()
|
|||||||
}
|
}
|
||||||
|
|||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
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) {
|
if (key == pxr::HdVolumeFieldSchemaTokens->filePath) {
|
||||||
auto path = BKE_volume_grids_frame_filepath(volume);
|
return pxr::VtValue(pxr::SdfAssetPath(filepath_, filepath_));
|
||||||
return pxr::VtValue(pxr::SdfAssetPath(path, path));
|
|
||||||
}
|
}
|
||||||
if (key == pxr::HdVolumeFieldSchemaTokens->fieldName) {
|
if (key == pxr::HdVolumeFieldSchemaTokens->fieldName) {
|
||||||
std::string name = id.GetName();
|
std::string name = id.GetName();
|
||||||
auto a = name.substr(name.find("_") + 1);
|
return pxr::VtValue(pxr::TfToken(name.substr(name.find("VF_") + 3)));
|
||||||
return pxr::VtValue(pxr::TfToken(name.substr(name.find("_") + 1)));
|
|
||||||
}
|
}
|
||||||
if (key == pxr::HdVolumeFieldSchemaTokens->fieldIndex) {
|
if (key == pxr::HdVolumeFieldSchemaTokens->fieldIndex) {
|
||||||
return pxr::VtValue(0);
|
return pxr::VtValue(0);
|
||||||
@ -71,7 +74,6 @@ pxr::VtValue VolumeData::get_data(pxr::SdfPath const &id, pxr::TfToken const &ke
|
|||||||
if (key == pxr::UsdHydraTokens->textureMemory) {
|
if (key == pxr::UsdHydraTokens->textureMemory) {
|
||||||
Bogdan Nagirniak
commented
log level 1 for remove log level 1 for remove
|
|||||||
return pxr::VtValue(0.0f);
|
return pxr::VtValue(0.0f);
|
||||||
}
|
}
|
||||||
BKE_volume_unload(volume);
|
|
||||||
return pxr::VtValue();
|
return pxr::VtValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,10 +84,10 @@ bool VolumeData::update_visibility()
|
|||||||
|
|
||||||
pxr::HdVolumeFieldDescriptorVector VolumeData::volume_field_descriptors() const
|
pxr::HdVolumeFieldDescriptorVector VolumeData::volume_field_descriptors() const
|
||||||
{
|
{
|
||||||
pxr::HdVolumeFieldDescriptorVector volume_field_descriptors;
|
|
||||||
Volume *volume = (Volume *)((Object *)id)->data;
|
Volume *volume = (Volume *)((Object *)id)->data;
|
||||||
Main *main = CTX_data_main(scene_delegate_->context);
|
Main *main = CTX_data_main(scene_delegate_->context);
|
||||||
if (!BKE_volume_load(volume, main)) {
|
|
||||||
|
if (!BKE_volume_is_loaded(volume) && !BKE_volume_load(volume, main)) {
|
||||||
return pxr::HdVolumeFieldDescriptorVector();
|
return pxr::HdVolumeFieldDescriptorVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +96,7 @@ pxr::HdVolumeFieldDescriptorVector VolumeData::volume_field_descriptors() const
|
|||||||
return pxr::HdVolumeFieldDescriptorVector();
|
return pxr::HdVolumeFieldDescriptorVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string grid_path = BKE_volume_grids_frame_filepath(volume);
|
pxr::HdVolumeFieldDescriptorVector volume_field_descriptors;
|
||||||
|
|
||||||
for (const int i : IndexRange(num_grids)) {
|
for (const int i : IndexRange(num_grids)) {
|
||||||
const VolumeGrid *grid = BKE_volume_grid_get_for_read(volume, i);
|
const VolumeGrid *grid = BKE_volume_grid_get_for_read(volume, i);
|
||||||
const std::string grid_name = BKE_volume_grid_name(grid);
|
const std::string grid_name = BKE_volume_grid_name(grid);
|
||||||
@ -103,7 +104,7 @@ pxr::HdVolumeFieldDescriptorVector VolumeData::volume_field_descriptors() const
|
|||||||
pxr::HdVolumeFieldDescriptor desc = pxr::HdVolumeFieldDescriptor(
|
pxr::HdVolumeFieldDescriptor desc = pxr::HdVolumeFieldDescriptor(
|
||||||
pxr::TfToken(grid_name),
|
pxr::TfToken(grid_name),
|
||||||
pxr::UsdVolImagingTokens->openvdbAsset,
|
pxr::UsdVolImagingTokens->openvdbAsset,
|
||||||
prim_id.AppendElementString("field_" + grid_name));
|
prim_id.AppendElementString("VF_" + grid_name));
|
||||||
volume_field_descriptors.push_back(desc);
|
volume_field_descriptors.push_back(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class VolumeData : public ObjectData {
|
|||||||
pxr::HdVolumeFieldDescriptorVector volume_field_descriptors() const;
|
pxr::HdVolumeFieldDescriptorVector volume_field_descriptors() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
;
|
std::string filepath_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
Loading…
Reference in New Issue
Block a user
Yes, move volume_field_descriptors to private field
VolumeData::field_descriptors_