Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cube performance #717

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/manifold/src/constructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ Manifold Manifold::Cube(glm::vec3 size, bool center) {
glm::length(size) == 0.) {
return Invalid();
}
auto cube = Manifold(std::make_shared<Impl>(Impl::Shape::Cube));
cube = cube.Scale(size);
if (center) cube = cube.Translate(-size / 2.0f);
return cube.AsOriginal();
glm::mat4x3 m =
glm::translate(center ? (-size / 2.0f) : glm::vec3(0)) * glm::scale(size);
return Manifold(std::make_shared<Impl>(Manifold::Impl::Shape::Cube, m));
}

/**
Expand Down
25 changes: 13 additions & 12 deletions src/manifold/src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ Manifold::Impl::Impl(const Mesh& mesh, const MeshRelationD& relation,
* Create either a unit tetrahedron, cube or octahedron. The cube is in the
* first octant, while the others are symmetric about the origin.
*/
Manifold::Impl::Impl(Shape shape) {
Manifold::Impl::Impl(Shape shape, const glm::mat4x3 m) {
std::vector<glm::vec3> vertPos;
std::vector<glm::ivec3> triVerts;
switch (shape) {
Expand All @@ -547,19 +547,19 @@ Manifold::Impl::Impl(Shape shape) {
break;
case Shape::Cube:
vertPos = {{0.0f, 0.0f, 0.0f}, //
{1.0f, 0.0f, 0.0f}, //
{1.0f, 1.0f, 0.0f}, //
{0.0f, 1.0f, 0.0f}, //
{0.0f, 0.0f, 1.0f}, //
{0.0f, 1.0f, 0.0f}, //
{0.0f, 1.0f, 1.0f}, //
{1.0f, 0.0f, 0.0f}, //
{1.0f, 0.0f, 1.0f}, //
{1.0f, 1.0f, 1.0f}, //
{0.0f, 1.0f, 1.0f}};
triVerts = {{0, 2, 1}, {0, 3, 2}, //
{4, 5, 6}, {4, 6, 7}, //
{0, 1, 5}, {0, 5, 4}, //
{1, 2, 6}, {1, 6, 5}, //
{2, 3, 7}, {2, 7, 6}, //
{3, 0, 4}, {3, 4, 7}};
{1.0f, 1.0f, 0.0f}, //
{1.0f, 1.0f, 1.0f}};
triVerts = {{1, 0, 4}, {2, 4, 0}, //
{1, 3, 0}, {3, 1, 5}, //
{3, 2, 0}, {3, 7, 2}, //
{5, 4, 6}, {5, 1, 4}, //
{6, 4, 2}, {7, 6, 2}, //
{7, 3, 5}, {7, 5, 6}};
break;
case Shape::Octahedron:
vertPos = {{1.0f, 0.0f, 0.0f}, //
Expand All @@ -575,6 +575,7 @@ Manifold::Impl::Impl(Shape shape) {
break;
}
vertPos_ = vertPos;
for (auto& v : vertPos_) v = m * glm::vec4(v, 1.0f);
CreateHalfedges(triVerts);
Finish();
meshRelation_.originalID = ReserveIDs(1);
Expand Down
2 changes: 1 addition & 1 deletion src/manifold/src/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct Manifold::Impl {

Impl() {}
enum class Shape { Tetrahedron, Cube, Octahedron };
Impl(Shape);
Impl(Shape, const glm::mat4x3 = glm::mat4x3(1));

Impl(const MeshGL&, std::vector<float> propertyTolerance = {});
Impl(const Mesh&, const MeshRelationD& relation,
Expand Down
2 changes: 1 addition & 1 deletion test/boolean_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TEST(Boolean, MeshGLRoundTrip) {
const Manifold result2(inGL);

ASSERT_LT(result2.OriginalID(), 0);
ExpectMeshes(result2, {{18, 32}});
ExpectMeshes(result2, {{16, 28}});
RelatedGL(result2, {original});

const MeshGL outGL = result2.GetMeshGL();
Expand Down
Loading