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 7980b32c00 - Show all commits

View File

@ -58,6 +58,8 @@ void VolumeData::init()
{ {
init_from_volume(); init_from_volume();
} }
write_transform();
write_materials();
} }
void VolumeData::insert() void VolumeData::insert()
@ -98,13 +100,6 @@ void VolumeData::update()
} }
if (id->recalc & ID_RECALC_TRANSFORM) { if (id->recalc & ID_RECALC_TRANSFORM) {
write_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; bits |= pxr::HdChangeTracker::DirtyTransform;
} }
@ -204,51 +199,6 @@ void VolumeData::init_from_modifier() {
Object *object = (Object *)this->id; Object *object = (Object *)this->id;
FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type( FluidModifierData *volume_modifier = (FluidModifierData *)BKE_modifiers_findby_type(
object, eModifierType_Fluid); 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, filepath_ = get_cached_file_path(volume_modifier->domain->cache_directory,
scene_delegate_->scene->r.cfra); scene_delegate_->scene->r.cfra);
for (auto &grid_name : supported_grids) { for (auto &grid_name : supported_grids) {
@ -256,7 +206,6 @@ void VolumeData::init_from_modifier() {
pxr::UsdVolImagingTokens->openvdbAsset, pxr::UsdVolImagingTokens->openvdbAsset,
prim_id.AppendElementString("VF_" + grid_name.GetString())); prim_id.AppendElementString("VF_" + grid_name.GetString()));
} }
write_materials();
} }
void VolumeData::init_from_volume() void VolumeData::init_from_volume()
@ -282,8 +231,6 @@ void VolumeData::init_from_volume()
} }
} }
BKE_volume_unload(volume); BKE_volume_unload(volume);
write_transform();
write_materials();
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra