getting closer, its starting to look like it...

This commit is contained in:
William Blattman 2012-03-18 21:57:44 -07:00
parent a93c047a5d
commit 805edfe12f

View File

@ -88,7 +88,7 @@ class Vertex(object):
'''
A vertex is a position along with other information such as color, normal vector and texture coordinates.
'''
def __init__(self, x, y, z):
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
self.z = z
@ -97,6 +97,24 @@ class Vertex(object):
def __repr__(self):
return "<%.2f, %.2f, %.2f>" % (self.x, self.y, self.z)
def __add__(self, other):
# for now just assume type(other) = Vertex... bad, I know
return Vertex(self.x + other.x, self.y + other.y, self.z + other.z)
def __radd__(self, other):
return self.__add__(other)
def __mul__(self, other):
# for now just assume type(other) = int or float
return Vertex(self.x * other, self.y * other, self.z * other)
def __rmul__(self, other):
return self.__mul__(other)
def __div__(self, other):
# same assumption as __mult__
return Vertex(self.x / other, self.y / other, self.z / other)
class Edge(object):
'''
'''
@ -112,6 +130,9 @@ class Edge(object):
return self.faces[1]
else:
return self.faces[0]
def __getMidPoint(self):
return sum(self.vertices, Vertex())/len(self.vertices)
midPoint = property(fget=__getMidPoint)
def __getSubEdges(self):
if not self.__subEdges:
@ -261,11 +282,17 @@ class Polygon(object):
For each original vertex P, take the average F of all n face vertices for faces touching P, and take the average R of all n edge midvertices for edges touching P, where each edge midvertex is the average of its two endvertex vertices. Move each original vertex to the vertex
'''
# each face knows how to subdivide and create a set of subfaces, including interior edges and setup their references correctly... <- not completely finished...
p = Polygon()
edges = []
vertices = []
faces = []
for face in self.faces:
for subFace in face.subFaces:
faces.append(subFace)
@ -273,9 +300,39 @@ class Polygon(object):
edges.append(edge)
for vertex in edge.vertices:
vertices.append(vertex)
for vertex in self.vertices:
faceVertices = []
edgeMidPoints = []
for edge in vertex.edges:
edgeMidPoints.append(edge.midPoint)
for face in edge.faces:
faceVertices.append(face.centroid)
f = sum(list(set(faceVertices)), Vertex())/len(list(set(faceVertices)))
r = sum(list(set(edgeMidPoints)), Vertex())/len(list(set(edgeMidPoints)))
p = vertex
n = len(vertex.edges)
v = (f + (2.0 * r) + (n - 3.0) * p) / n
# print v
vertex.x = v.x
vertex.y = v.y
vertex.z = v.z
# so now what.........
# (F + 2R + (n-3) P) / n
#
# F = average of all face vertices touching P
# R = average of all edge vertices touching P
# P original point
# n = number of edges connecting to P
p.faces = faces
p.vertices = vertices
p.edges = edges
# plotting these in excel seems to show the correct values (at first glace...)
# so now what.........
@ -293,6 +350,7 @@ def createPolygon():
v.append(Vertex(1.0, 1.0, 0.0))
v.append(Vertex(1.0, 0.0, 0.0))
v.append(Vertex(0.0, 0.0, 0.0))
v.append(Vertex(0.0, 1.0, 1.0))
v.append(Vertex(1.0, 1.0, 1.0))
v.append(Vertex(1.0, 0.0, 1.0))
@ -327,7 +385,7 @@ def createPolygon():
v[3].edges = [e[2], e[7], e[3]]
v[4].edges = [e[4], e[11], e[8]]
v[5].edges = [e[5], e[9], e[8]]
v[6].edges = [e[2], e[9], e[10]]
v[6].edges = [e[6], e[9], e[10]]
v[7].edges = [e[7], e[10], e[11]]
# face list
@ -339,16 +397,16 @@ def createPolygon():
f[5].edges = [e[10], e[9], e[8], e[11]]
#winged edges ordered by face, then by vertex reference
e[0].vertices, e[0].faces, e[0].edges = [v[0], v[1]], [f[0], f[4]], [e[3], e[1], e[4], e[5]]
e[1].vertices, e[1].faces, e[1].edges = [v[1], v[2]], [f[0], f[1]], [e[0], e[2], e[5], e[6]]
e[2].vertices, e[2].faces, e[2].edges = [v[2], v[3]], [f[0], f[2]], [e[3], e[7], e[1], e[6]]
e[3].vertices, e[3].faces, e[3].edges = [v[3], v[0]], [f[3], f[0]], [e[4], e[7], e[0], e[2]]
e[4].vertices, e[4].faces, e[4].edges = [v[0], v[4]], [f[3], f[4]], [e[11], e[3], e[0], e[8]]
e[5].vertices, e[5].faces, e[5].edges = [v[5], v[1]], [f[4], f[1]], [e[8], e[0], e[9], e[1]]
e[6].vertices, e[6].faces, e[6].edges = [v[2], v[6]], [f[1], f[2]], [e[1], e[9], e[2], e[10]]
e[7].vertices, e[7].faces, e[7].edges = [v[7], v[3]], [f[3], f[2]], [e[11], e[3], e[10], e[2]]
e[8].vertices, e[8].faces, e[8].edges = [v[4], v[5]], [f[4], f[5]], [e[4], e[5], e[11], e[9]]
e[9].vertices, e[9].faces, e[9].edges = [v[5], v[6]], [f[1], f[5]], [e[5], e[6], e[8], e[10]]
e[0].vertices, e[0].faces, e[0].edges = [v[0], v[1]], [f[0], f[4]], [e[3], e[1], e[4], e[5]]
e[1].vertices, e[1].faces, e[1].edges = [v[1], v[2]], [f[0], f[1]], [e[0], e[2], e[5], e[6]]
e[2].vertices, e[2].faces, e[2].edges = [v[2], v[3]], [f[0], f[2]], [e[1], e[3], e[6], e[7]]
e[3].vertices, e[3].faces, e[3].edges = [v[3], v[0]], [f[3], f[0]], [e[4], e[7], e[0], e[2]]
e[4].vertices, e[4].faces, e[4].edges = [v[0], v[4]], [f[3], f[4]], [e[11], e[3], e[0], e[8]]
e[5].vertices, e[5].faces, e[5].edges = [v[5], v[1]], [f[4], f[1]], [e[8], e[0], e[9], e[1]]
e[6].vertices, e[6].faces, e[6].edges = [v[2], v[6]], [f[1], f[2]], [e[1], e[9], e[2], e[10]]
e[7].vertices, e[7].faces, e[7].edges = [v[7], v[3]], [f[3], f[2]], [e[11], e[3], e[10], e[2]]
e[8].vertices, e[8].faces, e[8].edges = [v[4], v[5]], [f[4], f[5]], [e[4], e[5], e[11], e[9]]
e[9].vertices, e[9].faces, e[9].edges = [v[5], v[6]], [f[1], f[5]], [e[5], e[6], e[8], e[10]]
e[10].vertices, e[10].faces, e[10].edges = [v[7], v[6]], [f[2], f[5]], [e[7], e[6], e[11], e[9]]
e[11].vertices, e[11].faces, e[11].edges = [v[4], v[7]], [f[3], f[5]], [e[4], e[7], e[8], e[10]]