From 705d3e4f73a10ce61741de2821992b41e83e08c4 Mon Sep 17 00:00:00 2001 From: John Collins Date: Wed, 24 Apr 2024 22:47:59 -0700 Subject: [PATCH] Save --- .../main/cpp/manifold3d/matrix_transforms.hpp | 6 +-- src/manifold/include/matrix_transforms.hpp | 1 + src/manifold/src/manifold.cpp | 38 +++++++++++++++---- test/manifold_test.cpp | 2 +- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/bindings/java/src/main/cpp/manifold3d/matrix_transforms.hpp b/bindings/java/src/main/cpp/manifold3d/matrix_transforms.hpp index 660635ded..18998c4d9 100644 --- a/bindings/java/src/main/cpp/manifold3d/matrix_transforms.hpp +++ b/bindings/java/src/main/cpp/manifold3d/matrix_transforms.hpp @@ -158,11 +158,7 @@ glm::mat4x3 InvertTransform(const glm::mat4x3& m) { glm::mat3x3 rotationPart = glm::mat3x3(m); glm::mat4x3 unRotated = SetRotation(m, glm::transpose(rotationPart)); - - glm::vec3 translation = -m[3]; - glm::mat4x3 result = Translate(unRotated, translation); - - return result; + return SetTranslation(unRotated, -m[3]); } glm::mat3x2 InvertTransform(const glm::mat3x2& m) { diff --git a/src/manifold/include/matrix_transforms.hpp b/src/manifold/include/matrix_transforms.hpp index c0ed4bccc..b57f56c0b 100644 --- a/src/manifold/include/matrix_transforms.hpp +++ b/src/manifold/include/matrix_transforms.hpp @@ -165,6 +165,7 @@ glm::mat4x3 InvertTransform(const glm::mat4x3& m) { glm::mat3x3 rotationPart = glm::mat3x3(m); glm::mat4x3 unRotated = SetRotation(m, glm::transpose(rotationPart)); + unRotated[3] = {0, 0, 0}; glm::vec3 translation = -m[3]; glm::mat4x3 result = Translate(unRotated, translation); diff --git a/src/manifold/src/manifold.cpp b/src/manifold/src/manifold.cpp index 745d3ceb5..c921e02bf 100644 --- a/src/manifold/src/manifold.cpp +++ b/src/manifold/src/manifold.cpp @@ -19,6 +19,7 @@ #include "QuickHull.hpp" #include "boolean3.h" #include "csg_tree.h" +#include "glm/ext/matrix_float4x3.hpp" #include "glm/ext/quaternion_geometric.hpp" #include "impl.h" #include "par.h" @@ -482,6 +483,18 @@ std::vector Manifold::surfaceMap(const std::vector& tr return glm::length(t * d1); }; + auto toRelativeTfs = [](std::vector tfs) -> std::vector { + std::vector result; + result.push_back(tfs[0]); + for (int i = 0; i < tfs.size() - 1; i++) { + glm::mat4x3 inverse = MatrixTransforms::InvertTransform(tfs[i]); + glm::mat4x3 combined = MatrixTransforms::CombineTransforms(inverse, tfs[i+1]); + cout << " combined: " << combined[3].x << " " << combined[3].y << " " << combined[3].z << endl; + result.push_back(combined); + } + return result; + }; + auto& vertPos = impl->vertPos_; int currTfIdx = 0; @@ -492,9 +505,16 @@ std::vector Manifold::surfaceMap(const std::vector& tr int currHalfedgeIdx = 0; glm::mat4x3 currTf = transforms[currTfIdx]; + std::vector tfs = toRelativeTfs(transforms); + + for (auto& tf: tfs) { + cout << "tf pos: " << tf[3].x << " " << tf[3].y << " " << tf[3].z << endl; + } + do { - glm::mat4x3 nextTf = transforms[currTfIdx+1]; + glm::mat4x3 nextTf = MatrixTransforms::CombineTransforms(currTf, tfs[currTfIdx+1]); + cout << "POS: " << currTfIdx << " " << nextTf[3].x << " " << nextTf[3].y << " " << nextTf[3].z << endl; glm::vec3 currPos = currTf[3]; glm::vec3 nextPos = nextTf[3]; @@ -519,6 +539,7 @@ std::vector Manifold::surfaceMap(const std::vector& tr glm::vec3 tfPos = currTf[3]; glm::vec3 tfDirX = currTf[0]; + cout << "X DIR: " << tfDirX.x << " " << tfDirX.y << " " << tfDirX.z << endl; glm::vec3 intersection; std::vector edges = {currHalfedgeIdx, nextHalfedgeIdx, nnextHalfedgeIdx}; @@ -543,25 +564,26 @@ std::vector Manifold::surfaceMap(const std::vector& tr if (minDistance > 0.0001 && currManifoldDist + minDistance < currTfDist) { cout << "next TF not on current face" << endl; - cout << "currManifoldDist: " << currManifoldDist << " minDistance: " << minDistance << " currTfDist: " << currTfDist << endl; + cout << "currManifoldDist: " << currManifoldDist << " minDistance: " << minDistance << " currTfDist: " << currTfDist << " XDIRY: " << tfDirX.y << endl; currTf = MatrixTransforms::TranslateX(currTf, minDistance); result.push_back(currTf); currHalfedgeIdx = halfedges[nnextHalfedgeIdx].pairedHalfedge; currManifoldDist += minDistance; - currTfIdx += 1; - currTf = transforms[currTfIdx]; + glm::vec3 nextFaceNormal = impl->faceNormal_[halfedges[currHalfedgeIdx].face]; + float angle = (glm::pi() / 2) - angleBetweenVectors(nextFaceNormal, currTf[1]); + cout << "angle: " << angle << endl; + currTf = MatrixTransforms::Yaw(currTf, angle); } else { cout << "next TF on current face" << endl; cout << "currManifoldDist: " << currManifoldDist << " minDistance: " << minDistance << " currTfDist: " << currTfDist << endl; - result.push_back(currTf); + result.push_back(nextTf); currTfIdx += 1; - currTf = transforms[currTfIdx]; + currTf = nextTf; break; } } - } while (currTfIdx < transforms.size() - 1); + } while (currTfIdx < tfs.size() - 1); - result.push_back(transforms[transforms.size() - 1]); for (auto& tf: result) { cout << "tf pos: " << tf[3].x << " " << tf[3].y << " " << tf[3].z << endl; } diff --git a/test/manifold_test.cpp b/test/manifold_test.cpp index be932d8c9..5c39761fa 100644 --- a/test/manifold_test.cpp +++ b/test/manifold_test.cpp @@ -205,7 +205,7 @@ TEST(Manifold, surfaceMap) { glm::mat4x3 transform2 = {{1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {7.0, 0, 5}}; glm::mat4x3 transform3 = {{1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {9.0, 0, 5}}; glm::mat4x3 transform4 = {{1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {9.5, 0, 5}}; - glm::mat4x3 transform5 = {{1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {9.8, 0, 5}}; + glm::mat4x3 transform5 = {{1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {11.5, 0, 5}}; vector ret = cube.surfaceMap({transform1, transform2, transform3, transform4, transform5}); }