Skip to content
Snippets Groups Projects
Commit 8af9ef7f authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

RF: Mesh class potentially stores teo copies of triangles with opposite

winding order, to account for the possibility that different vertex sets
require different orders.
parent 51e03682
No related branches found
No related tags found
No related merge requests found
...@@ -98,6 +98,12 @@ class Mesh(notifier.Notifier, meta.Meta): ...@@ -98,6 +98,12 @@ class Mesh(notifier.Notifier, meta.Meta):
selectedVertices selectedVertices
vertexSets vertexSets
.. note:: Internally the ``Mesh`` class may store two versions of the
triangles, with opposite unwinding orders. It keeps track of the
required triangle unwinding order for each vertex set, so that
the :meth:`indices` method will return the appropriate copy for
the currently selected vertex set.
**Vertex data** **Vertex data**
...@@ -183,19 +189,17 @@ class Mesh(notifier.Notifier, meta.Meta): ...@@ -183,19 +189,17 @@ class Mesh(notifier.Notifier, meta.Meta):
self.__name = name self.__name = name
self.__dataSource = dataSource self.__dataSource = dataSource
self.__indices = np.asarray(indices).reshape((-1, 3)) self.__nvertices = indices.max() + 1
self.__nvertices = self.__indices.max() + 1 self.__selected = None
# This attribute is used to store # We potentially store two copies of
# the currently selected vertex set, # the indices, with opposite unwinding
# used as a kety into all of the # orders. The vindices dict stores refs
# dictionaries below. # to one or the other for each vertex
self.__selected = None # set.
self.__indices = np.asarray(indices).reshape((-1, 3))
# Flag used to keep track of whether self.__fixedIndices = None
# the triangle winding order has been self.__vindices = collections.OrderedDict()
# "fixed" - see the addVertices method.
self.__fixed = False
# All of these are populated # All of these are populated
# in the addVertices method # in the addVertices method
...@@ -287,7 +291,7 @@ class Mesh(notifier.Notifier, meta.Meta): ...@@ -287,7 +291,7 @@ class Mesh(notifier.Notifier, meta.Meta):
@property @property
def indices(self): def indices(self):
"""The ``(M, 3)`` triangles of this mesh. """ """The ``(M, 3)`` triangles of this mesh. """
return self.__indices return self.__vindices[self.__selected]
@property @property
...@@ -297,7 +301,7 @@ class Mesh(notifier.Notifier, meta.Meta): ...@@ -297,7 +301,7 @@ class Mesh(notifier.Notifier, meta.Meta):
""" """
selected = self.__selected selected = self.__selected
indices = self.__indices indices = self.__vindices[selected]
vertices = self.__vertices[selected] vertices = self.__vertices[selected]
fnormals = self.__faceNormals.get(selected, None) fnormals = self.__faceNormals.get(selected, None)
...@@ -315,7 +319,7 @@ class Mesh(notifier.Notifier, meta.Meta): ...@@ -315,7 +319,7 @@ class Mesh(notifier.Notifier, meta.Meta):
""" """
selected = self.__selected selected = self.__selected
indices = self.__indices indices = self.__vindices[selected]
vertices = self.__vertices[selected] vertices = self.__vertices[selected]
vnormals = self.__vertNormals.get(selected, None) vnormals = self.__vertNormals.get(selected, None)
...@@ -334,10 +338,8 @@ class Mesh(notifier.Notifier, meta.Meta): ...@@ -334,10 +338,8 @@ class Mesh(notifier.Notifier, meta.Meta):
``((xlow, ylow, zlow), (xhigh, yhigh, zhigh))`` ``((xlow, ylow, zlow), (xhigh, yhigh, zhigh))``
""" """
lo = self.__loBounds[self.__selected] lo = self.__loBounds[self.__selected]
hi = self.__hiBounds[self.__selected] hi = self.__hiBounds[self.__selected]
return lo, hi return lo, hi
...@@ -411,26 +413,26 @@ class Mesh(notifier.Notifier, meta.Meta): ...@@ -411,26 +413,26 @@ class Mesh(notifier.Notifier, meta.Meta):
self.nvertices)) self.nvertices))
self.__vertices[key] = vertices self.__vertices[key] = vertices
self.__vindices[key] = self.__indices
self.__loBounds[key] = lo self.__loBounds[key] = lo
self.__hiBounds[key] = hi self.__hiBounds[key] = hi
if select: if select:
self.vertices = key self.vertices = key
# indices already fixed? if fixWinding:
if fixWinding and (not self.__fixed): indices = self.__indices
indices = self.indices normals = self.normals
normals = self.normals needsFix = needsFixing(vertices, indices, normals, lo, hi)
needsFix = needsFixing(vertices, indices, normals, lo, hi)
self.__fixed = True
# See needsFixing documentation # See needsFixing documentation
if needsFix: if needsFix:
indices[:, [1, 2]] = indices[:, [2, 1]] if self.__fixedIndices is None:
self.__fixedIndices = indices[:, [0, 2, 1]]
for k, fn in self.__faceNormals.items(): self.__vindices[ key] = self.__fixedIndices
self.__faceNormals[k] = fn * -1 self.__faceNormals[key] = normals * -1
return vertices return vertices
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment