Skip to content

Commit

Permalink
removed cross_section dependency from manifold (#850)
Browse files Browse the repository at this point in the history
* removed cross_section dependency from manifold

* fix compile errors

* updated JS bindings

* fixed python bindings
  • Loading branch information
elalish authored Jun 27, 2024
1 parent ab1a96a commit 85d71f5
Show file tree
Hide file tree
Showing 21 changed files with 183 additions and 127 deletions.
9 changes: 4 additions & 5 deletions bindings/c/include/manifoldc.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ ManifoldManifold *manifold_trim_by_plane(void *mem, ManifoldManifold *m,

// 3D to 2D

ManifoldCrossSection *manifold_slice(void *mem, ManifoldManifold *m,
float height);
ManifoldCrossSection *manifold_project(void *mem, ManifoldManifold *m);
ManifoldPolygons *manifold_slice(void *mem, ManifoldManifold *m, float height);
ManifoldPolygons *manifold_project(void *mem, ManifoldManifold *m);

// Convex Hulls

Expand Down Expand Up @@ -157,11 +156,11 @@ ManifoldManifold *manifold_of_meshgl(void *mem, ManifoldMeshGL *mesh);
ManifoldManifold *manifold_smooth(void *mem, ManifoldMeshGL *mesh,
int *half_edges, float *smoothness,
int n_idxs);
ManifoldManifold *manifold_extrude(void *mem, ManifoldCrossSection *cs,
ManifoldManifold *manifold_extrude(void *mem, ManifoldPolygons *cs,
float height, int slices,
float twist_degrees, float scale_x,
float scale_y);
ManifoldManifold *manifold_revolve(void *mem, ManifoldCrossSection *cs,
ManifoldManifold *manifold_revolve(void *mem, ManifoldPolygons *cs,
int circular_segments);
ManifoldManifold *manifold_compose(void *mem, ManifoldManifoldVec *ms);
ManifoldManifoldVec *manifold_decompose(void *mem, ManifoldManifold *m);
Expand Down
13 changes: 6 additions & 7 deletions bindings/c/manifoldc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,14 @@ ManifoldManifold *manifold_trim_by_plane(void *mem, ManifoldManifold *m,
return to_c(new (mem) Manifold(trimmed));
}

ManifoldCrossSection *manifold_slice(void *mem, ManifoldManifold *m,
float height) {
ManifoldPolygons *manifold_slice(void *mem, ManifoldManifold *m, float height) {
auto poly = from_c(m)->Slice(height);
return to_c(new (mem) CrossSection(poly));
return to_c(new (mem) Polygons(poly));
}

ManifoldCrossSection *manifold_project(void *mem, ManifoldManifold *m) {
ManifoldPolygons *manifold_project(void *mem, ManifoldManifold *m) {
auto poly = from_c(m)->Project();
return to_c(new (mem) CrossSection(poly));
return to_c(new (mem) Polygons(poly));
}

ManifoldManifold *manifold_hull(void *mem, ManifoldManifold *m) {
Expand Down Expand Up @@ -382,7 +381,7 @@ ManifoldManifold *manifold_of_meshgl(void *mem, ManifoldMeshGL *mesh) {
return to_c(new (mem) Manifold(m));
}

ManifoldManifold *manifold_extrude(void *mem, ManifoldCrossSection *cs,
ManifoldManifold *manifold_extrude(void *mem, ManifoldPolygons *cs,
float height, int slices,
float twist_degrees, float scale_x,
float scale_y) {
Expand All @@ -391,7 +390,7 @@ ManifoldManifold *manifold_extrude(void *mem, ManifoldCrossSection *cs,
return to_c(new (mem) Manifold(m));
}

ManifoldManifold *manifold_revolve(void *mem, ManifoldCrossSection *cs,
ManifoldManifold *manifold_revolve(void *mem, ManifoldPolygons *cs,

int circular_segments) {
auto m = Manifold::Revolve(*from_c(cs), circular_segments);
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nanobind_add_module(
NB_STATIC STABLE_ABI LTO
autogen_docstrings.inl
manifold3d.cpp)
target_link_libraries(manifold3d PRIVATE manifold sdf polygon)
target_link_libraries(manifold3d PRIVATE manifold sdf polygon cross_section)
target_compile_options(manifold3d PRIVATE ${MANIFOLD_FLAGS} -DMODULE_NAME=manifold3d)
target_compile_features(manifold3d PUBLIC cxx_std_17)
set_target_properties(manifold3d PROPERTIES OUTPUT_NAME "manifold3d")
Expand Down
58 changes: 45 additions & 13 deletions bindings/python/manifold3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,18 @@ NB_MODULE(manifold3d, m) {
.def("trim_by_plane", &Manifold::TrimByPlane, nb::arg("normal"),
nb::arg("origin_offset"),
manifold__trim_by_plane__normal__origin_offset)
.def("slice", &Manifold::Slice, nb::arg("height"),
manifold__slice__height)
.def("project", &Manifold::Project, manifold__project)
.def(
"slice",
[](const Manifold &self, float height) {
return CrossSection(self.Slice(height));
},
nb::arg("height"), manifold__slice__height)
.def(
"project",
[](const Manifold &self) {
return CrossSection(self.Project()).Simplify(self.Precision());
},
manifold__project)
.def("status", &Manifold::Status, manifold__status)
.def(
"bounding_box",
Expand Down Expand Up @@ -402,14 +411,25 @@ NB_MODULE(manifold3d, m) {
.def_static("cube", &Manifold::Cube, nb::arg("size") = glm::vec3{1, 1, 1},
nb::arg("center") = false, manifold__cube__size__center)
.def_static(
"extrude", &Manifold::Extrude, nb::arg("crossSection"),
nb::arg("height"), nb::arg("n_divisions") = 0,
nb::arg("twist_degrees") = 0.0f,
"extrude",
[](const CrossSection &crossSection, float height, int nDivisions,
float twistDegrees, glm::vec2 scaleTop) {
return Manifold::Extrude(crossSection.ToPolygons(), height,
nDivisions, twistDegrees, scaleTop);
},
nb::arg("crossSection"), nb::arg("height"),
nb::arg("n_divisions") = 0, nb::arg("twist_degrees") = 0.0f,
nb::arg("scale_top") = std::make_tuple(1.0f, 1.0f),
manifold__extrude__cross_section__height__n_divisions__twist_degrees__scale_top)
.def_static(
"revolve", &Manifold::Revolve, nb::arg("crossSection"),
nb::arg("circular_segments") = 0, nb::arg("revolve_degrees") = 360.0,
"revolve",
[](const CrossSection &crossSection, int circularSegments,
float revolveDegrees) {
return Manifold::Revolve(crossSection.ToPolygons(),
circularSegments, revolveDegrees);
},
nb::arg("crossSection"), nb::arg("circular_segments") = 0,
nb::arg("revolve_degrees") = 360.0,
manifold__revolve__cross_section__circular_segments__revolve_degrees)
.def_static(
"cylinder", &Manifold::Cylinder, nb::arg("height"),
Expand Down Expand Up @@ -688,13 +708,25 @@ NB_MODULE(manifold3d, m) {
cross_section__compose__cross_sections)
.def("to_polygons", &CrossSection::ToPolygons, cross_section__to_polygons)
.def(
"extrude", &Manifold::Extrude, nb::arg("height"),
nb::arg("n_divisions") = 0, nb::arg("twist_degrees") = 0.0f,
"extrude",
[](const CrossSection &self, float height, int nDivisions,
float twistDegrees, glm::vec2 scaleTop) {
return Manifold::Extrude(self.ToPolygons(), height, nDivisions,
twistDegrees, scaleTop);
},
nb::arg("height"), nb::arg("n_divisions") = 0,
nb::arg("twist_degrees") = 0.0f,
nb::arg("scale_top") = std::make_tuple(1.0f, 1.0f),
manifold__extrude__cross_section__height__n_divisions__twist_degrees__scale_top)
.def("revolve", &Manifold::Revolve, nb::arg("circular_segments") = 0,
nb::arg("revolve_degrees") = 360.0,
manifold__revolve__cross_section__circular_segments__revolve_degrees)
.def(
"revolve",
[](const CrossSection &self, int circularSegments,
float revolveDegrees) {
return Manifold::Revolve(self.ToPolygons(), circularSegments,
revolveDegrees);
},
nb::arg("circular_segments") = 0, nb::arg("revolve_degrees") = 360.0,
manifold__revolve__cross_section__circular_segments__revolve_degrees)

.def_static("square", &CrossSection::Square, nb::arg("size"),
nb::arg("center") = false,
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ EMSCRIPTEN_BINDINGS(whatever) {
.function("_SplitByPlane", &man_js::SplitByPlane)
.function("_TrimByPlane", &Manifold::TrimByPlane)
.function("_Slice", &Manifold::Slice)
.function("project", &Manifold::Project)
.function("_Project", &Manifold::Project)
.function("hull", select_overload<Manifold() const>(&Manifold::Hull))
.function("_GetMeshJS", &js::GetMeshJS)
.function("refine", &Manifold::Refine)
Expand Down
13 changes: 9 additions & 4 deletions bindings/wasm/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,15 @@ Module.setup = function() {
height, nDivisions = 0, twistDegrees = 0.0, scaleTop = [1.0, 1.0],
center = false) {
scaleTop = vararg2vec2([scaleTop]);
const man =
Module._Extrude(this, height, nDivisions, twistDegrees, scaleTop);
const man = Module._Extrude(
this._ToPolygons(), height, nDivisions, twistDegrees, scaleTop);
return (center ? man.translate([0., 0., -height / 2.]) : man);
};

Module.CrossSection.prototype.revolve = function(
circularSegments = 0, revolveDegrees = 360.0) {
return Module._Revolve(this, circularSegments, revolveDegrees);
return Module._Revolve(
this._ToPolygons(), circularSegments, revolveDegrees);
};

Module.CrossSection.prototype.add = function(other) {
Expand Down Expand Up @@ -283,7 +284,11 @@ Module.setup = function() {
};

Module.Manifold.prototype.slice = function(height = 0.) {
return this._Slice(height);
return Module.CrossSection(this._Slice(height));
};

Module.Manifold.prototype.project = function() {
return Module.CrossSection(this._Project()).simplify(this.precision());
};

Module.Manifold.prototype.split = function(manifold) {
Expand Down
2 changes: 1 addition & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ target_include_directories(samples
)

target_link_libraries(samples
PUBLIC manifold sdf
PUBLIC manifold sdf cross_section
)

target_compile_options(samples PRIVATE ${MANIFOLD_FLAGS})
Expand Down
2 changes: 1 addition & 1 deletion samples/src/bracelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Manifold Base(float width, float radius, float decorRadius, float twistRadius,

CrossSection circle =
CrossSection::Circle(decorRadius, nDivision).Translate({twistRadius, 0});
Manifold decor = Manifold::Extrude(circle, width, nDivision, 180)
Manifold decor = Manifold::Extrude(circle.ToPolygons(), width, nDivision, 180)
.Scale({1.0f, 0.5f, 1.0f})
.Translate({0.0f, radius, 0.0f});

Expand Down
2 changes: 1 addition & 1 deletion samples/src/knot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Manifold TorusKnot(int p, int q, float majorRadius, float minorRadius,
linearSegments > 2 ? linearSegments : n * q * majorRadius / threadRadius;

CrossSection circle = CrossSection::Circle(1., n).Translate({2, 0});
Manifold knot = Manifold::Revolve(circle, m);
Manifold knot = Manifold::Revolve(circle.ToPolygons(), m);

knot =
knot.Warp([p, q, majorRadius, minorRadius, threadRadius](glm::vec3& v) {
Expand Down
2 changes: 1 addition & 1 deletion src/manifold/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
$<INSTALL_INTERFACE:include/${CMAKE_PROJECT_NAME}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
target_link_libraries(${PROJECT_NAME}
PUBLIC utilities cross_section sdf
PUBLIC utilities sdf
PRIVATE collider polygon ${MANIFOLD_INCLUDE} quickhull
)

Expand Down
9 changes: 4 additions & 5 deletions src/manifold/include/manifold.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <functional>
#include <memory>

#include "cross_section.h"
#include "public.h"
#include "vec_view.h"

Expand Down Expand Up @@ -174,10 +173,10 @@ class Manifold {
float radiusHigh = -1.0f, int circularSegments = 0,
bool center = false);
static Manifold Sphere(float radius, int circularSegments = 0);
static Manifold Extrude(const CrossSection& crossSection, float height,
static Manifold Extrude(const Polygons& crossSection, float height,
int nDivisions = 0, float twistDegrees = 0.0f,
glm::vec2 scaleTop = glm::vec2(1.0f));
static Manifold Revolve(const CrossSection& crossSection,
static Manifold Revolve(const Polygons& crossSection,
int circularSegments = 0,
float revolveDegrees = 360.0f);
///@}
Expand Down Expand Up @@ -279,8 +278,8 @@ class Manifold {
/** @name 2D from 3D
*/
///@{
CrossSection Slice(float height = 0) const;
CrossSection Project() const;
Polygons Slice(float height = 0) const;
Polygons Project() const;
///@}

/** @name Convex hull
Expand Down
Loading

0 comments on commit 85d71f5

Please sign in to comment.