|
|
|
#include <data/data_center.hpp>
|
|
|
|
|
|
|
|
#include <base/subface.hpp>
|
|
|
|
|
|
|
|
subface::~subface() noexcept
|
|
|
|
{
|
|
|
|
if (!data_center) return;
|
|
|
|
|
|
|
|
data_center->transform_blocks.release(*model_matrices);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal::transform_block &subface::raw_local_to_world() const { return model_matrices->local_to_world; }
|
|
|
|
|
|
|
|
internal::transform_block &subface::raw_world_to_local() const { return model_matrices->world_to_local; }
|
|
|
|
|
|
|
|
Eigen::Vector3d subface::local_to_world_scale() const { return model_matrices->local_to_world.linear().colwise().norm(); }
|
|
|
|
|
|
|
|
Eigen::Matrix3d subface::trans_world_to_local_linear() const { return model_matrices->world_to_local.linear().transpose(); }
|
|
|
|
|
|
|
|
std::pair<internal::paired_model_matrix *, bool> subface::apply_transform(internal::transform_type type, Eigen::Vector4d param)
|
|
|
|
{
|
|
|
|
std::cout << "Applying transform: " << param.head<3>() << std::endl;
|
|
|
|
auto temp = *model_matrices;
|
|
|
|
switch (type) {
|
|
|
|
case internal::transform_type::scale: {
|
|
|
|
std::cout << "Before scale:" << std::endl;
|
|
|
|
std::cout << "local_to_world.linear():\n" << temp.local_to_world.linear() << std::endl;
|
|
|
|
std::cout << "world_to_local.linear():\n" << temp.world_to_local.linear() << std::endl;
|
|
|
|
|
|
|
|
temp.local_to_world.linear() = param.head<3>().asDiagonal() * temp.local_to_world.linear();
|
|
|
|
temp.world_to_local.linear() = temp.world_to_local.linear() * param.head<3>().cwiseInverse().asDiagonal();
|
|
|
|
|
|
|
|
std::cout << "After scale:" << std::endl;
|
|
|
|
std::cout << "local_to_world.linear():\n" << temp.local_to_world.linear() << std::endl;
|
|
|
|
std::cout << "world_to_local.linear():\n" << temp.world_to_local.linear() << std::endl;
|
|
|
|
} break;
|
|
|
|
case internal::transform_type::rotation: {
|
|
|
|
auto rotation_matrix = Eigen::Quaterniond(param).toRotationMatrix();
|
|
|
|
temp.local_to_world.linear() = rotation_matrix * temp.local_to_world.linear();
|
|
|
|
temp.world_to_local.linear() = temp.world_to_local.linear() * rotation_matrix.transpose();
|
|
|
|
} break;
|
|
|
|
case internal::transform_type::translation: {
|
|
|
|
std::cout << "Before translation: " << std::endl;
|
|
|
|
std::cout << "Local to world: " << temp.local_to_world.translation() << std::endl;
|
|
|
|
std::cout << "World to local: " << temp.world_to_local.translation() << std::endl;
|
|
|
|
temp.local_to_world.translation() += param.head<3>();
|
|
|
|
temp.world_to_local.translation() -= param.head<3>();
|
|
|
|
std::cout << "After translation: " << std::endl;
|
|
|
|
std::cout << "Local to world: " << temp.local_to_world.translation() << std::endl;
|
|
|
|
std::cout << "World to local: " << temp.world_to_local.translation() << std::endl;
|
|
|
|
} break;
|
|
|
|
default: throw std::invalid_argument("Invalid transform type");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool reversed{};
|
|
|
|
if (temp.world_to_local.data()[0] < 0) {
|
|
|
|
temp.local_to_world.matrix() *= -1;
|
|
|
|
temp.world_to_local.matrix() *= -1;
|
|
|
|
reversed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto [iter, _] = data_center->transform_blocks.acquire(temp);
|
|
|
|
return {iter.operator->(), reversed};
|
|
|
|
}
|