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
Showing only changes of commit c7293b288d - Show all commits

View File

@ -11,6 +11,7 @@
#include <pxr/base/gf/rotation.h> #include <pxr/base/gf/rotation.h>
#include "BKE_material.h" #include "BKE_material.h"
#include "BKE_mesh.hh"
#include "BKE_object.h" #include "BKE_object.h"
#include "BKE_modifier.h" #include "BKE_modifier.h"
#include "BKE_volume.h" #include "BKE_volume.h"
@ -243,6 +244,8 @@ void VolumeData::init_from_volume()
void VolumeData::assign_volume_transform() { void VolumeData::assign_volume_transform() {
Object *object = (Object *)this->id; Object *object = (Object *)this->id;
Mesh *mesh = BKE_object_to_mesh(nullptr, object, false);
auto mod = pxr::GfMatrix4d(1.0f).SetScale(0.5) * auto mod = 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));
auto det = mod.GetDeterminant(); auto det = mod.GetDeterminant();
@ -259,7 +262,15 @@ void VolumeData::assign_volume_transform() {
scale[2] = 0.5f / object->scale[2]; scale[2] = 0.5f / object->scale[2];
} }
auto scale_matrix = pxr::GfMatrix4d(1.0f).SetScale(pxr::GfVec3d(scale[0], scale[1], 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 } // namespace blender::render::hydra