Write join_boundary_simple

This commit is contained in:
Chris Hodapp 2019-09-24 04:25:13 +02:00
parent fd3d3b91a5
commit af8e673215
2 changed files with 37 additions and 0 deletions

View File

@ -12,6 +12,24 @@
"import trimesh" "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", "cell_type": "code",
"execution_count": 65, "execution_count": 65,

View File

@ -135,3 +135,22 @@ def cube_distort(angle, open_xz=False):
faces[11,:] = [0, 5, 4] faces[11,:] = [0, 5, 4]
# winding order? # winding order?
return FaceVertexMesh(verts, faces) 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)