From 6ef2c7a9769640e30edc935d4f3bdda4bb8a127f Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 6 Jul 2023 20:44:20 +0300 Subject: [PATCH 01/23] initial --- .../render/hydra/scene_delegate/object.cc | 9 +- .../render/hydra/scene_delegate/volume.cc | 154 +++++++++++++++--- .../render/hydra/scene_delegate/volume.h | 6 + 3 files changed, 146 insertions(+), 23 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 81f4b920863d..5103728157a4 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -2,6 +2,8 @@ * Copyright 2011-2022 Blender Foundation */ #include "BKE_object.h" + +#include "DNA_scene_types.h" #include "DEG_depsgraph_query.h" #include "blender_scene_delegate.h" @@ -26,9 +28,14 @@ std::unique_ptr ObjectData::create(BlenderSceneDelegate *scene_deleg { std::unique_ptr data; + if (VolumeData::is_volume_modifier(object)) + { + return std::make_unique(scene_delegate, object, prim_id); + } + switch (object->type) { - case OB_MESH: case OB_SURF: + case OB_MESH: case OB_FONT: case OB_CURVES_LEGACY: case OB_MBALL: diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index ec270c8ba9bf..7f544612d296 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -8,16 +8,33 @@ #include #include +#include "DNA_scene_types.h" #include "BKE_material.h" +#include "BLI_path_util.h" +#include "BKE_modifier.h" +#include "DNA_fluid_types.h" #include "BKE_volume.h" #include "BLI_index_range.hh" +#include "BKE_object.h" #include "DNA_volume_types.h" +#include "BKE_mesh.hh" #include "blender_scene_delegate.h" #include "volume.h" +PXR_NAMESPACE_OPEN_SCOPE +TF_DEFINE_PRIVATE_TOKENS(grid_tokens_, + (density)(flame)(shadow)(temperature)(velocity)); +PXR_NAMESPACE_CLOSE_SCOPE + namespace blender::render::hydra { +const Set supported_grids = {pxr::grid_tokens_->density, + pxr::grid_tokens_->flame, + pxr::grid_tokens_->shadow, + pxr::grid_tokens_->temperature, + pxr::grid_tokens_->velocity}; + VolumeData::VolumeData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id) @@ -25,33 +42,22 @@ VolumeData::VolumeData(BlenderSceneDelegate *scene_delegate, { } +bool VolumeData::is_volume_modifier(Object *object) { + FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( + object, eModifierType_Fluid); + return volume_modifier && volume_modifier->type & MOD_FLUID_TYPE_DOMAIN && volume_modifier->domain->type == FLUID_DOMAIN_TYPE_GAS; +} + void VolumeData::init() { 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; + if (is_volume_modifier((Object *)this->id)) { + init_from_modifier(); } - 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)); - } - } + else + { + init_from_volume(); } - write_transform(); - write_materials(); - - BKE_volume_unload(volume); } void VolumeData::insert() @@ -92,6 +98,13 @@ void VolumeData::update() } if (id->recalc & ID_RECALC_TRANSFORM) { write_transform(); + if (is_volume_modifier(object)) { + Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); + transform *= pxr::GfMatrix4d(1.0).SetTranslate(pxr::GfVec3d(mesh->texspace_location[0] - 1, + mesh->texspace_location[1] - 1, + mesh->texspace_location[2] - 1)); + BKE_object_to_mesh_clear(object); + } bits |= pxr::HdChangeTracker::DirtyTransform; } @@ -176,4 +189,101 @@ void VolumeData::write_materials() } } +std::string VolumeData::get_cached_file_path(std::string directory, int frame) +{ + char file_path[FILE_MAX]; + char file_name[32]; + strcat(strcat(strcpy(file_name, FLUID_NAME_DATA), "_####"), FLUID_DOMAIN_EXTENSION_OPENVDB); + BLI_path_frame(file_name, sizeof(file_name), frame, 0); + BLI_path_join(file_path, sizeof(file_path), directory.c_str(), FLUID_DOMAIN_DIR_DATA, file_name); + + return file_path; +} + +void VolumeData::init_from_modifier() { + Object *object = (Object *)this->id; + FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( + object, eModifierType_Fluid); + Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); + write_transform(); + + float dims[3]; + BKE_object_dimensions_get(object, dims); + + double x = 0.0; + double y = 0.0; + double z = 0.0; + + //if (mesh->texspace_size[0] != 1.0) { + // x += mesh->texspace_size[0] * mesh->texspace_location[0] / 4; + //} + //if (mesh->texspace_size[1] != 1.0) { + // y += mesh->texspace_size[1] * mesh->texspace_location[1] / 4; + //} + //if (mesh->texspace_size[2] != 1.0) { + // z += mesh->texspace_size[2] * mesh->texspace_location[2] / 4; + //} + if (mesh->texspace_size[0] != 1.0) { + x = mesh->texspace_size[0] * dims[0] * mesh->texspace_location[0] / 2; + } + if (mesh->texspace_size[1] != 1.0) { + y = mesh->texspace_size[1] * dims[1] * mesh->texspace_location[1] / 2; + } + if (mesh->texspace_size[2] != 1.0) { + z = mesh->texspace_size[2] * dims[2] * mesh->texspace_location[2] / 2; + } + //pxr::GfMatrix4d loc = pxr::GfMatrix4d(1.0).SetTranslate(pxr::GfVec3d(mesh->texspace_location) - pxr::GfVec3d(x, y, z)); + pxr::GfMatrix4d loc = pxr::GfMatrix4d(1.0).SetTranslate( + pxr::GfVec3d(mesh->texspace_location) - pxr::GfVec3d(1.0 * mesh->texspace_size[0], + 1.0 * mesh->texspace_size[1], + 1.0 * mesh->texspace_size[2])); + pxr::GfMatrix4d size = pxr::GfMatrix4d(1.0).SetScale(pxr::GfVec3d(mesh->texspace_size)); + pxr::GfMatrix4d trans = pxr::GfMatrix4d(1.0).SetTranslate(pxr::GfVec3d(-x, -y, -z)); + //transform *= loc * size * trans; + + + pxr::GfMatrix4d scale = pxr::GfMatrix4d(1.0).SetScale(pxr::GfVec3d( + dims[0] / object->scale[0] / 2, dims[1] / object->scale[1] / 2, dims[2] / object->scale[2] / 2)); + + transform = transform * size * loc; // * trans;// * size; + + + BKE_object_to_mesh_clear(object); + filepath_ = get_cached_file_path(volume_modifier->domain->cache_directory, + scene_delegate_->scene->r.cfra); + for (auto &grid_name : supported_grids) { + field_descriptors_.emplace_back(grid_name, + pxr::UsdVolImagingTokens->openvdbAsset, + prim_id.AppendElementString("VF_" + grid_name.GetString())); + } + write_materials(); +} + +void VolumeData::init_from_volume() +{ + 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 (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)); + } + } + } + BKE_volume_unload(volume); + write_transform(); + write_materials(); +} + } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/volume.h b/source/blender/render/hydra/scene_delegate/volume.h index dba00d2521c4..932a39f3102e 100644 --- a/source/blender/render/hydra/scene_delegate/volume.h +++ b/source/blender/render/hydra/scene_delegate/volume.h @@ -5,6 +5,8 @@ #include +#include "BLI_set.hh" + #include "object.h" namespace blender::render::hydra { @@ -13,6 +15,7 @@ class VolumeData : public ObjectData { public: VolumeData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); + static bool is_volume_modifier(Object *object); void init() override; void insert() override; @@ -28,6 +31,9 @@ class VolumeData : public ObjectData { private: void write_materials(); + std::string get_cached_file_path(std::string directory, int frame); + void init_from_modifier(); + void init_from_volume(); std::string filepath_; pxr::HdVolumeFieldDescriptorVector field_descriptors_; -- 2.30.2 From 7980b32c00205b1e8ee3d4eae6080780b39641ab Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 7 Jul 2023 18:04:32 +0300 Subject: [PATCH 02/23] code clean up --- .../render/hydra/scene_delegate/volume.cc | 57 +------------------ 1 file changed, 2 insertions(+), 55 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index 7f544612d296..b38161103a5a 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -58,6 +58,8 @@ void VolumeData::init() { init_from_volume(); } + write_transform(); + write_materials(); } void VolumeData::insert() @@ -98,13 +100,6 @@ void VolumeData::update() } if (id->recalc & ID_RECALC_TRANSFORM) { write_transform(); - if (is_volume_modifier(object)) { - Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); - transform *= pxr::GfMatrix4d(1.0).SetTranslate(pxr::GfVec3d(mesh->texspace_location[0] - 1, - mesh->texspace_location[1] - 1, - mesh->texspace_location[2] - 1)); - BKE_object_to_mesh_clear(object); - } bits |= pxr::HdChangeTracker::DirtyTransform; } @@ -204,51 +199,6 @@ void VolumeData::init_from_modifier() { Object *object = (Object *)this->id; FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( object, eModifierType_Fluid); - Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); - write_transform(); - - float dims[3]; - BKE_object_dimensions_get(object, dims); - - double x = 0.0; - double y = 0.0; - double z = 0.0; - - //if (mesh->texspace_size[0] != 1.0) { - // x += mesh->texspace_size[0] * mesh->texspace_location[0] / 4; - //} - //if (mesh->texspace_size[1] != 1.0) { - // y += mesh->texspace_size[1] * mesh->texspace_location[1] / 4; - //} - //if (mesh->texspace_size[2] != 1.0) { - // z += mesh->texspace_size[2] * mesh->texspace_location[2] / 4; - //} - if (mesh->texspace_size[0] != 1.0) { - x = mesh->texspace_size[0] * dims[0] * mesh->texspace_location[0] / 2; - } - if (mesh->texspace_size[1] != 1.0) { - y = mesh->texspace_size[1] * dims[1] * mesh->texspace_location[1] / 2; - } - if (mesh->texspace_size[2] != 1.0) { - z = mesh->texspace_size[2] * dims[2] * mesh->texspace_location[2] / 2; - } - //pxr::GfMatrix4d loc = pxr::GfMatrix4d(1.0).SetTranslate(pxr::GfVec3d(mesh->texspace_location) - pxr::GfVec3d(x, y, z)); - pxr::GfMatrix4d loc = pxr::GfMatrix4d(1.0).SetTranslate( - pxr::GfVec3d(mesh->texspace_location) - pxr::GfVec3d(1.0 * mesh->texspace_size[0], - 1.0 * mesh->texspace_size[1], - 1.0 * mesh->texspace_size[2])); - pxr::GfMatrix4d size = pxr::GfMatrix4d(1.0).SetScale(pxr::GfVec3d(mesh->texspace_size)); - pxr::GfMatrix4d trans = pxr::GfMatrix4d(1.0).SetTranslate(pxr::GfVec3d(-x, -y, -z)); - //transform *= loc * size * trans; - - - pxr::GfMatrix4d scale = pxr::GfMatrix4d(1.0).SetScale(pxr::GfVec3d( - dims[0] / object->scale[0] / 2, dims[1] / object->scale[1] / 2, dims[2] / object->scale[2] / 2)); - - transform = transform * size * loc; // * trans;// * size; - - - BKE_object_to_mesh_clear(object); filepath_ = get_cached_file_path(volume_modifier->domain->cache_directory, scene_delegate_->scene->r.cfra); for (auto &grid_name : supported_grids) { @@ -256,7 +206,6 @@ void VolumeData::init_from_modifier() { pxr::UsdVolImagingTokens->openvdbAsset, prim_id.AppendElementString("VF_" + grid_name.GetString())); } - write_materials(); } void VolumeData::init_from_volume() @@ -282,8 +231,6 @@ void VolumeData::init_from_volume() } } BKE_volume_unload(volume); - write_transform(); - write_materials(); } } // namespace blender::render::hydra -- 2.30.2 From ed7a7123718bd254505295602227ba66aa0badbb Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 7 Jul 2023 18:17:46 +0300 Subject: [PATCH 03/23] make format & code clean up --- .../render/hydra/scene_delegate/image.cc | 2 +- .../render/hydra/scene_delegate/object.cc | 4 +--- .../render/hydra/scene_delegate/volume.cc | 23 +++++++++---------- .../render/hydra/scene_delegate/volume.h | 2 -- .../render/hydra/scene_delegate/world.cc | 7 ++---- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index c737cf333cc5..97dcf9a728ca 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -45,7 +45,7 @@ static std::string cache_image_file(Image *image, BKE_image_path_ext_from_imformat(&scene->r.im_format, &r_ext); opts.im_format = scene->r.im_format; } - + snprintf(file_name, sizeof(file_name), "img_%016llx%s", (uintptr_t)image, r_ext); file_path = get_cache_file(file_name); diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 5103728157a4..909215ca1883 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -3,7 +3,6 @@ #include "BKE_object.h" -#include "DNA_scene_types.h" #include "DEG_depsgraph_query.h" #include "blender_scene_delegate.h" @@ -28,8 +27,7 @@ std::unique_ptr ObjectData::create(BlenderSceneDelegate *scene_deleg { std::unique_ptr data; - if (VolumeData::is_volume_modifier(object)) - { + if (VolumeData::is_volume_modifier(object)) { return std::make_unique(scene_delegate, object, prim_id); } diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index b38161103a5a..c79d8c23a70a 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -8,23 +8,20 @@ #include #include -#include "DNA_scene_types.h" #include "BKE_material.h" -#include "BLI_path_util.h" #include "BKE_modifier.h" -#include "DNA_fluid_types.h" #include "BKE_volume.h" #include "BLI_index_range.hh" -#include "BKE_object.h" +#include "BLI_path_util.h" +#include "DNA_fluid_types.h" +#include "DNA_scene_types.h" #include "DNA_volume_types.h" -#include "BKE_mesh.hh" #include "blender_scene_delegate.h" #include "volume.h" PXR_NAMESPACE_OPEN_SCOPE -TF_DEFINE_PRIVATE_TOKENS(grid_tokens_, - (density)(flame)(shadow)(temperature)(velocity)); +TF_DEFINE_PRIVATE_TOKENS(grid_tokens_, (density)(flame)(shadow)(temperature)(velocity)); PXR_NAMESPACE_CLOSE_SCOPE namespace blender::render::hydra { @@ -42,10 +39,12 @@ VolumeData::VolumeData(BlenderSceneDelegate *scene_delegate, { } -bool VolumeData::is_volume_modifier(Object *object) { +bool VolumeData::is_volume_modifier(Object *object) +{ FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( object, eModifierType_Fluid); - return volume_modifier && volume_modifier->type & MOD_FLUID_TYPE_DOMAIN && volume_modifier->domain->type == FLUID_DOMAIN_TYPE_GAS; + return volume_modifier && volume_modifier->type & MOD_FLUID_TYPE_DOMAIN && + volume_modifier->domain->type == FLUID_DOMAIN_TYPE_GAS; } void VolumeData::init() @@ -54,8 +53,7 @@ void VolumeData::init() if (is_volume_modifier((Object *)this->id)) { init_from_modifier(); } - else - { + else { init_from_volume(); } write_transform(); @@ -195,7 +193,8 @@ std::string VolumeData::get_cached_file_path(std::string directory, int frame) return file_path; } -void VolumeData::init_from_modifier() { +void VolumeData::init_from_modifier() +{ Object *object = (Object *)this->id; FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( object, eModifierType_Fluid); diff --git a/source/blender/render/hydra/scene_delegate/volume.h b/source/blender/render/hydra/scene_delegate/volume.h index 932a39f3102e..ac96606b9719 100644 --- a/source/blender/render/hydra/scene_delegate/volume.h +++ b/source/blender/render/hydra/scene_delegate/volume.h @@ -5,8 +5,6 @@ #include -#include "BLI_set.hh" - #include "object.h" namespace blender::render::hydra { diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 511756cd3936..c7f7aa746286 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -176,11 +176,8 @@ void WorldData::write_transform() { transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d()); - transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), - pxr::GfVec3d()); - transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), - pxr::GfVec3d()); - + transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), pxr::GfVec3d()); + transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), pxr::GfVec3d()); } } // namespace blender::render::hydra -- 2.30.2 From 78ce3215d0aec14b8862c14a9e5611ed7cdd1df8 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 7 Jul 2023 18:19:34 +0300 Subject: [PATCH 04/23] code clean up --- source/blender/render/hydra/scene_delegate/object.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 909215ca1883..3ba788043737 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -2,7 +2,6 @@ * Copyright 2011-2022 Blender Foundation */ #include "BKE_object.h" - #include "DEG_depsgraph_query.h" #include "blender_scene_delegate.h" @@ -32,8 +31,8 @@ std::unique_ptr ObjectData::create(BlenderSceneDelegate *scene_deleg } switch (object->type) { - case OB_SURF: case OB_MESH: + case OB_SURF: case OB_FONT: case OB_CURVES_LEGACY: case OB_MBALL: -- 2.30.2 From 1a55b483673c98000f7fb3c68f5a9a2fba43dbdb Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 10 Jul 2023 22:23:49 +0300 Subject: [PATCH 05/23] fixed transform --- intern/cycles/scene/object.cpp | 1 + .../render/hydra/scene_delegate/volume.cc | 32 ++++++++++++++++++- .../render/hydra/scene_delegate/volume.h | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/intern/cycles/scene/object.cpp b/intern/cycles/scene/object.cpp index 1f000d4dcada..2f821ccc2bc0 100644 --- a/intern/cycles/scene/object.cpp +++ b/intern/cycles/scene/object.cpp @@ -344,6 +344,7 @@ float Object::compute_volume_step_size() const /* Step size is transformed from voxel to world space. */ Transform voxel_tfm = tfm; if (metadata.use_transform_3d) { + voxel_tfm = tfm * transform_inverse(metadata.transform_3d); } voxel_step_size = reduce_min(fabs(transform_direction(&voxel_tfm, size))); diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index c79d8c23a70a..984a6b71ba89 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -7,12 +7,16 @@ #include #include #include +#include +#include #include "BKE_material.h" +#include "BKE_object.h" #include "BKE_modifier.h" #include "BKE_volume.h" #include "BLI_index_range.hh" #include "BLI_path_util.h" +#include "BLI_math_rotation.h" #include "DNA_fluid_types.h" #include "DNA_scene_types.h" #include "DNA_volume_types.h" @@ -50,13 +54,14 @@ bool VolumeData::is_volume_modifier(Object *object) void VolumeData::init() { ID_LOG(1, ""); + write_transform(); if (is_volume_modifier((Object *)this->id)) { init_from_modifier(); } else { init_from_volume(); } - write_transform(); + write_materials(); } @@ -98,6 +103,7 @@ void VolumeData::update() } if (id->recalc & ID_RECALC_TRANSFORM) { write_transform(); + assign_volume_transform(); bits |= pxr::HdChangeTracker::DirtyTransform; } @@ -200,6 +206,9 @@ void VolumeData::init_from_modifier() object, eModifierType_Fluid); filepath_ = get_cached_file_path(volume_modifier->domain->cache_directory, scene_delegate_->scene->r.cfra); + + assign_volume_transform(); + for (auto &grid_name : supported_grids) { field_descriptors_.emplace_back(grid_name, pxr::UsdVolImagingTokens->openvdbAsset, @@ -232,4 +241,25 @@ void VolumeData::init_from_volume() BKE_volume_unload(volume); } +void VolumeData::assign_volume_transform() { + Object *object = (Object *)this->id; + auto mod = pxr::GfMatrix4d(1.0f).SetScale(0.5) * + pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(0.5)); + auto det = mod.GetDeterminant(); + auto inversed = mod.GetInverse(&det); + + float scale[3] = {0.5f, 0.5f, 0.5f}; + if (object->scale[0] != 0.0f) { + scale[0] = 0.5f / object->scale[0]; + } + if (object->scale[1] != 0.0f) { + scale[1] = 0.5f / object->scale[1]; + } + if (object->scale[2] != 0.0f) { + scale[2] = 0.5f / object->scale[2]; + } + auto scale_matrix = pxr::GfMatrix4d(1.0f).SetScale(pxr::GfVec3d(scale[0], scale[1], scale[2])); + transform = scale_matrix * inversed * transform; +} + } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/volume.h b/source/blender/render/hydra/scene_delegate/volume.h index ac96606b9719..3c84ab4c1a31 100644 --- a/source/blender/render/hydra/scene_delegate/volume.h +++ b/source/blender/render/hydra/scene_delegate/volume.h @@ -32,6 +32,7 @@ class VolumeData : public ObjectData { std::string get_cached_file_path(std::string directory, int frame); void init_from_modifier(); void init_from_volume(); + void assign_volume_transform(); std::string filepath_; pxr::HdVolumeFieldDescriptorVector field_descriptors_; -- 2.30.2 From c7293b288dd95dc3bdf291a88e567f373e4cca41 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 11 Jul 2023 14:01:42 +0300 Subject: [PATCH 06/23] added texture coordinates transform --- .../blender/render/hydra/scene_delegate/volume.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index 984a6b71ba89..2861d5977d67 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -11,6 +11,7 @@ #include #include "BKE_material.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_modifier.h" #include "BKE_volume.h" @@ -243,6 +244,8 @@ void VolumeData::init_from_volume() void VolumeData::assign_volume_transform() { Object *object = (Object *)this->id; + Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); + auto mod = pxr::GfMatrix4d(1.0f).SetScale(0.5) * pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(0.5)); auto det = mod.GetDeterminant(); @@ -259,7 +262,15 @@ void VolumeData::assign_volume_transform() { scale[2] = 0.5f / object->scale[2]; } auto scale_matrix = pxr::GfMatrix4d(1.0f).SetScale(pxr::GfVec3d(scale[0], scale[1], scale[2])); - transform = scale_matrix * inversed * transform; + auto texture_trans = pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(mesh->texspace_location[0], + mesh->texspace_location[1], + mesh->texspace_location[2])); + auto texture_scale = pxr::GfMatrix4d(1.0f).SetScale(pxr::GfVec3d(mesh->texspace_size[0], + mesh->texspace_size[1], + mesh->texspace_size[2])); + transform = scale_matrix * inversed * texture_scale * texture_trans * transform; + + BKE_object_to_mesh_clear(object); } } // namespace blender::render::hydra -- 2.30.2 From 451175ad180b76b3cdba51b2f73c9c8a8b9df648 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 11 Jul 2023 17:41:40 +0300 Subject: [PATCH 07/23] clean up --- intern/cycles/scene/object.cpp | 1 - .../render/hydra/scene_delegate/image.cc | 1 - .../render/hydra/scene_delegate/volume.cc | 20 +++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/intern/cycles/scene/object.cpp b/intern/cycles/scene/object.cpp index 2f821ccc2bc0..1f000d4dcada 100644 --- a/intern/cycles/scene/object.cpp +++ b/intern/cycles/scene/object.cpp @@ -344,7 +344,6 @@ float Object::compute_volume_step_size() const /* Step size is transformed from voxel to world space. */ Transform voxel_tfm = tfm; if (metadata.use_transform_3d) { - voxel_tfm = tfm * transform_inverse(metadata.transform_3d); } voxel_step_size = reduce_min(fabs(transform_direction(&voxel_tfm, size))); diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index 97dcf9a728ca..7a91028a7ce1 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -45,7 +45,6 @@ static std::string cache_image_file(Image *image, BKE_image_path_ext_from_imformat(&scene->r.im_format, &r_ext); opts.im_format = scene->r.im_format; } - snprintf(file_name, sizeof(file_name), "img_%016llx%s", (uintptr_t)image, r_ext); file_path = get_cache_file(file_name); diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index 2861d5977d67..642a6394a4f5 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -208,13 +208,13 @@ void VolumeData::init_from_modifier() filepath_ = get_cached_file_path(volume_modifier->domain->cache_directory, scene_delegate_->scene->r.cfra); - assign_volume_transform(); - for (auto &grid_name : supported_grids) { field_descriptors_.emplace_back(grid_name, pxr::UsdVolImagingTokens->openvdbAsset, prim_id.AppendElementString("VF_" + grid_name.GetString())); } + + assign_volume_transform(); } void VolumeData::init_from_volume() @@ -246,10 +246,10 @@ void VolumeData::assign_volume_transform() { Object *object = (Object *)this->id; Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); - auto mod = pxr::GfMatrix4d(1.0f).SetScale(0.5) * + pxr::GfMatrix4d fixed_transform = pxr::GfMatrix4d(1.0f).SetScale(0.5) * pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(0.5)); - auto det = mod.GetDeterminant(); - auto inversed = mod.GetInverse(&det); + double det = fixed_transform.GetDeterminant(); + pxr::GfMatrix4d inversed = fixed_transform.GetInverse(&det); float scale[3] = {0.5f, 0.5f, 0.5f}; if (object->scale[0] != 0.0f) { @@ -261,13 +261,17 @@ void VolumeData::assign_volume_transform() { if (object->scale[2] != 0.0f) { scale[2] = 0.5f / object->scale[2]; } - auto scale_matrix = pxr::GfMatrix4d(1.0f).SetScale(pxr::GfVec3d(scale[0], scale[1], scale[2])); - auto texture_trans = pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(mesh->texspace_location[0], + pxr::GfMatrix4d scale_matrix = pxr::GfMatrix4d(1.0f).SetScale( + pxr::GfVec3d(scale[0], scale[1], scale[2])); + pxr::GfMatrix4d texture_trans = pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d( + mesh->texspace_location[0], mesh->texspace_location[1], mesh->texspace_location[2])); - auto texture_scale = pxr::GfMatrix4d(1.0f).SetScale(pxr::GfVec3d(mesh->texspace_size[0], + pxr::GfMatrix4d texture_scale = pxr::GfMatrix4d(1.0f).SetScale( + pxr::GfVec3d(mesh->texspace_size[0], mesh->texspace_size[1], mesh->texspace_size[2])); + transform = scale_matrix * inversed * texture_scale * texture_trans * transform; BKE_object_to_mesh_clear(object); -- 2.30.2 From 69345afd331361df9897fce00df40e92dba2b51b Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 11 Jul 2023 17:46:31 +0300 Subject: [PATCH 08/23] make format removed unused imports --- .../render/hydra/scene_delegate/volume.cc | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index 642a6394a4f5..26412c25649b 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -7,17 +7,14 @@ #include #include #include -#include -#include #include "BKE_material.h" #include "BKE_mesh.hh" -#include "BKE_object.h" #include "BKE_modifier.h" +#include "BKE_object.h" #include "BKE_volume.h" #include "BLI_index_range.hh" #include "BLI_path_util.h" -#include "BLI_math_rotation.h" #include "DNA_fluid_types.h" #include "DNA_scene_types.h" #include "DNA_volume_types.h" @@ -62,7 +59,7 @@ void VolumeData::init() else { init_from_volume(); } - + write_materials(); } @@ -242,12 +239,13 @@ void VolumeData::init_from_volume() BKE_volume_unload(volume); } -void VolumeData::assign_volume_transform() { +void VolumeData::assign_volume_transform() +{ Object *object = (Object *)this->id; Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); - + pxr::GfMatrix4d fixed_transform = pxr::GfMatrix4d(1.0f).SetScale(0.5) * - pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(0.5)); + pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(0.5)); double det = fixed_transform.GetDeterminant(); pxr::GfMatrix4d inversed = fixed_transform.GetInverse(&det); @@ -264,13 +262,9 @@ void VolumeData::assign_volume_transform() { pxr::GfMatrix4d scale_matrix = pxr::GfMatrix4d(1.0f).SetScale( pxr::GfVec3d(scale[0], scale[1], scale[2])); pxr::GfMatrix4d texture_trans = pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d( - mesh->texspace_location[0], - mesh->texspace_location[1], - mesh->texspace_location[2])); + mesh->texspace_location[0], mesh->texspace_location[1], mesh->texspace_location[2])); pxr::GfMatrix4d texture_scale = pxr::GfMatrix4d(1.0f).SetScale( - pxr::GfVec3d(mesh->texspace_size[0], - mesh->texspace_size[1], - mesh->texspace_size[2])); + pxr::GfVec3d(mesh->texspace_size[0], mesh->texspace_size[1], mesh->texspace_size[2])); transform = scale_matrix * inversed * texture_scale * texture_trans * transform; -- 2.30.2 From d14c1c72abd8f6be87d920a9db0806cd09021770 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 11 Jul 2023 18:05:49 +0300 Subject: [PATCH 09/23] added warning for cache format --- source/blender/render/hydra/scene_delegate/volume.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index 26412c25649b..66d3faf817a6 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -202,6 +202,12 @@ void VolumeData::init_from_modifier() Object *object = (Object *)this->id; FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( object, eModifierType_Fluid); + + if ((volume_modifier->domain->cache_data_format & FLUID_DOMAIN_FILE_OPENVDB) == 0) { + CLOG_WARN(LOG_RENDER_HYDRA_SCENE, "Volume %s is't exported: only OpenVDB file format supported", prim_id.GetText()); + return; + } + filepath_ = get_cached_file_path(volume_modifier->domain->cache_directory, scene_delegate_->scene->r.cfra); -- 2.30.2 From deec41d30885f6cf03d4fd6ef931e495be3663b7 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 11 Jul 2023 18:06:24 +0300 Subject: [PATCH 10/23] make format --- source/blender/render/hydra/scene_delegate/volume.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index 66d3faf817a6..fbf073987851 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -204,7 +204,9 @@ void VolumeData::init_from_modifier() object, eModifierType_Fluid); if ((volume_modifier->domain->cache_data_format & FLUID_DOMAIN_FILE_OPENVDB) == 0) { - CLOG_WARN(LOG_RENDER_HYDRA_SCENE, "Volume %s is't exported: only OpenVDB file format supported", prim_id.GetText()); + CLOG_WARN(LOG_RENDER_HYDRA_SCENE, + "Volume %s is't exported: only OpenVDB file format supported", + prim_id.GetText()); return; } -- 2.30.2 From 98a8a4b7142a419e6804391eb4f2ca5ebf16c0ca Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 11 Jul 2023 18:07:08 +0300 Subject: [PATCH 11/23] clean up --- source/blender/render/hydra/scene_delegate/image.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index 7a91028a7ce1..97dcf9a728ca 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -45,6 +45,7 @@ static std::string cache_image_file(Image *image, BKE_image_path_ext_from_imformat(&scene->r.im_format, &r_ext); opts.im_format = scene->r.im_format; } + snprintf(file_name, sizeof(file_name), "img_%016llx%s", (uintptr_t)image, r_ext); file_path = get_cache_file(file_name); -- 2.30.2 From da26fad91b8b58ca27a7d5e81ac8a2dca2525564 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 12 Jul 2023 12:54:31 +0300 Subject: [PATCH 12/23] moved to separated class VolumeModifierData --- source/blender/render/hydra/CMakeLists.txt | 2 + .../scene_delegate/blender_scene_delegate.h | 1 + .../render/hydra/scene_delegate/object.cc | 4 +- .../render/hydra/scene_delegate/object.h | 2 +- .../render/hydra/scene_delegate/volume.cc | 145 +++--------------- .../render/hydra/scene_delegate/volume.h | 7 +- .../hydra/scene_delegate/volume_modifier.cc | 124 +++++++++++++++ .../hydra/scene_delegate/volume_modifier.h | 28 ++++ 8 files changed, 180 insertions(+), 133 deletions(-) create mode 100644 source/blender/render/hydra/scene_delegate/volume_modifier.cc create mode 100644 source/blender/render/hydra/scene_delegate/volume_modifier.h diff --git a/source/blender/render/hydra/CMakeLists.txt b/source/blender/render/hydra/CMakeLists.txt index bee162760ba9..4a29385c23ad 100644 --- a/source/blender/render/hydra/CMakeLists.txt +++ b/source/blender/render/hydra/CMakeLists.txt @@ -89,6 +89,8 @@ set(SRC scene_delegate/image.cc scene_delegate/volume.h scene_delegate/volume.cc + scene_delegate/volume_modifier.h + scene_delegate/volume_modifier.cc ) set(LIB diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 156b220b23ab..2f2ff0e97c7d 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -18,6 +18,7 @@ #include "mesh.h" #include "object.h" #include "volume.h" +#include "volume_modifier.h" #include "world.h" namespace blender::render::hydra { diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index a0af04dce09f..d393bd52c908 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -25,8 +25,8 @@ std::unique_ptr ObjectData::create(BlenderSceneDelegate *scene_deleg { std::unique_ptr data; - if (VolumeData::is_volume_modifier(object)) { - return std::make_unique(scene_delegate, object, prim_id); + if (VolumeModifierData::is_volume_modifier(object)) { + return std::make_unique(scene_delegate, object, prim_id); } switch (object->type) { diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index 1a31a0cbf245..cfde9caf1589 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -34,7 +34,7 @@ class ObjectData : public IdData { bool visible = true; protected: - void write_transform(); + virtual void write_transform(); }; using ObjectDataMap = Map>; diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index fbf073987851..ec270c8ba9bf 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -9,31 +9,15 @@ #include #include "BKE_material.h" -#include "BKE_mesh.hh" -#include "BKE_modifier.h" -#include "BKE_object.h" #include "BKE_volume.h" #include "BLI_index_range.hh" -#include "BLI_path_util.h" -#include "DNA_fluid_types.h" -#include "DNA_scene_types.h" #include "DNA_volume_types.h" #include "blender_scene_delegate.h" #include "volume.h" -PXR_NAMESPACE_OPEN_SCOPE -TF_DEFINE_PRIVATE_TOKENS(grid_tokens_, (density)(flame)(shadow)(temperature)(velocity)); -PXR_NAMESPACE_CLOSE_SCOPE - namespace blender::render::hydra { -const Set supported_grids = {pxr::grid_tokens_->density, - pxr::grid_tokens_->flame, - pxr::grid_tokens_->shadow, - pxr::grid_tokens_->temperature, - pxr::grid_tokens_->velocity}; - VolumeData::VolumeData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id) @@ -41,26 +25,33 @@ VolumeData::VolumeData(BlenderSceneDelegate *scene_delegate, { } -bool VolumeData::is_volume_modifier(Object *object) -{ - FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( - object, eModifierType_Fluid); - return volume_modifier && volume_modifier->type & MOD_FLUID_TYPE_DOMAIN && - volume_modifier->domain->type == FLUID_DOMAIN_TYPE_GAS; -} - void VolumeData::init() { ID_LOG(1, ""); - write_transform(); - if (is_volume_modifier((Object *)this->id)) { - init_from_modifier(); - } - else { - init_from_volume(); + 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 (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_materials(); + + BKE_volume_unload(volume); } void VolumeData::insert() @@ -101,7 +92,6 @@ void VolumeData::update() } if (id->recalc & ID_RECALC_TRANSFORM) { write_transform(); - assign_volume_transform(); bits |= pxr::HdChangeTracker::DirtyTransform; } @@ -186,97 +176,4 @@ void VolumeData::write_materials() } } -std::string VolumeData::get_cached_file_path(std::string directory, int frame) -{ - char file_path[FILE_MAX]; - char file_name[32]; - strcat(strcat(strcpy(file_name, FLUID_NAME_DATA), "_####"), FLUID_DOMAIN_EXTENSION_OPENVDB); - BLI_path_frame(file_name, sizeof(file_name), frame, 0); - BLI_path_join(file_path, sizeof(file_path), directory.c_str(), FLUID_DOMAIN_DIR_DATA, file_name); - - return file_path; -} - -void VolumeData::init_from_modifier() -{ - Object *object = (Object *)this->id; - FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( - object, eModifierType_Fluid); - - if ((volume_modifier->domain->cache_data_format & FLUID_DOMAIN_FILE_OPENVDB) == 0) { - CLOG_WARN(LOG_RENDER_HYDRA_SCENE, - "Volume %s is't exported: only OpenVDB file format supported", - prim_id.GetText()); - return; - } - - filepath_ = get_cached_file_path(volume_modifier->domain->cache_directory, - scene_delegate_->scene->r.cfra); - - for (auto &grid_name : supported_grids) { - field_descriptors_.emplace_back(grid_name, - pxr::UsdVolImagingTokens->openvdbAsset, - prim_id.AppendElementString("VF_" + grid_name.GetString())); - } - - assign_volume_transform(); -} - -void VolumeData::init_from_volume() -{ - 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 (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)); - } - } - } - BKE_volume_unload(volume); -} - -void VolumeData::assign_volume_transform() -{ - Object *object = (Object *)this->id; - Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); - - pxr::GfMatrix4d fixed_transform = pxr::GfMatrix4d(1.0f).SetScale(0.5) * - pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(0.5)); - double det = fixed_transform.GetDeterminant(); - pxr::GfMatrix4d inversed = fixed_transform.GetInverse(&det); - - float scale[3] = {0.5f, 0.5f, 0.5f}; - if (object->scale[0] != 0.0f) { - scale[0] = 0.5f / object->scale[0]; - } - if (object->scale[1] != 0.0f) { - scale[1] = 0.5f / object->scale[1]; - } - if (object->scale[2] != 0.0f) { - scale[2] = 0.5f / object->scale[2]; - } - pxr::GfMatrix4d scale_matrix = pxr::GfMatrix4d(1.0f).SetScale( - pxr::GfVec3d(scale[0], scale[1], scale[2])); - pxr::GfMatrix4d texture_trans = pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d( - mesh->texspace_location[0], mesh->texspace_location[1], mesh->texspace_location[2])); - pxr::GfMatrix4d texture_scale = pxr::GfMatrix4d(1.0f).SetScale( - pxr::GfVec3d(mesh->texspace_size[0], mesh->texspace_size[1], mesh->texspace_size[2])); - - transform = scale_matrix * inversed * texture_scale * texture_trans * transform; - - BKE_object_to_mesh_clear(object); -} - } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/volume.h b/source/blender/render/hydra/scene_delegate/volume.h index 3c84ab4c1a31..b010af96b433 100644 --- a/source/blender/render/hydra/scene_delegate/volume.h +++ b/source/blender/render/hydra/scene_delegate/volume.h @@ -13,7 +13,6 @@ class VolumeData : public ObjectData { public: VolumeData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); - static bool is_volume_modifier(Object *object); void init() override; void insert() override; @@ -27,12 +26,8 @@ class VolumeData : public ObjectData { pxr::SdfPath material_id() const; void available_materials(Set &paths) const; - private: + protected: void write_materials(); - std::string get_cached_file_path(std::string directory, int frame); - void init_from_modifier(); - void init_from_volume(); - void assign_volume_transform(); std::string filepath_; pxr::HdVolumeFieldDescriptorVector field_descriptors_; diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.cc b/source/blender/render/hydra/scene_delegate/volume_modifier.cc new file mode 100644 index 000000000000..4d0351c8561a --- /dev/null +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.cc @@ -0,0 +1,124 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2011-2022 Blender Foundation */ + +#include +#include +#include +#include +#include +#include + +#include "BKE_material.h" +#include "BKE_mesh.hh" +#include "BKE_modifier.h" +#include "BKE_object.h" +#include "BKE_volume.h" +#include "BLI_index_range.hh" +#include "BLI_path_util.h" +#include "DNA_fluid_types.h" +#include "DNA_scene_types.h" +#include "DNA_volume_types.h" + +#include "blender_scene_delegate.h" +#include "volume_modifier.h" + +PXR_NAMESPACE_OPEN_SCOPE +TF_DEFINE_PRIVATE_TOKENS(grid_tokens_, (density)(flame)(shadow)(temperature)(velocity)); +PXR_NAMESPACE_CLOSE_SCOPE + +namespace blender::render::hydra { + +const Set supported_grids = {pxr::grid_tokens_->density, + pxr::grid_tokens_->flame, + pxr::grid_tokens_->shadow, + pxr::grid_tokens_->temperature, + pxr::grid_tokens_->velocity}; + +VolumeModifierData::VolumeModifierData(BlenderSceneDelegate *scene_delegate, + Object *object, + pxr::SdfPath const &prim_id) + : VolumeData(scene_delegate, object, prim_id) +{ +} + +bool VolumeModifierData::is_volume_modifier(Object *object) +{ + FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( + object, eModifierType_Fluid); + return volume_modifier && volume_modifier->type & MOD_FLUID_TYPE_DOMAIN && + volume_modifier->domain->type == FLUID_DOMAIN_TYPE_GAS; +} + +void VolumeModifierData::init() +{ + ID_LOG(1, ""); + + Object *object = (Object *)this->id; + FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( + object, eModifierType_Fluid); + + if ((volume_modifier->domain->cache_data_format & FLUID_DOMAIN_FILE_OPENVDB) == 0) { + CLOG_WARN(LOG_RENDER_HYDRA_SCENE, + "Volume %s is't exported: only OpenVDB file format supported", + prim_id.GetText()); + return; + } + + filepath_ = get_cached_file_path(volume_modifier->domain->cache_directory, + scene_delegate_->scene->r.cfra); + + for (auto &grid_name : supported_grids) { + field_descriptors_.emplace_back(grid_name, + pxr::UsdVolImagingTokens->openvdbAsset, + prim_id.AppendElementString("VF_" + grid_name.GetString())); + } + + write_transform(); + write_materials(); +} + +void VolumeModifierData::write_transform() +{ + Object *object = (Object *)this->id; + Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); + + pxr::GfMatrix4d fixed_transform = pxr::GfMatrix4d(1.0f).SetScale(0.5) * + pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(0.5)); + double det = fixed_transform.GetDeterminant(); + pxr::GfMatrix4d inversed = fixed_transform.GetInverse(&det); + + float scale[3] = {0.5f, 0.5f, 0.5f}; + if (object->scale[0] != 0.0f) { + scale[0] = 0.5f / object->scale[0]; + } + if (object->scale[1] != 0.0f) { + scale[1] = 0.5f / object->scale[1]; + } + if (object->scale[2] != 0.0f) { + scale[2] = 0.5f / object->scale[2]; + } + pxr::GfMatrix4d scale_matrix = pxr::GfMatrix4d(1.0f).SetScale( + pxr::GfVec3d(scale[0], scale[1], scale[2])); + pxr::GfMatrix4d texture_trans = pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d( + mesh->texspace_location[0], mesh->texspace_location[1], mesh->texspace_location[2])); + pxr::GfMatrix4d texture_scale = pxr::GfMatrix4d(1.0f).SetScale( + pxr::GfVec3d(mesh->texspace_size[0], mesh->texspace_size[1], mesh->texspace_size[2])); + + transform = scale_matrix * inversed * texture_scale * texture_trans * + gf_matrix_from_transform(object->object_to_world); + + BKE_object_to_mesh_clear(object); +} + +std::string VolumeModifierData::get_cached_file_path(std::string directory, int frame) +{ + char file_path[FILE_MAX]; + char file_name[32]; + strcat(strcat(strcpy(file_name, FLUID_NAME_DATA), "_####"), FLUID_DOMAIN_EXTENSION_OPENVDB); + BLI_path_frame(file_name, sizeof(file_name), frame, 0); + BLI_path_join(file_path, sizeof(file_path), directory.c_str(), FLUID_DOMAIN_DIR_DATA, file_name); + + return file_path; +} + +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.h b/source/blender/render/hydra/scene_delegate/volume_modifier.h new file mode 100644 index 000000000000..16f68a85ad2c --- /dev/null +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2011-2022 Blender Foundation */ + +#pragma once + +#include + +#include "object.h" +#include "volume.h" + +namespace blender::render::hydra { + +class VolumeModifierData : public VolumeData { + + public: + VolumeModifierData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); + static bool is_volume_modifier(Object *object); + + void init() override; + + private: + void write_transform() override; + + std::string get_cached_file_path(std::string directory, int frame); + +}; + +} // namespace blender::render::hydra -- 2.30.2 From 9f011a391052c52fbb1fb49c6140e3474e48125f Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 12 Jul 2023 13:13:37 +0300 Subject: [PATCH 13/23] clean up --- .../render/hydra/scene_delegate/volume_modifier.cc | 9 --------- .../render/hydra/scene_delegate/volume_modifier.h | 1 - 2 files changed, 10 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.cc b/source/blender/render/hydra/scene_delegate/volume_modifier.cc index 4d0351c8561a..a0382250cb61 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.cc +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.cc @@ -1,19 +1,10 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ -#include -#include -#include -#include -#include #include -#include "BKE_material.h" #include "BKE_mesh.hh" #include "BKE_modifier.h" -#include "BKE_object.h" -#include "BKE_volume.h" -#include "BLI_index_range.hh" #include "BLI_path_util.h" #include "DNA_fluid_types.h" #include "DNA_scene_types.h" diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.h b/source/blender/render/hydra/scene_delegate/volume_modifier.h index 16f68a85ad2c..719f4ebb351e 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.h +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.h @@ -5,7 +5,6 @@ #include -#include "object.h" #include "volume.h" namespace blender::render::hydra { -- 2.30.2 From 83d68ba1123a355f3bac674800aa43b36aba70a8 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 12 Jul 2023 13:19:40 +0300 Subject: [PATCH 14/23] make format --- .../blender/render/hydra/scene_delegate/volume_modifier.cc | 4 ++-- source/blender/render/hydra/scene_delegate/volume_modifier.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.cc b/source/blender/render/hydra/scene_delegate/volume_modifier.cc index a0382250cb61..20d9a08500e7 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.cc +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.cc @@ -26,8 +26,8 @@ const Set supported_grids = {pxr::grid_tokens_->density, pxr::grid_tokens_->velocity}; VolumeModifierData::VolumeModifierData(BlenderSceneDelegate *scene_delegate, - Object *object, - pxr::SdfPath const &prim_id) + Object *object, + pxr::SdfPath const &prim_id) : VolumeData(scene_delegate, object, prim_id) { } diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.h b/source/blender/render/hydra/scene_delegate/volume_modifier.h index 719f4ebb351e..5c2cc4e4278b 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.h +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.h @@ -12,7 +12,9 @@ namespace blender::render::hydra { class VolumeModifierData : public VolumeData { public: - VolumeModifierData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); + VolumeModifierData(BlenderSceneDelegate *scene_delegate, + Object *object, + pxr::SdfPath const &prim_id); static bool is_volume_modifier(Object *object); void init() override; @@ -21,7 +23,6 @@ class VolumeModifierData : public VolumeData { void write_transform() override; std::string get_cached_file_path(std::string directory, int frame); - }; } // namespace blender::render::hydra -- 2.30.2 From 905c4b31fba93689c95cf32f0f4f0000f34c4f5d Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 12 Jul 2023 14:21:10 +0300 Subject: [PATCH 15/23] simplified code --- .../render/hydra/scene_delegate/volume_modifier.cc | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.cc b/source/blender/render/hydra/scene_delegate/volume_modifier.cc index 20d9a08500e7..24ff31e7270a 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.cc +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.cc @@ -19,12 +19,6 @@ PXR_NAMESPACE_CLOSE_SCOPE namespace blender::render::hydra { -const Set supported_grids = {pxr::grid_tokens_->density, - pxr::grid_tokens_->flame, - pxr::grid_tokens_->shadow, - pxr::grid_tokens_->temperature, - pxr::grid_tokens_->velocity}; - VolumeModifierData::VolumeModifierData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id) @@ -57,8 +51,8 @@ void VolumeModifierData::init() filepath_ = get_cached_file_path(volume_modifier->domain->cache_directory, scene_delegate_->scene->r.cfra); - - for (auto &grid_name : supported_grids) { + + for (auto &grid_name : pxr::grid_tokens_->allTokens) { field_descriptors_.emplace_back(grid_name, pxr::UsdVolImagingTokens->openvdbAsset, prim_id.AppendElementString("VF_" + grid_name.GetString())); -- 2.30.2 From 5a7b814878923695188cc2368dab033e9eb37952 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 12 Jul 2023 14:30:18 +0300 Subject: [PATCH 16/23] refactoring --- source/blender/render/hydra/scene_delegate/mesh.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 312e343028a6..4639d4499849 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -13,7 +13,7 @@ #include "mesh.h" PXR_NAMESPACE_OPEN_SCOPE -TF_DEFINE_PRIVATE_TOKENS(_tokens, (st)); +TF_DEFINE_PRIVATE_TOKENS(tokens_, (st)); PXR_NAMESPACE_CLOSE_SCOPE namespace blender::render::hydra { @@ -89,7 +89,7 @@ pxr::VtValue MeshData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) else if (key == pxr::HdTokens->normals) { return pxr::VtValue(submesh(id).normals); } - else if (key == pxr::_tokens->st) { + else if (key == pxr::tokens_->st) { return pxr::VtValue(submesh(id).uvs); } return pxr::VtValue(); @@ -133,7 +133,7 @@ pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors( } if (!submeshes_[0].uvs.empty()) { primvars.emplace_back( - pxr::_tokens->st, interpolation, pxr::HdPrimvarRoleTokens->textureCoordinate); + pxr::tokens_->st, interpolation, pxr::HdPrimvarRoleTokens->textureCoordinate); } } return primvars; -- 2.30.2 From 475c609b95f8cb8a2587f0829995553079d6d1ec Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Fri, 14 Jul 2023 13:38:00 +0300 Subject: [PATCH 17/23] Fixed write_transform() --- intern/ghost/intern/GHOST_SystemWin32.cc | 2 +- .../hydra/scene_delegate/volume_modifier.cc | 39 +++++++------------ 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/intern/ghost/intern/GHOST_SystemWin32.cc b/intern/ghost/intern/GHOST_SystemWin32.cc index 21b9f33a25d9..3dae6b7914a2 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cc +++ b/intern/ghost/intern/GHOST_SystemWin32.cc @@ -304,7 +304,7 @@ GHOST_IContext *GHOST_SystemWin32::createOffscreenContext(GHOST_GPUSettings gpuS true, wnd, mHDC, - WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 4, minor, (debug_context ? WGL_CONTEXT_DEBUG_BIT_ARB : 0), diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.cc b/source/blender/render/hydra/scene_delegate/volume_modifier.cc index 24ff31e7270a..3990b2a99a44 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.cc +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.cc @@ -65,34 +65,25 @@ void VolumeModifierData::init() void VolumeModifierData::write_transform() { Object *object = (Object *)this->id; - Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); - pxr::GfMatrix4d fixed_transform = pxr::GfMatrix4d(1.0f).SetScale(0.5) * - pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(0.5)); - double det = fixed_transform.GetDeterminant(); - pxr::GfMatrix4d inversed = fixed_transform.GetInverse(&det); - - float scale[3] = {0.5f, 0.5f, 0.5f}; - if (object->scale[0] != 0.0f) { - scale[0] = 0.5f / object->scale[0]; + /* set base scaling */ + float scale[3]; + for (int i = 0; i < 3; ++i) { + scale[i] = (object->scale[i] != 0.0f) ? 1.0f / object->scale[i] : 1.0f; } - if (object->scale[1] != 0.0f) { - scale[1] = 0.5f / object->scale[1]; - } - if (object->scale[2] != 0.0f) { - scale[2] = 0.5f / object->scale[2]; - } - pxr::GfMatrix4d scale_matrix = pxr::GfMatrix4d(1.0f).SetScale( - pxr::GfVec3d(scale[0], scale[1], scale[2])); - pxr::GfMatrix4d texture_trans = pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d( - mesh->texspace_location[0], mesh->texspace_location[1], mesh->texspace_location[2])); - pxr::GfMatrix4d texture_scale = pxr::GfMatrix4d(1.0f).SetScale( - pxr::GfVec3d(mesh->texspace_size[0], mesh->texspace_size[1], mesh->texspace_size[2])); + transform = pxr::GfMatrix4d().SetScale(pxr::GfVec3d(scale)); - transform = scale_matrix * inversed * texture_scale * texture_trans * - gf_matrix_from_transform(object->object_to_world); + /* positioning to center */ + transform *= pxr::GfMatrix4d().SetTranslate(pxr::GfVec3d(-1, -1, -1)); - BKE_object_to_mesh_clear(object); + /* including texspace transform */ + float texspace_loc[3] = {0.0f, 0.0f, 0.0f}, texspace_scale[3] = {1.0f, 1.0f, 1.0f}; + BKE_mesh_texspace_get((Mesh *)object->data, texspace_loc, texspace_scale); + transform *= pxr::GfMatrix4d(1.0f).SetScale(pxr::GfVec3d(texspace_scale)) * + pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(texspace_loc)); + + /* */ + transform *= gf_matrix_from_transform(object->object_to_world); } std::string VolumeModifierData::get_cached_file_path(std::string directory, int frame) -- 2.30.2 From 2168d355cf7a502643e91ddc5be2ab10d0dcab6f Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Fri, 14 Jul 2023 14:01:49 +0300 Subject: [PATCH 18/23] Added VolumeModifierData::update() --- .../hydra/scene_delegate/volume_modifier.cc | 31 +++++++++++++++++++ .../hydra/scene_delegate/volume_modifier.h | 1 + 2 files changed, 32 insertions(+) diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.cc b/source/blender/render/hydra/scene_delegate/volume_modifier.cc index 3990b2a99a44..1fc479d9e7af 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.cc +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.cc @@ -28,6 +28,10 @@ VolumeModifierData::VolumeModifierData(BlenderSceneDelegate *scene_delegate, bool VolumeModifierData::is_volume_modifier(Object *object) { + if (object->type != OB_MESH) { + return false; + } + FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( object, eModifierType_Fluid); return volume_modifier && volume_modifier->type & MOD_FLUID_TYPE_DOMAIN && @@ -62,6 +66,33 @@ void VolumeModifierData::init() write_materials(); } +void VolumeModifierData::update() +{ + Object *object = (Object *)id; + if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) { + remove(); + init(); + insert(); + return; + } + pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; + 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, ""); +} + void VolumeModifierData::write_transform() { Object *object = (Object *)this->id; diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.h b/source/blender/render/hydra/scene_delegate/volume_modifier.h index 5c2cc4e4278b..2a4b8942cdda 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.h +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.h @@ -18,6 +18,7 @@ class VolumeModifierData : public VolumeData { static bool is_volume_modifier(Object *object); void init() override; + void update() override; private: void write_transform() override; -- 2.30.2 From 3fb4129d304b7820b1f5e6e52205f8bed376fa1b Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Fri, 14 Jul 2023 14:59:29 +0300 Subject: [PATCH 19/23] Moved modifier to VolumeModifierData --- .../hydra/scene_delegate/volume_modifier.cc | 25 ++++++++----------- .../hydra/scene_delegate/volume_modifier.h | 4 +++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.cc b/source/blender/render/hydra/scene_delegate/volume_modifier.cc index 1fc479d9e7af..86b452730129 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.cc +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.cc @@ -6,7 +6,6 @@ #include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BLI_path_util.h" -#include "DNA_fluid_types.h" #include "DNA_scene_types.h" #include "DNA_volume_types.h" @@ -32,10 +31,10 @@ bool VolumeModifierData::is_volume_modifier(Object *object) return false; } - FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( + FluidModifierData *modifier = (FluidModifierData *)BKE_modifiers_findby_type( object, eModifierType_Fluid); - return volume_modifier && volume_modifier->type & MOD_FLUID_TYPE_DOMAIN && - volume_modifier->domain->type == FLUID_DOMAIN_TYPE_GAS; + return modifier && modifier->type & MOD_FLUID_TYPE_DOMAIN && + modifier->domain->type == FLUID_DOMAIN_TYPE_GAS; } void VolumeModifierData::init() @@ -43,17 +42,16 @@ void VolumeModifierData::init() ID_LOG(1, ""); Object *object = (Object *)this->id; - FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( - object, eModifierType_Fluid); + modifier_ = (FluidModifierData *)BKE_modifiers_findby_type(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, "Volume %s is't exported: only OpenVDB file format supported", prim_id.GetText()); 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); for (auto &grid_name : pxr::grid_tokens_->allTokens) { @@ -98,12 +96,9 @@ void VolumeModifierData::write_transform() Object *object = (Object *)this->id; /* set base scaling */ - float scale[3]; - for (int i = 0; i < 3; ++i) { - scale[i] = (object->scale[i] != 0.0f) ? 1.0f / object->scale[i] : 1.0f; - } - transform = pxr::GfMatrix4d().SetScale(pxr::GfVec3d(scale)); - + transform = pxr::GfMatrix4d().SetScale(pxr::GfVec3d(1.0f / modifier_->domain->global_size[0], + 1.0f / modifier_->domain->global_size[1], + 1.0f / modifier_->domain->global_size[2])); /* positioning to center */ 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)) * pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(texspace_loc)); - /* */ + /* applying object transform */ transform *= gf_matrix_from_transform(object->object_to_world); } diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.h b/source/blender/render/hydra/scene_delegate/volume_modifier.h index 2a4b8942cdda..853c3a5d48f1 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.h +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.h @@ -5,6 +5,8 @@ #include +#include "DNA_fluid_types.h" + #include "volume.h" namespace blender::render::hydra { @@ -24,6 +26,8 @@ class VolumeModifierData : public VolumeData { void write_transform() override; std::string get_cached_file_path(std::string directory, int frame); + + FluidModifierData *modifier_; }; } // namespace blender::render::hydra -- 2.30.2 From 1be51ad64d5c4775e2c1f25e4b2dc536e6cc1dff Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Fri, 14 Jul 2023 17:17:36 +0300 Subject: [PATCH 20/23] Fixes in VolumeData updates, improved logging --- intern/ghost/intern/GHOST_SystemWin32.cc | 2 +- .../blender/render/hydra/scene_delegate/volume.cc | 8 +++++--- .../render/hydra/scene_delegate/volume_modifier.cc | 14 +++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/intern/ghost/intern/GHOST_SystemWin32.cc b/intern/ghost/intern/GHOST_SystemWin32.cc index 3dae6b7914a2..21b9f33a25d9 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cc +++ b/intern/ghost/intern/GHOST_SystemWin32.cc @@ -304,7 +304,7 @@ GHOST_IContext *GHOST_SystemWin32::createOffscreenContext(GHOST_GPUSettings gpuS true, wnd, mHDC, - WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, + WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 4, minor, (debug_context ? WGL_CONTEXT_DEBUG_BIT_ARB : 0), diff --git a/source/blender/render/hydra/scene_delegate/volume.cc b/source/blender/render/hydra/scene_delegate/volume.cc index ec270c8ba9bf..e54f91a715a2 100644 --- a/source/blender/render/hydra/scene_delegate/volume.cc +++ b/source/blender/render/hydra/scene_delegate/volume.cc @@ -27,13 +27,15 @@ VolumeData::VolumeData(BlenderSceneDelegate *scene_delegate, void VolumeData::init() { - ID_LOG(1, ""); + field_descriptors_.clear(); + 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); + ID_LOG(1, "%s", filepath_.c_str()); if (volume->runtime.grids) { const int num_grids = BKE_volume_num_grids(volume); @@ -64,14 +66,14 @@ void VolumeData::insert() for (auto &desc : field_descriptors_) { scene_delegate_->GetRenderIndex().InsertBprim( desc.fieldPrimType, scene_delegate_, desc.fieldId); - ID_LOG(1, "Volume field %s", desc.fieldId.GetText()); + ID_LOG(2, "Volume field %s", desc.fieldId.GetText()); } } void VolumeData::remove() { for (auto &desc : field_descriptors_) { - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", desc.fieldId.GetText()); + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", desc.fieldId.GetText()); scene_delegate_->GetRenderIndex().RemoveBprim(desc.fieldPrimType, desc.fieldId); } CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", prim_id.GetText()); diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.cc b/source/blender/render/hydra/scene_delegate/volume_modifier.cc index 86b452730129..93f0ce2334ba 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.cc +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.cc @@ -39,10 +39,12 @@ bool VolumeModifierData::is_volume_modifier(Object *object) void VolumeModifierData::init() { - ID_LOG(1, ""); + field_descriptors_.clear(); Object *object = (Object *)this->id; - modifier_ = (FluidModifierData *)BKE_modifiers_findby_type(object, eModifierType_Fluid); + ModifierData *md = BKE_modifiers_findby_type(object, eModifierType_Fluid); + modifier_ = (FluidModifierData *)BKE_modifier_get_evaluated( + scene_delegate_->depsgraph, object, md); if ((modifier_->domain->cache_data_format & FLUID_DOMAIN_FILE_OPENVDB) == 0) { CLOG_WARN(LOG_RENDER_HYDRA_SCENE, @@ -53,6 +55,7 @@ void VolumeModifierData::init() filepath_ = get_cached_file_path(modifier_->domain->cache_directory, scene_delegate_->scene->r.cfra); + ID_LOG(1, "%s", filepath_.c_str()); for (auto &grid_name : pxr::grid_tokens_->allTokens) { field_descriptors_.emplace_back(grid_name, @@ -96,9 +99,10 @@ void VolumeModifierData::write_transform() Object *object = (Object *)this->id; /* set base scaling */ - transform = pxr::GfMatrix4d().SetScale(pxr::GfVec3d(1.0f / modifier_->domain->global_size[0], - 1.0f / modifier_->domain->global_size[1], - 1.0f / modifier_->domain->global_size[2])); + transform = pxr::GfMatrix4d().SetScale( + pxr::GfVec3d(modifier_->domain->scale / modifier_->domain->global_size[0], + modifier_->domain->scale / modifier_->domain->global_size[1], + modifier_->domain->scale / modifier_->domain->global_size[2])); /* positioning to center */ transform *= pxr::GfMatrix4d().SetTranslate(pxr::GfVec3d(-1, -1, -1)); -- 2.30.2 From 75f18b7479308a6c395986e942c66d88b6b7f0fd Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Fri, 14 Jul 2023 17:26:28 +0300 Subject: [PATCH 21/23] Cleanups --- source/blender/render/hydra/scene_delegate/volume_modifier.cc | 4 ++-- source/blender/render/hydra/scene_delegate/volume_modifier.h | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.cc b/source/blender/render/hydra/scene_delegate/volume_modifier.cc index 93f0ce2334ba..fceb55a858e9 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.cc +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.cc @@ -3,7 +3,7 @@ #include -#include "BKE_mesh.hh" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BLI_path_util.h" #include "DNA_scene_types.h" @@ -56,7 +56,7 @@ void VolumeModifierData::init() filepath_ = get_cached_file_path(modifier_->domain->cache_directory, scene_delegate_->scene->r.cfra); ID_LOG(1, "%s", filepath_.c_str()); - + for (auto &grid_name : pxr::grid_tokens_->allTokens) { field_descriptors_.emplace_back(grid_name, pxr::UsdVolImagingTokens->openvdbAsset, diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.h b/source/blender/render/hydra/scene_delegate/volume_modifier.h index 853c3a5d48f1..7ea99de7b46d 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.h +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.h @@ -3,8 +3,6 @@ #pragma once -#include - #include "DNA_fluid_types.h" #include "volume.h" -- 2.30.2 From 591c48b017ac9192307996f3842ae5843d436741 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Fri, 14 Jul 2023 21:02:36 +0300 Subject: [PATCH 22/23] cleanup --- source/blender/render/hydra/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/CMakeLists.txt b/source/blender/render/hydra/CMakeLists.txt index 53df989e0aa0..93582000d134 100644 --- a/source/blender/render/hydra/CMakeLists.txt +++ b/source/blender/render/hydra/CMakeLists.txt @@ -75,6 +75,8 @@ endif() set(SRC python.cc + camera.h + camera.cc engine.h engine.cc final_engine.h @@ -83,8 +85,6 @@ set(SRC preview_engine.cc viewport_engine.h viewport_engine.cc - camera.h - camera.cc render_task_delegate.cc render_task_delegate.h -- 2.30.2 From b49e816dbee9cc1e4361f3b4a8532f442c112549 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Fri, 21 Jul 2023 00:47:19 +0300 Subject: [PATCH 23/23] Fixes after merge --- source/blender/render/hydra/scene_delegate/object.cc | 8 ++++---- source/blender/render/hydra/scene_delegate/volume.h | 1 - .../render/hydra/scene_delegate/volume_modifier.cc | 3 ++- .../blender/render/hydra/scene_delegate/volume_modifier.h | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 6b7e2e4108ac..6817026b3fc0 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -25,16 +25,16 @@ std::unique_ptr ObjectData::create(BlenderSceneDelegate *scene_deleg { std::unique_ptr obj_data; - if (VolumeModifierData::is_volume_modifier(object)) { - return std::make_unique(scene_delegate, object, prim_id); - } - switch (object->type) { case OB_MESH: case OB_SURF: case OB_FONT: case OB_CURVES_LEGACY: case OB_MBALL: + if (VolumeModifierData::is_volume_modifier(object)) { + obj_data = std::make_unique(scene_delegate, object, prim_id); + break; + } obj_data = std::make_unique(scene_delegate, object, prim_id); break; case OB_CURVES: diff --git a/source/blender/render/hydra/scene_delegate/volume.h b/source/blender/render/hydra/scene_delegate/volume.h index f58d2106668e..a3c858598c38 100644 --- a/source/blender/render/hydra/scene_delegate/volume.h +++ b/source/blender/render/hydra/scene_delegate/volume.h @@ -29,7 +29,6 @@ class VolumeData : public ObjectData { protected: void write_materials() override; - private: std::string filepath_; pxr::HdVolumeFieldDescriptorVector field_descriptors_; MaterialData *mat_data_ = nullptr; diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.cc b/source/blender/render/hydra/scene_delegate/volume_modifier.cc index fceb55a858e9..fc436f0deb5b 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.cc +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.cc @@ -120,7 +120,8 @@ std::string VolumeModifierData::get_cached_file_path(std::string directory, int { char file_path[FILE_MAX]; char file_name[32]; - strcat(strcat(strcpy(file_name, FLUID_NAME_DATA), "_####"), FLUID_DOMAIN_EXTENSION_OPENVDB); + snprintf( + file_name, sizeof(file_name), "%s_####%s", FLUID_NAME_DATA, FLUID_DOMAIN_EXTENSION_OPENVDB); BLI_path_frame(file_name, sizeof(file_name), frame, 0); BLI_path_join(file_path, sizeof(file_path), directory.c_str(), FLUID_DOMAIN_DIR_DATA, file_name); diff --git a/source/blender/render/hydra/scene_delegate/volume_modifier.h b/source/blender/render/hydra/scene_delegate/volume_modifier.h index 7ea99de7b46d..12c1c6ecbf26 100644 --- a/source/blender/render/hydra/scene_delegate/volume_modifier.h +++ b/source/blender/render/hydra/scene_delegate/volume_modifier.h @@ -20,9 +20,10 @@ class VolumeModifierData : public VolumeData { void init() override; void update() override; - private: + protected: void write_transform() override; + private: std::string get_cached_file_path(std::string directory, int frame); FluidModifierData *modifier_; -- 2.30.2