Only build the layer data mesh after we have received all the polygons

Certain polygons might be added to a layer later, so to prevent issues
when using range drawing, we need to wait until we have all layer data
then process that in the right order.
This commit is contained in:
Arjen Hiemstra 2015-04-28 11:30:52 +02:00
parent 23e5bcc55b
commit 9dbff5a109
2 changed files with 27 additions and 13 deletions

View file

@ -8,7 +8,7 @@ class LayerData(MeshData):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._layers = {} self._layers = {}
self._element_counts = [] self._element_counts = {}
def addPolygon(self, layer, type, data): def addPolygon(self, layer, type, data):
if layer not in self._layers: if layer not in self._layers:
@ -16,7 +16,6 @@ class LayerData(MeshData):
p = Polygon(self, type, data) p = Polygon(self, type, data)
self._layers[layer].append(p) self._layers[layer].append(p)
self._element_counts.append(p.count)
def getLayers(self): def getLayers(self):
return self._layers return self._layers
@ -24,6 +23,15 @@ class LayerData(MeshData):
def getElementCounts(self): def getElementCounts(self):
return self._element_counts return self._element_counts
def build(self):
for layer, data in self._layers.items():
if layer not in self._element_counts:
self._element_counts[layer] = []
for polygon in data:
polygon.build()
self._element_counts[layer].append(polygon.count)
class Polygon(): class Polygon():
NoneType = 0 NoneType = 0
Inset0Type = 1 Inset0Type = 1
@ -34,27 +42,31 @@ class Polygon():
def __init__(self, mesh, type, data): def __init__(self, mesh, type, data):
super().__init__() super().__init__()
self._mesh = mesh
self._type = type self._type = type
self._begin = mesh._vertex_count self._data = data
mesh.addVertices(data)
self._end = self._begin + len(data) - 1 def build(self):
self._begin = self._mesh._vertex_count
self._mesh.addVertices(self._data)
self._end = self._begin + len(self._data) - 1
color = None color = None
if type == self.Inset0Type: if self._type == self.Inset0Type:
color = [1, 0, 0, 1] color = [1, 0, 0, 1]
elif type == self.InsetXType: elif self._type == self.InsetXType:
color = [0, 1, 0, 1] color = [0, 1, 0, 1]
elif type == self.SkinType: elif self._type == self.SkinType:
color = [1, 1, 0, 1] color = [1, 1, 0, 1]
elif type == self.SupportType: elif self._type == self.SupportType:
color = [0, 1, 1, 1] color = [0, 1, 1, 1]
elif type == self.SkirtType: elif self._type == self.SkirtType:
color = [0, 1, 1, 1] color = [0, 1, 1, 1]
else: else:
color = [1, 1, 1, 1] color = [1, 1, 1, 1]
colors = [color for i in range(len(data))] colors = [color for i in range(len(self._data))]
mesh.addColors(numpy.array(colors, dtype=numpy.float32)) self._mesh.addColors(numpy.array(colors, dtype=numpy.float32))
indices = [] indices = []
for i in range(self._begin, self._end): for i in range(self._begin, self._end):
@ -63,7 +75,7 @@ class Polygon():
indices.append(self._end) indices.append(self._end)
indices.append(self._begin) indices.append(self._begin)
mesh.addIndices(numpy.array(indices, dtype=numpy.int32)) self._mesh.addIndices(numpy.array(indices, dtype=numpy.int32))
@property @property
def type(self): def type(self):

View file

@ -54,6 +54,8 @@ class ProcessSlicedObjectListJob(Job):
layerData.addPolygon(layer.id, polygon.type, points) layerData.addPolygon(layer.id, polygon.type, points)
# We are done processing all the layers we got from the engine, now create a mesh out of the data
layerData.build()
mesh.layerData = layerData mesh.layerData = layerData
new_node.setMeshData(mesh) new_node.setMeshData(mesh)