mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-08 06:23:59 -06:00
Merge branch 'master' of https://github.com/Ultimaker/Cura
This commit is contained in:
commit
785d7cf6d1
7 changed files with 264 additions and 85 deletions
|
@ -61,6 +61,28 @@ message Polygon {
|
|||
float line_width = 3; // The width of the line being laid down
|
||||
}
|
||||
|
||||
message LayerOptimized {
|
||||
int32 id = 1;
|
||||
float height = 2; // Z position
|
||||
float thickness = 3; // height of a single layer
|
||||
|
||||
repeated PathSegment path_segment = 4; // layer data
|
||||
}
|
||||
|
||||
|
||||
message PathSegment {
|
||||
int32 extruder = 1; // The extruder used for this path segment
|
||||
enum PointType {
|
||||
Point2D = 0;
|
||||
Point3D = 1;
|
||||
}
|
||||
PointType point_type = 2;
|
||||
bytes points = 3; // The points defining the line segments, bytes of float[2/3] array of length N+1
|
||||
bytes line_type = 4; // Type of line segment as an unsigned char array of length 1 or N, where N is the number of line segments in this path
|
||||
bytes line_width = 5; // The widths of the line segments as bytes of a float array of length 1 or N
|
||||
}
|
||||
|
||||
|
||||
message GCodeLayer {
|
||||
bytes data = 2;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ class CuraEngineBackend(Backend):
|
|||
Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged)
|
||||
self._onActiveViewChanged()
|
||||
self._stored_layer_data = []
|
||||
self._stored_optimized_layer_data = []
|
||||
|
||||
#Triggers for when to (re)start slicing:
|
||||
self._global_container_stack = None
|
||||
|
@ -77,6 +78,7 @@ class CuraEngineBackend(Backend):
|
|||
|
||||
#Listeners for receiving messages from the back-end.
|
||||
self._message_handlers["cura.proto.Layer"] = self._onLayerMessage
|
||||
self._message_handlers["cura.proto.LayerOptimized"] = self._onOptimizedLayerMessage
|
||||
self._message_handlers["cura.proto.Progress"] = self._onProgressMessage
|
||||
self._message_handlers["cura.proto.GCodeLayer"] = self._onGCodeLayerMessage
|
||||
self._message_handlers["cura.proto.GCodePrefix"] = self._onGCodePrefixMessage
|
||||
|
@ -139,6 +141,7 @@ class CuraEngineBackend(Backend):
|
|||
self.printDurationMessage.emit(0, [0])
|
||||
|
||||
self._stored_layer_data = []
|
||||
self._stored_optimized_layer_data = []
|
||||
|
||||
if self._slicing: #We were already slicing. Stop the old job.
|
||||
self._terminate()
|
||||
|
@ -167,6 +170,7 @@ class CuraEngineBackend(Backend):
|
|||
self._slicing = False
|
||||
self._restart = True
|
||||
self._stored_layer_data = []
|
||||
self._stored_optimized_layer_data = []
|
||||
if self._start_slice_job is not None:
|
||||
self._start_slice_job.cancel()
|
||||
|
||||
|
@ -267,6 +271,12 @@ class CuraEngineBackend(Backend):
|
|||
def _onLayerMessage(self, message):
|
||||
self._stored_layer_data.append(message)
|
||||
|
||||
## Called when an optimized sliced layer data message is received from the engine.
|
||||
#
|
||||
# \param message The protobuf message containing sliced layer data.
|
||||
def _onOptimizedLayerMessage(self, message):
|
||||
self._stored_optimized_layer_data.append(message)
|
||||
|
||||
## Called when a progress message is received from the engine.
|
||||
#
|
||||
# \param message The protobuf message containing the slicing progress.
|
||||
|
@ -284,9 +294,9 @@ class CuraEngineBackend(Backend):
|
|||
self._slicing = False
|
||||
Logger.log("d", "Slicing took %s seconds", time() - self._slice_start_time )
|
||||
if self._layer_view_active and (self._process_layers_job is None or not self._process_layers_job.isRunning()):
|
||||
self._process_layers_job = ProcessSlicedLayersJob.ProcessSlicedLayersJob(self._stored_layer_data)
|
||||
self._process_layers_job = ProcessSlicedLayersJob.ProcessSlicedLayersJob(self._stored_optimized_layer_data)
|
||||
self._process_layers_job.start()
|
||||
self._stored_layer_data = []
|
||||
self._stored_optimized_layer_data = []
|
||||
|
||||
## Called when a g-code message is received from the engine.
|
||||
#
|
||||
|
@ -357,10 +367,10 @@ class CuraEngineBackend(Backend):
|
|||
self._layer_view_active = True
|
||||
# There is data and we're not slicing at the moment
|
||||
# if we are slicing, there is no need to re-calculate the data as it will be invalid in a moment.
|
||||
if self._stored_layer_data and not self._slicing:
|
||||
self._process_layers_job = ProcessSlicedLayersJob.ProcessSlicedLayersJob(self._stored_layer_data)
|
||||
if self._stored_optimized_layer_data and not self._slicing:
|
||||
self._process_layers_job = ProcessSlicedLayersJob.ProcessSlicedLayersJob(self._stored_optimized_layer_data)
|
||||
self._process_layers_job.start()
|
||||
self._stored_layer_data = []
|
||||
self._stored_optimized_layer_data = []
|
||||
else:
|
||||
self._layer_view_active = False
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ from UM.Math.Vector import Vector
|
|||
|
||||
from cura import LayerDataBuilder
|
||||
from cura import LayerDataDecorator
|
||||
from cura import LayerPolygon
|
||||
|
||||
import numpy
|
||||
from time import time
|
||||
|
@ -82,26 +83,46 @@ class ProcessSlicedLayersJob(Job):
|
|||
abs_layer_number = layer.id + abs(min_layer_number)
|
||||
|
||||
layer_data.addLayer(abs_layer_number)
|
||||
this_layer = layer_data.getLayer(abs_layer_number)
|
||||
layer_data.setLayerHeight(abs_layer_number, layer.height)
|
||||
layer_data.setLayerThickness(abs_layer_number, layer.thickness)
|
||||
|
||||
for p in range(layer.repeatedMessageCount("polygons")):
|
||||
polygon = layer.getRepeatedMessage("polygons", p)
|
||||
for p in range(layer.repeatedMessageCount("path_segment")):
|
||||
polygon = layer.getRepeatedMessage("path_segment", p)
|
||||
|
||||
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.
|
||||
extruder = polygon.extruder
|
||||
|
||||
line_types = numpy.fromstring(polygon.line_type, dtype="u1") # Convert bytearray to numpy array
|
||||
line_types = line_types.reshape((-1,1))
|
||||
|
||||
points = numpy.fromstring(polygon.points, dtype="f4") # Convert bytearray to numpy array
|
||||
if polygon.point_type == 0: # Point2D
|
||||
points = points.reshape((-1,2)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
|
||||
else: # Point3D
|
||||
points = points.reshape((-1,3))
|
||||
|
||||
line_widths = numpy.fromstring(polygon.line_width, dtype="f4") # Convert bytearray to numpy array
|
||||
line_widths = line_widths.reshape((-1,1)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
|
||||
|
||||
# Create a new 3D-array, copy the 2D points over and insert the right height.
|
||||
# This uses manual array creation + copy rather than numpy.insert since this is
|
||||
# faster.
|
||||
new_points = numpy.empty((len(points), 3), numpy.float32)
|
||||
new_points[:,0] = points[:,0]
|
||||
new_points[:,1] = layer.height
|
||||
new_points[:,2] = -points[:,1]
|
||||
if polygon.point_type == 0: # Point2D
|
||||
new_points[:,0] = points[:,0]
|
||||
new_points[:,1] = layer.height/1000 # layer height value is in backend representation
|
||||
new_points[:,2] = -points[:,1]
|
||||
else: # Point3D
|
||||
new_points[:,0] = points[:,0]
|
||||
new_points[:,1] = points[:,2]
|
||||
new_points[:,2] = -points[:,1]
|
||||
|
||||
|
||||
new_points /= 1000
|
||||
this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths)
|
||||
this_poly.buildCache()
|
||||
|
||||
this_layer.polygons.append(this_poly)
|
||||
|
||||
layer_data.addPolygon(abs_layer_number, polygon.type, new_points, polygon.line_width)
|
||||
Job.yieldThread()
|
||||
Job.yieldThread()
|
||||
current_layer += 1
|
||||
|
|
|
@ -25,6 +25,8 @@ from . import LayerViewProxy
|
|||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
import numpy
|
||||
|
||||
## View used to display g-code paths.
|
||||
class LayerView(View):
|
||||
def __init__(self):
|
||||
|
@ -42,7 +44,7 @@ class LayerView(View):
|
|||
self._top_layers_job = None
|
||||
self._activity = False
|
||||
|
||||
Preferences.getInstance().addPreference("view/top_layer_count", 1)
|
||||
Preferences.getInstance().addPreference("view/top_layer_count", 5)
|
||||
Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged)
|
||||
|
||||
self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count"))
|
||||
|
@ -253,11 +255,13 @@ class _CreateTopLayersJob(Job):
|
|||
if not layer or layer.getVertices() is None:
|
||||
continue
|
||||
|
||||
layer_mesh.addIndices(layer_mesh._vertex_count+layer.getIndices())
|
||||
layer_mesh.addVertices(layer.getVertices())
|
||||
|
||||
# Scale layer color by a brightness factor based on the current layer number
|
||||
# This will result in a range of 0.5 - 1.0 to multiply colors by.
|
||||
brightness = (2.0 - (i / self._solid_layers)) / 2.0
|
||||
brightness = numpy.ones((1,4), dtype=numpy.float32) * (2.0 - (i / self._solid_layers)) / 2.0
|
||||
brightness[0, 3] = 1.0;
|
||||
layer_mesh.addColors(layer.getColors() * brightness)
|
||||
|
||||
if self._cancel:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue