Skip to content

Commit

Permalink
adding test of properties
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish committed Jul 26, 2023
1 parent 18edefc commit 5148b2a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,8 @@
"Verts"
],
"javascript.format.semicolons": "insert",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none",
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ node test/manifold_test.js
### Python

The CMake script will build the python binding `manifold3d` automatically. To
use the extension, please add `$BUILD_DIR/tools` to your `PYTHONPATH`, where
use the extension, please add `$BUILD_DIR/bindings/python` to your `PYTHONPATH`, where
`$BUILD_DIR` is the build directory for CMake. Examples using the python binding
can be found in `bindings/python/examples`. To see exported samples, run:
```
Expand Down
39 changes: 39 additions & 0 deletions bindings/python/examples/sponge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from manifold3d import Manifold


def fractal(holes, hole, w, position, depth, maxDepth):
w /= 3
holes.append(hole.scale([w, w, 1.0]).translate([position[0], position[1], 0.0]))
if depth == maxDepth:
return
offsets = [
[-w, -w],
[-w, 0.0],
[-w, w],
[0.0, w],
[w, w],
[w, 0.0],
[w, -w],
[0.0, -w],
]
for offset in offsets:
fractal(holes, hole, w, position + offset, depth + 1, maxDepth)


def posColors(newProp, pos):
for i in [0, 1, 2]:
newProp[i] = (1 - pos[i]) / 2


def run(n=1):
result = Manifold.cube([1, 1, 1], True)
holes = []
fractal(holes, result, 1.0, [0.0, 0.0], 1, n)

hole = Manifold.compose(holes)

result -= hole
result -= hole.rotate([90, 0, 0])
result -= hole.rotate([0, 90, 0])

return result.trim_by_plane([1, 1, 1], 0).setProperties(3, posColors).scale(100)
32 changes: 32 additions & 0 deletions bindings/python/manifold3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,31 @@ PYBIND11_MODULE(manifold3d, m) {
"the user to choose their function with discretion."
"\n\n"
":param warpFunc: A function that modifies a given vertex position.")
.def(
"set_properties",
[](Manifold &self, int newNumProp,
const std::function<void(py::array_t<float> &, Float3,
const py::array_t<float> &)> &f) {
const int oldNumProp = self.NumProp();
return self.SetProperties(newNumProp, [newNumProp, oldNumProp, &f](
float *newProps,
glm::vec3 v,
const float *oldProps) {
f(py::array(newNumProp, newProps), std::make_tuple(v.x, v.y, v.z),
py::array(oldNumProp, oldProps));
});
},
py::arg("new_num_prop"), py::arg("f"),
"Create a new copy of this manifold with updated vertex properties "
"by supplying a function that takes the existing position and "
"properties as input. You may specify any number of output "
"properties, allowing creation and removal of channels. Note: "
"undefined behavior will result if you read past the number of input "
"properties or write past the number of output properties."
"\n\n"
":param numProp: The new number of properties per vertex."
":param propFunc: A function that modifies the properties of a given "
"vertex.")
.def(
"refine", [](Manifold &self, int n) { return self.Refine(n); },
py::arg("n"),
Expand Down Expand Up @@ -428,6 +453,13 @@ PYBIND11_MODULE(manifold3d, m) {
.def_static(
"from_mesh", [](const MeshGL &mesh) { return Manifold(mesh); },
py::arg("mesh"))
.def_static(
"compose",
[](const std::vector<Manifold> &list) {
return Manifold::Compose(list);
},
"combine several manifolds into one without checking for "
"intersections.")
.def_static(
"tetrahedron", []() { return Manifold::Tetrahedron(); },
"Constructs a tetrahedron centered at the origin with one vertex at "
Expand Down

0 comments on commit 5148b2a

Please sign in to comment.