From a45c84c183fda9bb3148a4b1eeed5e4a33a430c6 Mon Sep 17 00:00:00 2001 From: "Stephen M. McQuay" Date: Thu, 7 Jun 2012 22:24:52 -0600 Subject: [PATCH] Started adding connectivity generation - also added a test file in the blender folder --- blender/samples/cube-gimp.json | 1 + surf/geometry.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 blender/samples/cube-gimp.json diff --git a/blender/samples/cube-gimp.json b/blender/samples/cube-gimp.json new file mode 100644 index 0000000..06a928d --- /dev/null +++ b/blender/samples/cube-gimp.json @@ -0,0 +1 @@ +{"edges": [[4, 5], [5, 1], [1, 0], [0, 4], [5, 6], [6, 2], [2, 1], [6, 7], [7, 3], [3, 2], [7, 4], [0, 3]], "vertices": [[-1.0, -1.0, -1.0], [-1.0, 1.0, -1.0], [1.0, 1.0, -1.0], [1.0, -1.0, -1.0], [-1.0, -1.0, 1.0], [-1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, -1.0, 1.0]], "faces": [[4, 5, 1, 0], [5, 6, 2, 1], [6, 7, 3, 2], [7, 4, 0, 3], [0, 1, 2, 3], [7, 6, 5, 4]]} \ No newline at end of file diff --git a/surf/geometry.py b/surf/geometry.py index c780317..88ab767 100644 --- a/surf/geometry.py +++ b/surf/geometry.py @@ -175,25 +175,30 @@ class PolygonMesh(object): @property def edges_for_face(self): """returns a list of edge indices for a given face index.""" + # XXX if self._edges_for_face is None: - # TODO: eventually support generating this ourselves ... - raise NotImplementedError + self._edges_for_face = [[] for i in range(len(self.faces))] + return self._edges_for_face @property def edges_for_vert(self): """returns a list of edge indices for a given vertex index.""" if self._edges_for_vert is None: - # TODO: eventually support generating this ourselves ... - raise NotImplementedError + self._edges_for_vert = [[] for i in range(len(self.vertices))] + for i, edge in enumerate(self.edges): + for vid in edge: + self._edges_for_vert[vid].append(i) return self._edges_for_vert @property def faces_for_vert(self): """returns a list of face indices for a given vert index.""" if self._faces_for_vert is None: - # TODO: eventually support generating this ourselves ... - raise NotImplementedError + self._faces_for_vert = [[] for i in range(len(self.vertices))] + for i, face in enumerate(self.faces): + for vid in face: + self._faces_for_vert[vid].append(i) return self._faces_for_vert def __unicode__(self):