Commit 362207d6 authored by Guillaume Seguin's avatar Guillaume Seguin

Compute stl dims in stltool

parent d73b1100
......@@ -307,27 +307,6 @@ class StlPlater(Plater):
model.rot = rotation
model.scale = list(scale)
model.filename = name
minx = float("inf")
miny = float("inf")
minz = float("inf")
maxx = float("-inf")
maxy = float("-inf")
maxz = float("-inf")
for i in model.facets:
for j in i[1]:
if j[0] < minx:
minx = j[0]
if j[1] < miny:
miny = j[1]
if j[2] < minz:
minz = j[2]
if j[0] > maxx:
maxx = j[0]
if j[1] > maxy:
maxy = j[1]
if j[2] > maxz:
maxz = j[2]
model.dims = [minx, maxx, miny, maxy, minz, maxz]
self.add_model(name, model)
model.centeroffset = [-(model.dims[1] + model.dims[0]) / 2,
-(model.dims[3] + model.dims[2]) / 2,
......
......@@ -89,6 +89,35 @@ def emitstl(filename, facets = [], objname = "stltool_export", binary = 1):
class stl(object):
_dims = None
def _get_dims(self):
if self._dims is None:
minx = float("inf")
miny = float("inf")
minz = float("inf")
maxx = float("-inf")
maxy = float("-inf")
maxz = float("-inf")
for normal, facet in self.facets:
for vert in facet:
if vert[0] < minx:
minx = vert[0]
if vert[1] < miny:
miny = vert[1]
if vert[2] < minz:
minz = vert[2]
if vert[0] > maxx:
maxx = vert[0]
if vert[1] > maxy:
maxy = vert[1]
if vert[2] > maxz:
maxz = vert[2]
self._dims = [minx, maxx, miny, maxy, minz, maxz]
return self._dims
dims = property(_get_dims)
def __init__(self, filename = None):
self.facet = [[0, 0, 0], [[0, 0, 0], [0, 0, 0], [0, 0, 0]]]
self.facets = []
......@@ -145,7 +174,6 @@ class stl(object):
return self.transform(matrix)
def rotate(self, v = [0, 0, 0]):
import math
z = v[2]
matrix1 = [[math.cos(math.radians(z)), -math.sin(math.radians(z)), 0, 0],
[math.sin(math.radians(z)), math.cos(math.radians(z)), 0, 0],
......
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