Commit 49d166b2 authored by lode_leroy's avatar lode_leroy

fix triangle normal initialization

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@78 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 18b81f52
...@@ -14,7 +14,7 @@ except: ...@@ -14,7 +14,7 @@ except:
class Triangle: class Triangle:
id = 0 id = 0
# points are expected to be in ClockWise order # points are expected to be in ClockWise order
def __init__(self, p1=None, p2=None, p3=None, e1=None, e2=None, e3=None): def __init__(self, p1=None, p2=None, p3=None, e1=None, e2=None, e3=None, n=None):
self.id = Triangle.id self.id = Triangle.id
Triangle.id += 1 Triangle.id += 1
self.p1 = p1 self.p1 = p1
...@@ -32,6 +32,7 @@ class Triangle: ...@@ -32,6 +32,7 @@ class Triangle:
self.e3 = Line(p3,p1) self.e3 = Line(p3,p1)
else: else:
self.e3 = e3 self.e3 = e3
self._normal = n
self._minx = None self._minx = None
self._miny = None self._miny = None
self._minz = None self._minz = None
...@@ -42,7 +43,6 @@ class Triangle: ...@@ -42,7 +43,6 @@ class Triangle:
self._middle = None self._middle = None
self._radius = None self._radius = None
self._radiussq = None self._radiussq = None
self._normal = None
self._plane = None self._plane = None
def __repr__(self): def __repr__(self):
......
...@@ -185,9 +185,9 @@ def ImportModel(filename, use_kdtree=True): ...@@ -185,9 +185,9 @@ def ImportModel(filename, use_kdtree=True):
# 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:
t = Triangle(p1, p2, p3, UniqueEdge(p1,p2), UniqueEdge(p2,p3), UniqueEdge(p3,p1)) t = Triangle(p1, p2, p3, UniqueEdge(p1,p2), UniqueEdge(p2,p3), UniqueEdge(p3,p1), n)
elif dotcross < 0: elif dotcross < 0:
t = Triangle(p1, p3, p2, UniqueEdge(p1,p3), UniqueEdge(p3,p2), UniqueEdge(p2,p1)) t = Triangle(p1, p3, p2, UniqueEdge(p1,p3), UniqueEdge(p3,p2), UniqueEdge(p2,p1), n)
else: else:
# the three points are in a line - or two points are identical # the three points are in a line - or two points are identical
# usually this is caused by points, that are too close together # usually this is caused by points, that are too close together
...@@ -195,10 +195,7 @@ def ImportModel(filename, use_kdtree=True): ...@@ -195,10 +195,7 @@ def ImportModel(filename, use_kdtree=True):
print "ERROR: skipping invalid triangle: %s / %s / %s" % (p1, p2, p3) print "ERROR: skipping invalid triangle: %s / %s / %s" % (p1, p2, p3)
n=p1=p2=p3=None n=p1=p2=p3=None
continue continue
t._normal = n
n=p1=p2=p3=None n=p1=p2=p3=None
if t.normal().z < 0:
continue
model.append(t) model.append(t)
continue continue
m = endsolid.match(line) m = endsolid.match(line)
......
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