Skip to content

Commit

Permalink
removed RotateUp and uint
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish committed Oct 19, 2024
1 parent 0a51ae2 commit 74b74c7
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 26 deletions.
1 change: 1 addition & 0 deletions include/manifold/manifold.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class Manifold {
Manifold Scale(vec3) const;
Manifold Rotate(double xDegrees, double yDegrees = 0.0,
double zDegrees = 0.0) const;
Manifold Rotate(quat quaternion) const;
Manifold Transform(const mat3x4&) const;
Manifold Mirror(vec3) const;
Manifold Warp(std::function<void(vec3&)>) const;
Expand Down
5 changes: 5 additions & 0 deletions src/csg_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ std::shared_ptr<CsgNode> CsgNode::Rotate(double xDegrees, double yDegrees,
return Transform(transform);
}

std::shared_ptr<CsgNode> CsgNode::Rotate(quat q) const {
mat3x4 transform(la::qmat(q), vec3());
return Transform(transform);
}

CsgLeafNode::CsgLeafNode() : pImpl_(std::make_shared<Manifold::Impl>()) {}

CsgLeafNode::CsgLeafNode(std::shared_ptr<const Manifold::Impl> pImpl_)
Expand Down
1 change: 1 addition & 0 deletions src/csg_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CsgNode : public std::enable_shared_from_this<CsgNode> {
std::shared_ptr<CsgNode> Scale(const vec3 &s) const;
std::shared_ptr<CsgNode> Rotate(double xDegrees = 0, double yDegrees = 0,
double zDegrees = 0) const;
std::shared_ptr<CsgNode> Rotate(quat q) const;
};

class CsgLeafNode final : public CsgNode {
Expand Down
4 changes: 4 additions & 0 deletions src/manifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ Manifold Manifold::Rotate(double xDegrees, double yDegrees,
return Manifold(pNode_->Rotate(xDegrees, yDegrees, zDegrees));
}

Manifold Manifold::Rotate(quat quaternion) const {
return Manifold(pNode_->Rotate(quaternion));
}

/**
* Transform this Manifold in space. The first three columns form a 3x3 matrix
* transform and the last is a translation vector. This operation can be
Expand Down
4 changes: 2 additions & 2 deletions src/meshIO/meshIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ aiScene* CreateScene(const ExportOptions& options) {

scene->mRootNode = new aiNode();
scene->mRootNode->mNumMeshes = 1;
scene->mRootNode->mMeshes = new uint[scene->mRootNode->mNumMeshes];
scene->mRootNode->mMeshes = new uint32_t[scene->mRootNode->mNumMeshes];
scene->mRootNode->mMeshes[0] = 0;

scene->mMeshes[0]->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
Expand Down Expand Up @@ -251,7 +251,7 @@ void ExportMesh(const std::string& filename, const MeshGL& mesh,
for (size_t i = 0; i < mesh_out->mNumFaces; ++i) {
aiFace& face = mesh_out->mFaces[i];
face.mNumIndices = 3;
face.mIndices = new uint[face.mNumIndices];
face.mIndices = new uint32_t[face.mNumIndices];
for (int j : {0, 1, 2}) face.mIndices[j] = mesh.triVerts[3 * i + j];
}

Expand Down
15 changes: 0 additions & 15 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,6 @@ inline int CCW(vec2 p0, vec2 p1, vec2 p2, double tol) {
return area > 0 ? 1 : -1;
}

/**
* This 4x3 matrix can be used as an input to Manifold.Transform() to turn an
* object. Turns along the shortest path from given up-vector to (0, 0, 1).
*
* @param up The vector to be turned to point upwards. Length does not matter.
*/
inline mat3x4 RotateUp(vec3 up) {
up = la::normalize(up);
const vec3 axis = la::cross(up, {0, 0, 1});
double angle = la::asin(la::length(axis));
if (la::dot(up, {0, 0, 1}) < 0) angle = kPi - angle;
const quat q = la::rotation_quat(la::normalize(axis), angle);
return mat3x4(la::qmat(q), vec3());
}

inline mat4 Mat4(mat3x4 a) {
return mat4({a[0], 0}, {a[1], 0}, {a[2], 0}, {a[3], 1});
}
Expand Down
6 changes: 2 additions & 4 deletions test/boolean_complex_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifdef MANIFOLD_CROSS_SECTION
#include "manifold/cross_section.h"
#endif
#include "../src/utils.h" // For RotateUp
#include "manifold/manifold.h"
#include "manifold/polygon.h"
#include "test.h"
Expand Down Expand Up @@ -1084,9 +1083,8 @@ TEST(BooleanComplex, SimpleOffset) {
if (len < 0.03) continue;
manifold::Manifold origin_cyl = manifold::Manifold::Cylinder(len, 1, 1, 8);
vec3 evec(-1 * edge.x, -1 * edge.y, edge.z);
manifold::Manifold rotated_cyl =
origin_cyl.Transform(manifold::RotateUp(evec));
manifold::Manifold right = rotated_cyl.Translate(ev1);
quat q = rotation_quat(normalize(evec), vec3(0, 0, 1));
manifold::Manifold right = origin_cyl.Rotate(q).Translate(ev1);
if (!right.NumTri()) continue;
c += right;
// See above discussion
Expand Down
4 changes: 2 additions & 2 deletions test/samples_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifdef MANIFOLD_CROSS_SECTION
#include "manifold/cross_section.h"
#endif
#include "../src/utils.h"
#include "manifold/polygon.h"
#include "test.h"

Expand Down Expand Up @@ -147,7 +146,8 @@ TEST(Samples, TetPuzzle) {

Manifold puzzle2 = puzzle.Rotate(0, 0, 180);
EXPECT_TRUE((puzzle ^ puzzle2).IsEmpty());
puzzle = puzzle.Transform(RotateUp({1, -1, -1}));
quat q = rotation_quat(normalize(vec3(1, -1, -1)), vec3(0, 0, 1));
puzzle = puzzle.Rotate(q);
#ifdef MANIFOLD_EXPORT
if (options.exportModels) ExportMesh("tetPuzzle.glb", puzzle.GetMeshGL(), {});
#endif
Expand Down
4 changes: 1 addition & 3 deletions test/smooth_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <algorithm>

#include "../src/utils.h"
#ifdef MANIFOLD_CROSS_SECTION
#include "manifold/cross_section.h"
#endif
Expand Down Expand Up @@ -325,8 +324,7 @@ TEST(Smooth, Torus) {
vec3 tan(v.y, -v.x, 0);
tan *= la::dot(tan, edge) < 0 ? -1.0 : 1.0;
tangent = CircularTangent(tan, edge);
} else if (std::abs(la::determinant(mat2(vec2(v), vec2(edge)))) <
kTolerance) {
} else if (std::abs(la::determinant(mat2(vec2(v), vec2(edge)))) < 1e-5) {
const double theta = std::asin(v.z);
vec2 xy(v);
const double r = la::length(xy);
Expand Down

0 comments on commit 74b74c7

Please sign in to comment.