In the middle of implementing Catmull-Clark
This commit is contained in:
+11
-49
@@ -25,11 +25,10 @@ def cross(a, b):
|
||||
k = a.x * b.y - a.y * b.x
|
||||
return Vertex(i, j, k)
|
||||
|
||||
|
||||
def _centroid(verts):
|
||||
xs = [vertex.x for vertex in verts]
|
||||
ys = [vertex.y for vertex in verts]
|
||||
zs = [vertex.z for vertex in verts]
|
||||
def centroid(verts):
|
||||
xs = [v.x for v in verts]
|
||||
ys = [v.y for v in verts]
|
||||
zs = [v.z for v in verts]
|
||||
|
||||
# average each vertex component
|
||||
x = sum(xs) / len(xs)
|
||||
@@ -38,7 +37,6 @@ def _centroid(verts):
|
||||
|
||||
return Vertex(x, y, z)
|
||||
|
||||
|
||||
class Vertex(object):
|
||||
'''
|
||||
A vertex is a position along with other information such as color, normal
|
||||
@@ -86,52 +84,12 @@ class Vertex(object):
|
||||
return Vertex(-self.x, -self.y, -self.z)
|
||||
|
||||
def __unicode__(self):
|
||||
return pprint.pformat([self.x, self.y, self.z])
|
||||
return u'V{0}'.format([self.x, self.y, self.z])
|
||||
|
||||
__str__ = __unicode__
|
||||
__repr__ = __unicode__
|
||||
|
||||
|
||||
class Edge(object):
|
||||
def __init__(self, v1, v2):
|
||||
self.v1 = v1
|
||||
self.v2 = v2
|
||||
|
||||
@property
|
||||
def centroid(self):
|
||||
return _centroid([self.v1, self.v2])
|
||||
|
||||
def __unicode__(self):
|
||||
return pprint.pformat((self.v1, self.v2))
|
||||
|
||||
__str__ = __unicode__
|
||||
__repr__ = __unicode__
|
||||
|
||||
|
||||
class Face(object):
|
||||
'''
|
||||
A face is a closed set of edges, in which a triangle face has three edges,
|
||||
and a quad face has four edges. Blender stores a face as a collection of
|
||||
the verts that compose it, so we shall store them thusly as well.
|
||||
|
||||
Blender historicaly only supported faces with an edge count of three or
|
||||
four. We will cross the N-gon bridge in the future.
|
||||
'''
|
||||
|
||||
def __init__(self, verts=None):
|
||||
self.verts = verts or []
|
||||
|
||||
def __unicode__(self):
|
||||
return pprint.pformat(self.verts)
|
||||
|
||||
__str__ = __unicode__
|
||||
__repr__ = __unicode__
|
||||
|
||||
@property
|
||||
def centroid(self):
|
||||
return _centroid(self.verts)
|
||||
|
||||
|
||||
class PolygonMesh(object):
|
||||
'''
|
||||
A polygon object is a collection of the following lists:
|
||||
@@ -146,7 +104,7 @@ class PolygonMesh(object):
|
||||
'''
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.vertices = kwargs['vertices']
|
||||
self.vertices = [Vertex(*v) for v in kwargs['vertices']]
|
||||
self.edges = kwargs['edges']
|
||||
self.faces = kwargs['faces']
|
||||
|
||||
@@ -168,7 +126,7 @@ class PolygonMesh(object):
|
||||
>>> mesh.faces_for_edge[0]
|
||||
[0, 1]
|
||||
>>> [self.face[i] for i in mesh.faces_for_edge[1]]
|
||||
[<Face 0>, <Face 1>]
|
||||
[[...], [...], ...]
|
||||
|
||||
where 0 and 1 are indices into the face list
|
||||
"""
|
||||
@@ -216,3 +174,7 @@ class PolygonMesh(object):
|
||||
|
||||
__str__ = __unicode__
|
||||
__repr__ = __unicode__
|
||||
|
||||
def centroid(self, vert_ids):
|
||||
verts = [self.vertices[vid] for vid in vert_ids]
|
||||
return centroid(verts)
|
||||
|
||||
Reference in New Issue
Block a user