mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-10 08:17:49 -06:00
Support colours for rendering the layer view
This commit is contained in:
parent
4e6322d94e
commit
800faf6bcf
1 changed files with 33 additions and 3 deletions
36
LayerData.py
36
LayerData.py
|
@ -1,4 +1,5 @@
|
||||||
from UM.Mesh.MeshData import MeshData
|
from UM.Mesh.MeshData import MeshData
|
||||||
|
from UM.Math.Color import Color
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
import math
|
import math
|
||||||
|
@ -7,16 +8,22 @@ class LayerData(MeshData):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._layers = {}
|
self._layers = {}
|
||||||
|
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:
|
||||||
self._layers[layer] = []
|
self._layers[layer] = []
|
||||||
|
|
||||||
self._layers[layer].append(Polygon(self, type, data))
|
p = Polygon(self, type, data)
|
||||||
|
self._layers[layer].append(p)
|
||||||
|
self._element_counts.append(p.count)
|
||||||
|
|
||||||
def getLayers(self):
|
def getLayers(self):
|
||||||
return self._layers
|
return self._layers
|
||||||
|
|
||||||
|
def getElementCounts(self):
|
||||||
|
return self._element_counts
|
||||||
|
|
||||||
class Polygon():
|
class Polygon():
|
||||||
NoneType = 0
|
NoneType = 0
|
||||||
Inset0Type = 1
|
Inset0Type = 1
|
||||||
|
@ -30,11 +37,30 @@ class Polygon():
|
||||||
self._type = type
|
self._type = type
|
||||||
self._begin = mesh._vertex_count
|
self._begin = mesh._vertex_count
|
||||||
mesh.addVertices(data)
|
mesh.addVertices(data)
|
||||||
|
self._end = self._begin + len(data)
|
||||||
|
|
||||||
indices = [self._begin + i for i in range(len(data))]
|
color = None
|
||||||
|
if type == self.Inset0Type:
|
||||||
|
color = [1, 0, 0, 1]
|
||||||
|
elif type == self.InsetXType:
|
||||||
|
color = [0, 1, 0, 1]
|
||||||
|
elif type == self.SkinType:
|
||||||
|
color = [1, 1, 0, 1]
|
||||||
|
elif type == self.SupportType:
|
||||||
|
color = [0, 1, 1, 1]
|
||||||
|
elif type == self.SkirtType:
|
||||||
|
color = [0, 1, 1, 1]
|
||||||
|
else:
|
||||||
|
color = [1, 1, 1, 1]
|
||||||
|
|
||||||
|
colors = [color for i in range(len(data))]
|
||||||
|
mesh.addColors(numpy.array(colors, dtype=numpy.float32))
|
||||||
|
|
||||||
|
indices = []
|
||||||
|
for i in range(self._begin, self._end):
|
||||||
|
indices.append(i)
|
||||||
|
indices.append(i + 1)
|
||||||
mesh.addIndices(numpy.array(indices, dtype=numpy.int32))
|
mesh.addIndices(numpy.array(indices, dtype=numpy.int32))
|
||||||
self._end = mesh._vertex_count
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
|
@ -43,3 +69,7 @@ class Polygon():
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
return self._data
|
return self._data
|
||||||
|
|
||||||
|
@property
|
||||||
|
def count(self):
|
||||||
|
return self._end - self._begin
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue