本文整理汇总了Python中UM.Scene.SceneNode.SceneNode.setParent方法的典型用法代码示例。如果您正苦于以下问题:Python SceneNode.setParent方法的具体用法?Python SceneNode.setParent怎么用?Python SceneNode.setParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.Scene.SceneNode.SceneNode
的用法示例。
在下文中一共展示了SceneNode.setParent方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
def read(self, file_name):
extension = os.path.splitext(file_name)[1]
if extension.lower() == self._supported_extension:
layer_data = LayerData()
with open (file_name,"rt") as f:
layer = ""
current_path_type = ""
current_layer_nr = 0
poly_list = []
old_position = [0,0,0]
current_z = 0
for line in f:
if line.startswith(';TYPE:'):
current_path_type = line[6:].strip()
#layer_data.addPolygon(current_layer_nr,3 ,None ,5 )
elif line.startswith(';LAYER:'):
current_layer_nr = int(line[7:].strip())
layer_data.addLayer(int(line[7:].strip()))
elif line.startswith(';'):
pass # Ignore comments
else:
command_type = self.getCodeInt(line, 'G')
if command_type == 0 or command_type == 1: #Move command
x = self.getCodeFloat(line, 'X')
y = self.getCodeFloat(line, 'Y')
z = self.getCodeFloat(line, 'Z')
if z:
current_z = z
if x and y:
polygon_data = numpy.zeros((4,3)) #Square :)
polygon_data[0,:] = old_position
polygon_data[1,:] = old_position
polygon_data[2,:] = [x,current_z,y]
polygon_data[3,:] = [x,current_z,y]
old_position = [x,current_z,y]
if current_path_type == "SKIRT":
layer_data.addPolygon(current_layer_nr,5 ,polygon_data ,5 )
elif current_path_type == "WALL-INNER":
layer_data.addPolygon(current_layer_nr,3 ,polygon_data ,5 )
elif current_path_type == "WALL-OUTER":
layer_data.addPolygon(current_layer_nr,1 ,polygon_data ,5 )
else:
layer_data.addPolygon(current_layer_nr,2 ,polygon_data ,5 )
#e = self.getCodeFloat(line, 'E')
#print(x , " ", y , " ", z, " " , e)
pass
layer_data.build()
decorator = LayerDataDecorator()
decorator.setLayerData(layer_data)
new_node = SceneNode()
new_node.setMeshData(MeshData())
new_node.addDecorator(decorator)
new_node.setParent(self._scene.getRoot())
示例2: groupSelected
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
def groupSelected(self):
group_node = SceneNode()
group_decorator = GroupDecorator()
group_node.addDecorator(group_decorator)
group_node.setParent(self.getController().getScene().getRoot())
for node in Selection.getAllSelectedObjects():
node.setParent(group_node)
for node in group_node.getChildren():
Selection.remove(node)
Selection.add(group_node)
示例3: run
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
def run(self):
objectIdMap = {}
new_node = SceneNode()
## Put all nodes in a dict identified by ID
for node in DepthFirstIterator(self._scene.getRoot()):
if type(node) is SceneNode and node.getMeshData():
if hasattr(node.getMeshData(), "layerData"):
self._scene.getRoot().removeChild(node)
else:
objectIdMap[id(node)] = node
settings = Application.getInstance().getActiveMachine()
layerHeight = settings.getSettingValueByKey("layer_height")
for object in self._message.objects:
try:
node = objectIdMap[object.id]
except KeyError:
continue
mesh = MeshData()
layerData = LayerData.LayerData()
for layer in object.layers:
for polygon in layer.polygons:
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 = numpy.asarray(points, dtype=numpy.float32)
points /= 1000
points = numpy.insert(points, 1, layer.id * layerHeight, axis = 1)
points[:,2] *= -1
if not settings.getSettingValueByKey("machine_center_is_zero"):
center = [settings.getSettingValueByKey("machine_width") / 2, 0.0, -settings.getSettingValueByKey("machine_depth") / 2]
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)
# 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
new_node.setMeshData(mesh)
new_node.setParent(self._scene.getRoot())
示例4: groupSelected
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
def groupSelected(self):
group_node = SceneNode()
group_decorator = GroupDecorator()
group_node.addDecorator(group_decorator)
group_node.setParent(self.getController().getScene().getRoot())
for node in Selection.getAllSelectedObjects():
node.setParent(group_node)
group_node.setCenterPosition(group_node.getBoundingBox().center)
#group_node.translate(Vector(0,group_node.getBoundingBox().center.y,0))
group_node.translate(group_node.getBoundingBox().center)
for node in group_node.getChildren():
Selection.remove(node)
Selection.add(group_node)
示例5: groupSelected
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
def groupSelected(self):
# Create a group-node
group_node = SceneNode()
group_decorator = GroupDecorator()
group_node.addDecorator(group_decorator)
group_node.setParent(self.getController().getScene().getRoot())
group_node.setSelectable(True)
center = Selection.getSelectionCenter()
group_node.setPosition(center)
group_node.setCenterPosition(center)
# Move selected nodes into the group-node
Selection.applyOperation(SetParentOperation, group_node)
# Deselect individual nodes and select the group-node instead
for node in group_node.getChildren():
Selection.remove(node)
Selection.add(group_node)
示例6: groupSelected
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
def groupSelected(self):
group_node = SceneNode()
group_decorator = GroupDecorator()
group_node.addDecorator(group_decorator)
group_node.setParent(self.getController().getScene().getRoot())
center = Selection.getSelectionCenter()
group_node.setPosition(center)
group_node.setCenterPosition(center)
for node in Selection.getAllSelectedObjects():
world = node.getWorldPosition()
node.setParent(group_node)
node.setPosition(world - center)
for node in group_node.getChildren():
Selection.remove(node)
Selection.add(group_node)
示例7: run
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
def run(self):
if Application.getInstance().getController().getActiveView().getPluginId() == "LayerView":
self._progress = Message(catalog.i18nc("Layers View mode", "Layers"), 0, False, 0)
self._progress.show()
Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged)
objectIdMap = {}
new_node = SceneNode()
## Put all nodes in a dict identified by ID
for node in DepthFirstIterator(self._scene.getRoot()):
if type(node) is SceneNode and node.getMeshData():
if node.callDecoration("getLayerData"):
#if hasattr(node.getMeshData(), "layerData"):
self._scene.getRoot().removeChild(node)
else:
objectIdMap[id(node)] = node
settings = Application.getInstance().getActiveMachine()
layerHeight = settings.getSettingValueByKey("layer_height")
center = None
if not settings.getSettingValueByKey("machine_center_is_zero"):
center = numpy.array([settings.getSettingValueByKey("machine_width") / 2, 0.0, -settings.getSettingValueByKey("machine_depth") / 2])
else:
center = numpy.array([0.0, 0.0, 0.0])
if self._progress:
self._progress.setProgress(2)
mesh = MeshData()
layer_data = LayerData.LayerData()
for object in self._message.objects:
try:
node = objectIdMap[object.id]
except KeyError:
continue
for layer in object.layers:
layer_data.addLayer(layer.id)
layer_data.setLayerHeight(layer.id, layer.height)
layer_data.setLayerThickness(layer.id, layer.thickness)
for polygon in layer.polygons:
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 = numpy.asarray(points, dtype=numpy.float32)
points /= 1000
points = numpy.insert(points, 1, (layer.height / 1000), axis = 1)
points[:,2] *= -1
points -= numpy.array(center)
layer_data.addPolygon(layer.id, polygon.type, points, polygon.line_width)
if self._progress:
self._progress.setProgress(50)
# We are done processing all the layers we got from the engine, now create a mesh out of the data
layer_data.build()
if self._progress:
self._progress.setProgress(100)
#Add layerdata decorator to scene node to indicate that the node has layerdata
decorator = LayerDataDecorator.LayerDataDecorator()
decorator.setLayerData(layer_data)
new_node.addDecorator(decorator)
new_node.setMeshData(mesh)
new_node.setParent(self._scene.getRoot())
view = Application.getInstance().getController().getActiveView()
if view.getPluginId() == "LayerView":
view.resetLayerData()
if self._progress:
self._progress.hide()
示例8: run
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
def run(self):
if Application.getInstance().getController().getActiveView().getPluginId() == "LayerView":
self._progress = Message(catalog.i18nc("@info:status", "Processing Layers"), 0, False, -1)
self._progress.show()
Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged)
object_id_map = {}
new_node = SceneNode()
## Put all nodes in a dict identified by ID
for node in DepthFirstIterator(self._scene.getRoot()):
if type(node) is SceneNode and node.getMeshData():
if node.callDecoration("getLayerData"):
self._scene.getRoot().removeChild(node)
else:
object_id_map[id(node)] = node
Job.yieldThread()
settings = Application.getInstance().getMachineManager().getActiveProfile()
center = None
if not settings.getSettingValue("machine_center_is_zero"):
center = numpy.array([settings.getSettingValue("machine_width") / 2, 0.0, -settings.getSettingValue("machine_depth") / 2])
else:
center = numpy.array([0.0, 0.0, 0.0])
mesh = MeshData()
layer_data = LayerData.LayerData()
layer_count = 0
for object in self._message.objects:
layer_count += len(object.layers)
current_layer = 0
for object in self._message.objects:
try:
node = object_id_map[object.id]
except KeyError:
continue
for layer in object.layers:
layer_data.addLayer(layer.id)
layer_data.setLayerHeight(layer.id, layer.height)
layer_data.setLayerThickness(layer.id, layer.thickness)
for polygon in layer.polygons:
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 = numpy.asarray(points, dtype=numpy.float32)
points /= 1000
points = numpy.insert(points, 1, (layer.height / 1000), axis = 1)
points[:,2] *= -1
points -= center
layer_data.addPolygon(layer.id, polygon.type, points, polygon.line_width)
Job.yieldThread()
current_layer += 1
progress = (current_layer / layer_count) * 100
# TODO: Rebuild the layer data mesh once the layer has been processed.
# This needs some work in LayerData so we can add the new layers instead of recreating the entire mesh.
if self._progress:
self._progress.setProgress(progress)
# We are done processing all the layers we got from the engine, now create a mesh out of the data
layer_data.build()
#Add layerdata decorator to scene node to indicate that the node has layerdata
decorator = LayerDataDecorator.LayerDataDecorator()
decorator.setLayerData(layer_data)
new_node.addDecorator(decorator)
new_node.setMeshData(mesh)
new_node.setParent(self._scene.getRoot())
if self._progress:
self._progress.setProgress(100)
view = Application.getInstance().getController().getActiveView()
if view.getPluginId() == "LayerView":
view.resetLayerData()
if self._progress:
self._progress.hide()
示例9: run
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
def run(self):
if Application.getInstance().getController().getActiveView().getPluginId() == "LayerView":
self._progress = Message(catalog.i18nc("@info:status", "Processing Layers"), 0, False, -1)
self._progress.show()
Job.yieldThread()
if self._abort_requested:
if self._progress:
self._progress.hide()
return
Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged)
object_id_map = {}
new_node = SceneNode()
## Put all nodes in a dictionary identified by ID
for node in DepthFirstIterator(self._scene.getRoot()):
if type(node) is SceneNode and node.getMeshData():
if node.callDecoration("getLayerData"):
self._scene.getRoot().removeChild(node)
else:
object_id_map[id(node)] = node
Job.yieldThread()
if self._abort_requested:
if self._progress:
self._progress.hide()
return
settings = Application.getInstance().getMachineManager().getWorkingProfile()
mesh = MeshData()
layer_data = LayerData.LayerData()
layer_count = 0
for i in range(self._message.repeatedMessageCount("objects")):
layer_count += self._message.getRepeatedMessage("objects", i).repeatedMessageCount("layers")
current_layer = 0
for object_position in range(self._message.repeatedMessageCount("objects")):
current_object = self._message.getRepeatedMessage("objects", object_position)
try:
node = object_id_map[current_object.id]
except KeyError:
continue
for l in range(current_object.repeatedMessageCount("layers")):
layer = current_object.getRepeatedMessage("layers", l)
layer_data.addLayer(layer.id)
layer_data.setLayerHeight(layer.id, layer.height)
layer_data.setLayerThickness(layer.id, layer.thickness)
for p in range(layer.repeatedMessageCount("polygons")):
polygon = layer.getRepeatedMessage("polygons", 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.
# 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]
new_points /= 1000
layer_data.addPolygon(layer.id, polygon.type, new_points, polygon.line_width)
Job.yieldThread()
Job.yieldThread()
current_layer += 1
progress = (current_layer / layer_count) * 100
# TODO: Rebuild the layer data mesh once the layer has been processed.
# This needs some work in LayerData so we can add the new layers instead of recreating the entire mesh.
if self._abort_requested:
if self._progress:
self._progress.hide()
return
if self._progress:
self._progress.setProgress(progress)
# We are done processing all the layers we got from the engine, now create a mesh out of the data
layer_data.build()
if self._abort_requested:
if self._progress:
self._progress.hide()
return
#Add layerdata decorator to scene node to indicate that the node has layerdata
decorator = LayerDataDecorator.LayerDataDecorator()
decorator.setLayerData(layer_data)
new_node.addDecorator(decorator)
new_node.setMeshData(mesh)
new_node.setParent(self._scene.getRoot()) #Note: After this we can no longer abort!
if not settings.getSettingValue("machine_center_is_zero"):
new_node.setPosition(Vector(-settings.getSettingValue("machine_width") / 2, 0.0, settings.getSettingValue("machine_depth") / 2))
#.........这里部分代码省略.........
示例10: run
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
def run(self):
if Application.getInstance().getController().getActiveView().getPluginId() == "LayerView":
self._progress = Message(catalog.i18nc("@info:status", "Processing Layers"), 0, False, -1)
self._progress.show()
Job.yieldThread()
if self._abort_requested:
if self._progress:
self._progress.hide()
return
Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged)
new_node = SceneNode()
## Remove old layer data (if any)
for node in DepthFirstIterator(self._scene.getRoot()):
if type(node) is SceneNode and node.getMeshData():
if node.callDecoration("getLayerData"):
self._scene.getRoot().removeChild(node)
Job.yieldThread()
if self._abort_requested:
if self._progress:
self._progress.hide()
return
settings = Application.getInstance().getMachineManager().getWorkingProfile()
mesh = MeshData()
layer_data = LayerData.LayerData()
layer_count = len(self._layers)
# Find the minimum layer number
# When using a raft, the raft layers are sent as layers < 0. Instead of allowing layers < 0, we
# instead simply offset all other layers so the lowest layer is always 0.
min_layer_number = 0
for layer in self._layers:
if(layer.id < min_layer_number):
min_layer_number = layer.id
current_layer = 0
for layer in self._layers:
abs_layer_number = layer.id + abs(min_layer_number)
layer_data.addLayer(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)
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.
# 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]
new_points /= 1000
layer_data.addPolygon(abs_layer_number, polygon.type, new_points, polygon.line_width)
Job.yieldThread()
Job.yieldThread()
current_layer += 1
progress = (current_layer / layer_count) * 100
# TODO: Rebuild the layer data mesh once the layer has been processed.
# This needs some work in LayerData so we can add the new layers instead of recreating the entire mesh.
if self._abort_requested:
if self._progress:
self._progress.hide()
return
if self._progress:
self._progress.setProgress(progress)
# We are done processing all the layers we got from the engine, now create a mesh out of the data
layer_data.build()
if self._abort_requested:
if self._progress:
self._progress.hide()
return
# Add LayerDataDecorator to scene node to indicate that the node has layer data
decorator = LayerDataDecorator.LayerDataDecorator()
decorator.setLayerData(layer_data)
new_node.addDecorator(decorator)
new_node.setMeshData(mesh)
new_node.setParent(self._scene.getRoot()) # Note: After this we can no longer abort!
if not settings.getSettingValue("machine_center_is_zero"):
new_node.setPosition(Vector(-settings.getSettingValue("machine_width") / 2, 0.0, settings.getSettingValue("machine_depth") / 2))
if self._progress:
self._progress.setProgress(100)
#.........这里部分代码省略.........
示例11: run
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
#.........这里部分代码省略.........
line_thicknesses = numpy.fromstring(polygon.line_thickness, dtype="f4") # Convert bytearray to numpy array
line_thicknesses = line_thicknesses.reshape((-1,1)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
line_feedrates = numpy.fromstring(polygon.line_feedrate, dtype="f4") # Convert bytearray to numpy array
line_feedrates = line_feedrates.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)
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]
this_poly = LayerPolygon.LayerPolygon(extruder, line_types, new_points, line_widths, line_thicknesses, line_feedrates)
this_poly.buildCache()
this_layer.polygons.append(this_poly)
Job.yieldThread()
Job.yieldThread()
current_layer += 1
progress = (current_layer / layer_count) * 99
# TODO: Rebuild the layer data mesh once the layer has been processed.
# This needs some work in LayerData so we can add the new layers instead of recreating the entire mesh.
if self._abort_requested:
if self._progress_message:
self._progress_message.hide()
return
if self._progress_message:
self._progress_message.setProgress(progress)
# We are done processing all the layers we got from the engine, now create a mesh out of the data
# Find out colors per extruder
global_container_stack = Application.getInstance().getGlobalContainerStack()
manager = ExtruderManager.getInstance()
extruders = list(manager.getMachineExtruders(global_container_stack.getId()))
if extruders:
material_color_map = numpy.zeros((len(extruders), 4), dtype=numpy.float32)
for extruder in extruders:
position = int(extruder.getMetaDataEntry("position", default="0")) # Get the position
try:
default_color = ExtrudersModel.defaultColors[position]
except IndexError:
default_color = "#e0e000"
color_code = extruder.material.getMetaDataEntry("color_code", default=default_color)
color = colorCodeToRGBA(color_code)
material_color_map[position, :] = color
else:
# Single extruder via global stack.
material_color_map = numpy.zeros((1, 4), dtype=numpy.float32)
color_code = global_container_stack.material.getMetaDataEntry("color_code", default="#e0e000")
color = colorCodeToRGBA(color_code)
material_color_map[0, :] = color
# We have to scale the colors for compatibility mode
if OpenGLContext.isLegacyOpenGL() or bool(Preferences.getInstance().getValue("view/force_layer_view_compatibility_mode")):
line_type_brightness = 0.5 # for compatibility mode
else:
line_type_brightness = 1.0
layer_mesh = layer_data.build(material_color_map, line_type_brightness)
if self._abort_requested:
if self._progress_message:
self._progress_message.hide()
return
# Add LayerDataDecorator to scene node to indicate that the node has layer data
decorator = LayerDataDecorator.LayerDataDecorator()
decorator.setLayerData(layer_mesh)
new_node.addDecorator(decorator)
new_node.setMeshData(mesh)
# Set build volume as parent, the build volume can move as a result of raft settings.
# It makes sense to set the build volume as parent: the print is actually printed on it.
new_node_parent = Application.getInstance().getBuildVolume()
new_node.setParent(new_node_parent) # Note: After this we can no longer abort!
settings = Application.getInstance().getGlobalContainerStack()
if not settings.getProperty("machine_center_is_zero", "value"):
new_node.setPosition(Vector(-settings.getProperty("machine_width", "value") / 2, 0.0, settings.getProperty("machine_depth", "value") / 2))
if self._progress_message:
self._progress_message.setProgress(100)
if self._progress_message:
self._progress_message.hide()
# Clear the unparsed layers. This saves us a bunch of memory if the Job does not get destroyed.
self._layers = None
Logger.log("d", "Processing layers took %s seconds", time() - start_time)
示例12: run
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import setParent [as 别名]
#.........这里部分代码省略.........
if(layer.id < min_layer_number):
min_layer_number = layer.id
current_layer = 0
for layer in self._layers:
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("path_segment")):
polygon = layer.getRepeatedMessage("path_segment", p)
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)
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]
this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths)
this_poly.buildCache()
this_layer.polygons.append(this_poly)
Job.yieldThread()
Job.yieldThread()
current_layer += 1
progress = (current_layer / layer_count) * 99
# TODO: Rebuild the layer data mesh once the layer has been processed.
# This needs some work in LayerData so we can add the new layers instead of recreating the entire mesh.
if self._abort_requested:
if self._progress:
self._progress.hide()
return
if self._progress:
self._progress.setProgress(progress)
# We are done processing all the layers we got from the engine, now create a mesh out of the data
layer_mesh = layer_data.build()
if self._abort_requested:
if self._progress:
self._progress.hide()
return
# Add LayerDataDecorator to scene node to indicate that the node has layer data
decorator = LayerDataDecorator.LayerDataDecorator()
decorator.setLayerData(layer_mesh)
new_node.addDecorator(decorator)
new_node.setMeshData(mesh)
# Set build volume as parent, the build volume can move as a result of raft settings.
# It makes sense to set the build volume as parent: the print is actually printed on it.
new_node_parent = Application.getInstance().getBuildVolume()
new_node.setParent(new_node_parent) # Note: After this we can no longer abort!
settings = Application.getInstance().getGlobalContainerStack()
if not settings.getProperty("machine_center_is_zero", "value"):
new_node.setPosition(Vector(-settings.getProperty("machine_width", "value") / 2, 0.0, settings.getProperty("machine_depth", "value") / 2))
if self._progress:
self._progress.setProgress(100)
view = Application.getInstance().getController().getActiveView()
if view.getPluginId() == "LayerView":
view.resetLayerData()
if self._progress:
self._progress.hide()
# Clear the unparsed layers. This saves us a bunch of memory if the Job does not get destroyed.
self._layers = None
Logger.log("d", "Processing layers took %s seconds", time() - start_time)