Export volumes from object modifier (quick effect) #62

Merged
Bogdan Nagirniak merged 28 commits from BLEN-448 into hydra-render 2023-07-20 23:49:25 +02:00
2 changed files with 14 additions and 15 deletions
Showing only changes of commit 3fb4129d30 - Show all commits

View File

@ -6,7 +6,6 @@
#include "BKE_mesh.hh" #include "BKE_mesh.hh"
#include "BKE_modifier.h" #include "BKE_modifier.h"
#include "BLI_path_util.h" #include "BLI_path_util.h"
#include "DNA_fluid_types.h"
#include "DNA_scene_types.h" #include "DNA_scene_types.h"
#include "DNA_volume_types.h" #include "DNA_volume_types.h"
@ -32,10 +31,10 @@ bool VolumeModifierData::is_volume_modifier(Object *object)
return false; return false;
} }
FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( FluidModifierData *modifier = (FluidModifierData *)BKE_modifiers_findby_type(
object, eModifierType_Fluid); object, eModifierType_Fluid);
return volume_modifier && volume_modifier->type & MOD_FLUID_TYPE_DOMAIN && return modifier && modifier->type & MOD_FLUID_TYPE_DOMAIN &&
volume_modifier->domain->type == FLUID_DOMAIN_TYPE_GAS; modifier->domain->type == FLUID_DOMAIN_TYPE_GAS;
} }
void VolumeModifierData::init() void VolumeModifierData::init()
@ -43,17 +42,16 @@ void VolumeModifierData::init()
ID_LOG(1, ""); ID_LOG(1, "");
Object *object = (Object *)this->id; Object *object = (Object *)this->id;
FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( modifier_ = (FluidModifierData *)BKE_modifiers_findby_type(object, eModifierType_Fluid);
object, eModifierType_Fluid);
if ((volume_modifier->domain->cache_data_format & FLUID_DOMAIN_FILE_OPENVDB) == 0) { if ((modifier_->domain->cache_data_format & FLUID_DOMAIN_FILE_OPENVDB) == 0) {
CLOG_WARN(LOG_RENDER_HYDRA_SCENE, CLOG_WARN(LOG_RENDER_HYDRA_SCENE,
"Volume %s is't exported: only OpenVDB file format supported", "Volume %s is't exported: only OpenVDB file format supported",
prim_id.GetText()); prim_id.GetText());
return; return;
} }
filepath_ = get_cached_file_path(volume_modifier->domain->cache_directory, filepath_ = get_cached_file_path(modifier_->domain->cache_directory,
scene_delegate_->scene->r.cfra); scene_delegate_->scene->r.cfra);
for (auto &grid_name : pxr::grid_tokens_->allTokens) { for (auto &grid_name : pxr::grid_tokens_->allTokens) {
@ -98,12 +96,9 @@ void VolumeModifierData::write_transform()
Object *object = (Object *)this->id; Object *object = (Object *)this->id;
/* set base scaling */ /* set base scaling */
float scale[3]; transform = pxr::GfMatrix4d().SetScale(pxr::GfVec3d(1.0f / modifier_->domain->global_size[0],
for (int i = 0; i < 3; ++i) { 1.0f / modifier_->domain->global_size[1],
scale[i] = (object->scale[i] != 0.0f) ? 1.0f / object->scale[i] : 1.0f; 1.0f / modifier_->domain->global_size[2]));
}
transform = pxr::GfMatrix4d().SetScale(pxr::GfVec3d(scale));
/* positioning to center */ /* positioning to center */
transform *= pxr::GfMatrix4d().SetTranslate(pxr::GfVec3d(-1, -1, -1)); transform *= pxr::GfMatrix4d().SetTranslate(pxr::GfVec3d(-1, -1, -1));
@ -113,7 +108,7 @@ void VolumeModifierData::write_transform()
transform *= pxr::GfMatrix4d(1.0f).SetScale(pxr::GfVec3d(texspace_scale)) * transform *= pxr::GfMatrix4d(1.0f).SetScale(pxr::GfVec3d(texspace_scale)) *
pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(texspace_loc)); pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(texspace_loc));
/* */ /* applying object transform */
transform *= gf_matrix_from_transform(object->object_to_world); transform *= gf_matrix_from_transform(object->object_to_world);
} }

View File

@ -5,6 +5,8 @@
#include <pxr/imaging/hd/sceneDelegate.h> #include <pxr/imaging/hd/sceneDelegate.h>
#include "DNA_fluid_types.h"
#include "volume.h" #include "volume.h"
namespace blender::render::hydra { namespace blender::render::hydra {
@ -24,6 +26,8 @@ class VolumeModifierData : public VolumeData {
void write_transform() override; void write_transform() override;
std::string get_cached_file_path(std::string directory, int frame); std::string get_cached_file_path(std::string directory, int frame);
FluidModifierData *modifier_;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra