Commit d38c7c85 authored by lode_leroy's avatar lode_leroy

fix STL model without normals

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@68 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent e6fd1fa8
...@@ -118,8 +118,8 @@ def ImportModel(filename, use_kdtree=True): ...@@ -118,8 +118,8 @@ def ImportModel(filename, use_kdtree=True):
solid = re.compile("\s*solid\s+(\w+)\s+.*") solid = re.compile("\s*solid\s+(\w+)\s+.*")
solid_AOI = re.compile("\s*solid\s+\"([\w\-]+)\"; Produced by Art of Illusion.*") solid_AOI = re.compile("\s*solid\s+\"([\w\-]+)\"; Produced by Art of Illusion.*")
endsolid = re.compile("\s*endsolid\s+") endsolid = re.compile("\s*endsolid\s*")
facet = re.compile("\s*facet\s+") facet = re.compile("\s*facet\s*")
normal = re.compile("\s*facet\s+normal\s+(?P<x>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<y>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<z>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+") normal = re.compile("\s*facet\s+normal\s+(?P<x>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<y>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<z>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+")
endfacet = re.compile("\s*endfacet\s+") endfacet = re.compile("\s*endfacet\s+")
loop = re.compile("\s*outer\s+loop\s+") loop = re.compile("\s*outer\s+loop\s+")
...@@ -145,6 +145,8 @@ def ImportModel(filename, use_kdtree=True): ...@@ -145,6 +145,8 @@ def ImportModel(filename, use_kdtree=True):
n = Point(float(m.group('x')),float(m.group('z')),float(m.group('y'))) n = Point(float(m.group('x')),float(m.group('z')),float(m.group('y')))
else: else:
n = Point(float(m.group('x')),float(m.group('y')),float(m.group('z'))) n = Point(float(m.group('x')),float(m.group('y')),float(m.group('z')))
else:
n = None
continue continue
m = loop.match(line) m = loop.match(line)
if m: if m:
...@@ -169,6 +171,10 @@ def ImportModel(filename, use_kdtree=True): ...@@ -169,6 +171,10 @@ def ImportModel(filename, use_kdtree=True):
continue continue
m = endfacet.match(line) m = endfacet.match(line)
if m: if m:
if not n:
n = p3.sub(p1).cross(p2.sub(p1))
n.normalize()
# make sure the points are in ClockWise order # make sure the points are in ClockWise order
dotcross = n.dot(p3.sub(p1).cross(p2.sub(p1))) dotcross = n.dot(p3.sub(p1).cross(p2.sub(p1)))
if dotcross > 0: if dotcross > 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