mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Use the new layer message properties to properly create layers
Now we use the height as provided by the engine to render the layer at. Contributes to #52
This commit is contained in:
parent
9849283144
commit
ad88506325
2 changed files with 74 additions and 21 deletions
|
@ -2,7 +2,9 @@
|
||||||
# Cura is released under the terms of the AGPLv3 or higher.
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
from UM.Mesh.MeshData import MeshData
|
from UM.Mesh.MeshData import MeshData
|
||||||
|
from UM.Mesh.MeshBuilder import MeshBuilder
|
||||||
from UM.Math.Color import Color
|
from UM.Math.Color import Color
|
||||||
|
from UM.Math.Vector import Vector
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
import math
|
import math
|
||||||
|
@ -13,12 +15,19 @@ class LayerData(MeshData):
|
||||||
self._layers = {}
|
self._layers = {}
|
||||||
self._element_counts = {}
|
self._element_counts = {}
|
||||||
|
|
||||||
def addPolygon(self, layer, type, data):
|
def addLayer(self, layer):
|
||||||
if layer not in self._layers:
|
if layer not in self._layers:
|
||||||
self._layers[layer] = []
|
self._layers[layer] = Layer(layer)
|
||||||
|
|
||||||
p = Polygon(self, type, data)
|
def addPolygon(self, layer, type, data, line_width):
|
||||||
self._layers[layer].append(p)
|
if layer not in self._layers:
|
||||||
|
self.addLayer(layer)
|
||||||
|
|
||||||
|
p = Polygon(self, type, data, line_width)
|
||||||
|
self._layers[layer].polygons.append(p)
|
||||||
|
|
||||||
|
def getLayer(self, layer):
|
||||||
|
return self._layers[layer]
|
||||||
|
|
||||||
def getLayers(self):
|
def getLayers(self):
|
||||||
return self._layers
|
return self._layers
|
||||||
|
@ -26,14 +35,61 @@ class LayerData(MeshData):
|
||||||
def getElementCounts(self):
|
def getElementCounts(self):
|
||||||
return self._element_counts
|
return self._element_counts
|
||||||
|
|
||||||
|
def setLayerHeight(self, layer, height):
|
||||||
|
if layer not in self._layers:
|
||||||
|
self.addLayer(layer)
|
||||||
|
|
||||||
|
self._layers[layer].setHeight(height)
|
||||||
|
|
||||||
|
def setLayerThickness(self, layer, thickness):
|
||||||
|
if layer not in self._layers:
|
||||||
|
self.addLayer(layer)
|
||||||
|
|
||||||
|
self._layers[layer].setThickness(thickness)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
for layer, data in self._layers.items():
|
for layer, data in self._layers.items():
|
||||||
if layer not in self._element_counts:
|
data.build()
|
||||||
self._element_counts[layer] = []
|
|
||||||
|
self._element_counts[layer] = data.elementCount
|
||||||
|
|
||||||
|
class Layer():
|
||||||
|
def __init__(self, id):
|
||||||
|
self._id = id
|
||||||
|
self._height = 0.0
|
||||||
|
self._thickness = 0.0
|
||||||
|
self._polygons = []
|
||||||
|
self._element_count = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def height(self):
|
||||||
|
return self._height
|
||||||
|
|
||||||
|
@property
|
||||||
|
def thickness(self):
|
||||||
|
return self._thickness
|
||||||
|
|
||||||
|
@property
|
||||||
|
def polygons(self):
|
||||||
|
return self._polygons
|
||||||
|
|
||||||
|
@property
|
||||||
|
def elementCount(self):
|
||||||
|
return self._element_count
|
||||||
|
|
||||||
|
def setHeight(self, height):
|
||||||
|
self._height = height
|
||||||
|
|
||||||
|
def setThickness(self, thickness):
|
||||||
|
self._thickness = thickness
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
for polygon in self._polygons:
|
||||||
|
if polygon._type == Polygon.InfillType or polygon._type == Polygon.SupportInfillType:
|
||||||
|
continue
|
||||||
|
|
||||||
for polygon in data:
|
|
||||||
polygon.build()
|
polygon.build()
|
||||||
self._element_counts[layer].append(polygon.elementCount)
|
self._element_count += polygon.elementCount
|
||||||
|
|
||||||
class Polygon():
|
class Polygon():
|
||||||
NoneType = 0
|
NoneType = 0
|
||||||
|
|
|
@ -32,22 +32,24 @@ class ProcessSlicedObjectListJob(Job):
|
||||||
settings = Application.getInstance().getActiveMachine()
|
settings = Application.getInstance().getActiveMachine()
|
||||||
layerHeight = settings.getSettingValueByKey("layer_height")
|
layerHeight = settings.getSettingValueByKey("layer_height")
|
||||||
|
|
||||||
|
mesh = MeshData()
|
||||||
for object in self._message.objects:
|
for object in self._message.objects:
|
||||||
try:
|
try:
|
||||||
node = objectIdMap[object.id]
|
node = objectIdMap[object.id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
mesh = MeshData()
|
|
||||||
|
|
||||||
layerData = LayerData.LayerData()
|
layerData = LayerData.LayerData()
|
||||||
for layer in object.layers:
|
for layer in object.layers:
|
||||||
|
layerData.addLayer(layer.id)
|
||||||
|
layerData.setLayerHeight(layer.id, layer.height)
|
||||||
|
layerData.setLayerThickness(layer.id, layer.thickness)
|
||||||
for polygon in layer.polygons:
|
for polygon in layer.polygons:
|
||||||
points = numpy.fromstring(polygon.points, dtype="i8") # Convert bytearray to numpy array
|
points = numpy.fromstring(polygon.points, dtype="i8") # Convert bytearray to numpy array
|
||||||
points = points.reshape((-1,2)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
|
points = points.reshape((-1,2)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
|
||||||
points = numpy.asarray(points, dtype=numpy.float32)
|
points = numpy.asarray(points, dtype=numpy.float32)
|
||||||
points /= 1000
|
points /= 1000
|
||||||
points = numpy.insert(points, 1, layer.id * layerHeight, axis = 1)
|
points = numpy.insert(points, 1, (layer.height / 1000), axis = 1)
|
||||||
|
|
||||||
points[:,2] *= -1
|
points[:,2] *= -1
|
||||||
|
|
||||||
|
@ -55,13 +57,8 @@ class ProcessSlicedObjectListJob(Job):
|
||||||
center = [settings.getSettingValueByKey("machine_width") / 2, 0.0, -settings.getSettingValueByKey("machine_depth") / 2]
|
center = [settings.getSettingValueByKey("machine_width") / 2, 0.0, -settings.getSettingValueByKey("machine_depth") / 2]
|
||||||
points -= numpy.array(center)
|
points -= numpy.array(center)
|
||||||
|
|
||||||
#points = numpy.pad(points, ((0,0), (0,1)), "constant", constant_values=(0.0, 1.0))
|
|
||||||
#inverse = node.getWorldTransformation().getInverse().getData()
|
|
||||||
#points = points.dot(inverse)
|
|
||||||
#points = points[:,0:3]
|
|
||||||
|
|
||||||
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
|
# We are done processing all the layers we got from the engine, now create a mesh out of the data
|
||||||
layerData.build()
|
layerData.build()
|
||||||
mesh.layerData = layerData
|
mesh.layerData = layerData
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue