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:
class Triangle:
id = 0
# 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
Triangle.id += 1
self.p1 = p1
......@@ -32,6 +32,7 @@ class Triangle:
self.e3 = Line(p3,p1)
else:
self.e3 = e3
self._normal = n
self._minx = None
self._miny = None
self._minz = None
......@@ -42,7 +43,6 @@ class Triangle:
self._middle = None
self._radius = None
self._radiussq = None
self._normal = None
self._plane = None
def __repr__(self):
......
......@@ -185,9 +185,9 @@ def ImportModel(filename, use_kdtree=True):
# make sure the points are in ClockWise order
dotcross = n.dot(p3.sub(p1).cross(p2.sub(p1)))
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:
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:
# the three points are in a line - or two points are identical
# usually this is caused by points, that are too close together
......@@ -195,10 +195,7 @@ def ImportModel(filename, use_kdtree=True):
print "ERROR: skipping invalid triangle: %s / %s / %s" % (p1, p2, p3)
n=p1=p2=p3=None
continue
t._normal = n
n=p1=p2=p3=None
if t.normal().z < 0:
continue
model.append(t)
continue
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