forked from blender/blender
Export volumes from object modifier (quick effect) #62
@ -344,7 +344,6 @@ float Object::compute_volume_step_size() const
|
|||||||
/* Step size is transformed from voxel to world space. */
|
/* Step size is transformed from voxel to world space. */
|
||||||
Transform voxel_tfm = tfm;
|
Transform voxel_tfm = tfm;
|
||||||
if (metadata.use_transform_3d) {
|
if (metadata.use_transform_3d) {
|
||||||
|
|
||||||
voxel_tfm = tfm * transform_inverse(metadata.transform_3d);
|
voxel_tfm = tfm * transform_inverse(metadata.transform_3d);
|
||||||
}
|
}
|
||||||
voxel_step_size = reduce_min(fabs(transform_direction(&voxel_tfm, size)));
|
voxel_step_size = reduce_min(fabs(transform_direction(&voxel_tfm, size)));
|
||||||
|
@ -45,7 +45,6 @@ static std::string cache_image_file(Image *image,
|
|||||||
BKE_image_path_ext_from_imformat(&scene->r.im_format, &r_ext);
|
BKE_image_path_ext_from_imformat(&scene->r.im_format, &r_ext);
|
||||||
opts.im_format = scene->r.im_format;
|
opts.im_format = scene->r.im_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(file_name, sizeof(file_name), "img_%016llx%s", (uintptr_t)image, r_ext);
|
snprintf(file_name, sizeof(file_name), "img_%016llx%s", (uintptr_t)image, r_ext);
|
||||||
|
|
||||||
file_path = get_cache_file(file_name);
|
file_path = get_cache_file(file_name);
|
||||||
|
@ -208,13 +208,13 @@ void VolumeData::init_from_modifier()
|
|||||||
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);
|
||||||
|
|
||||||
assign_volume_transform();
|
|
||||||
|
|
||||||
for (auto &grid_name : supported_grids) {
|
for (auto &grid_name : supported_grids) {
|
||||||
field_descriptors_.emplace_back(grid_name,
|
field_descriptors_.emplace_back(grid_name,
|
||||||
pxr::UsdVolImagingTokens->openvdbAsset,
|
pxr::UsdVolImagingTokens->openvdbAsset,
|
||||||
prim_id.AppendElementString("VF_" + grid_name.GetString()));
|
prim_id.AppendElementString("VF_" + grid_name.GetString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assign_volume_transform();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VolumeData::init_from_volume()
|
void VolumeData::init_from_volume()
|
||||||
@ -246,10 +246,10 @@ void VolumeData::assign_volume_transform() {
|
|||||||
Object *object = (Object *)this->id;
|
Object *object = (Object *)this->id;
|
||||||
Mesh *mesh = BKE_object_to_mesh(nullptr, object, false);
|
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));
|
pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(0.5));
|
||||||
auto det = mod.GetDeterminant();
|
double det = fixed_transform.GetDeterminant();
|
||||||
auto inversed = mod.GetInverse(&det);
|
pxr::GfMatrix4d inversed = fixed_transform.GetInverse(&det);
|
||||||
|
|
||||||
float scale[3] = {0.5f, 0.5f, 0.5f};
|
float scale[3] = {0.5f, 0.5f, 0.5f};
|
||||||
if (object->scale[0] != 0.0f) {
|
if (object->scale[0] != 0.0f) {
|
||||||
@ -261,13 +261,17 @@ void VolumeData::assign_volume_transform() {
|
|||||||
if (object->scale[2] != 0.0f) {
|
if (object->scale[2] != 0.0f) {
|
||||||
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]));
|
pxr::GfMatrix4d scale_matrix = pxr::GfMatrix4d(1.0f).SetScale(
|
||||||
auto texture_trans = pxr::GfMatrix4d(1.0f).SetTranslate(pxr::GfVec3d(mesh->texspace_location[0],
|
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[1],
|
||||||
mesh->texspace_location[2]));
|
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[1],
|
||||||
mesh->texspace_size[2]));
|
mesh->texspace_size[2]));
|
||||||
|
|
||||||
transform = scale_matrix * inversed * texture_scale * texture_trans * transform;
|
transform = scale_matrix * inversed * texture_scale * texture_trans * transform;
|
||||||
|
|
||||||
BKE_object_to_mesh_clear(object);
|
BKE_object_to_mesh_clear(object);
|
||||||
|
Loading…
Reference in New Issue
Block a user