From af8e67321597b61a4ce59710bf07d8fee095534d Mon Sep 17 00:00:00 2001 From: Chris Hodapp Date: Tue, 24 Sep 2019 04:25:13 +0200 Subject: [PATCH] Write join_boundary_simple --- Scratch.ipynb | 18 ++++++++++++++++++ meshutil.py | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Scratch.ipynb b/Scratch.ipynb index ab708c2..007a7a0 100644 --- a/Scratch.ipynb +++ b/Scratch.ipynb @@ -12,6 +12,24 @@ "import trimesh" ] }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "b1 = numpy.array([\n", + " [0, 0, 0],\n", + " [1, 0, 0],\n", + " [1, 1, 0],\n", + " [0, 1, 0],\n", + "], dtype=numpy.float64)\n", + "b2 = numpy.array(b1 + [0,0,1])\n", + "\n", + "testmesh = meshutil.join_boundary_simple(b1, b2)\n", + "testmesh.to_stl_mesh().save(\"simple.stl\")" + ] + }, { "cell_type": "code", "execution_count": 65, diff --git a/meshutil.py b/meshutil.py index a9188fc..24779fe 100644 --- a/meshutil.py +++ b/meshutil.py @@ -135,3 +135,22 @@ def cube_distort(angle, open_xz=False): faces[11,:] = [0, 5, 4] # winding order? return FaceVertexMesh(verts, faces) + +def join_boundary_simple(bound1, bound2): + # bound1 & bound2 are both arrays of shape (N,3), representing + # the points of a boundary. This joins the two boundaries by + # simply connecting quads (made of 2 triangles) straight across. + # + # Winding will proceed in the direction of the first boundary. + #` + # Returns FaceVertexMesh. + n = bound1.shape[0] + vs = numpy.concatenate([bound1, bound2]) + # Indices 0...N-1 are from bound1, N...2*N-1 are from bound2 + fs = numpy.zeros((2*n, 3), dtype=int) + for i in range(n): + v0 = i + v1 = (i + 1) % n + fs[2*i] = [n + v1, n + v0, v0] + fs[2*i + 1] = [v1, n + v1, v0] + return FaceVertexMesh(vs, fs)