Commit a1d6ad4d authored by Guillaume Seguin's avatar Guillaume Seguin

Add stl cutting functions and plumb it in the plater

parent 681e9989
......@@ -290,7 +290,20 @@ class StlPlater(Plater):
name = self.l.GetSelection()
name = self.l.GetString(name)
model = self.models[name]
print "Cutting", name, self.cutting_axis, self.cutting_direction, self.cutting_dist, model
transformation = transformation_matrix(model)
transformed = model.transform(transformation)
print _("Cutting %s alongside %s axis") % (name, self.cutting_axis)
axes = ["x", "y", "z"]
cut = transformed.cut(axes.index(self.cutting_axis),
self.cutting_direction,
self.cutting_dist)
cut.offsets = [0, 0, 0]
cut.rot = 0
cut.scale = model.scale
cut.filename = model.filename
cut.centeroffset = [0, 0, 0]
self.s.prepare_model(cut, 2)
self.models[name] = cut
self.cutconfirmbutton.Disable()
def clickcb(self, event, single = False):
......
......@@ -244,6 +244,31 @@ class stl(object):
newmodel = self.transform(matrix)
return newmodel
def cut(self, axis, direction, dist):
s = stl()
s.facets = []
f = min if direction == 1 else max
for _, facet in self.facets:
minval = f([vertex[axis] for vertex in facet])
if direction * minval > direction * dist:
continue
vertices = []
for vertex in facet:
vertex = numpy.copy(vertex)
if direction * (vertex[axis] - dist) > 0:
vertex[axis] = dist
vertices.append(vertex)
s.facets.append(genfacet(vertices))
s.insolid = 0
s.infacet = 0
s.inloop = 0
s.facetloc = 0
s.name = self.name
for facet in s.facets:
s.facetsminz += [(min(map(lambda x:x[2], facet[1])), facet)]
s.facetsmaxz += [(max(map(lambda x:x[2], facet[1])), facet)]
return s
def translation_matrix(self, v):
matrix = [[1, 0, 0, v[0]],
[0, 1, 0, v[1]],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment