mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 15:37:27 -06:00
Add a LayerData class and a Job class to create it from a Protobuf message
This commit is contained in:
parent
4b3e2a3f8c
commit
ecd8a8d2a3
2 changed files with 82 additions and 0 deletions
37
ProcessSlicedObjectListJob.py
Normal file
37
ProcessSlicedObjectListJob.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
from UM.Job import Job
|
||||
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
||||
from UM.Scene.SceneNode import SceneNode
|
||||
from UM.Application import Application
|
||||
from UM.Mesh.MeshData import MeshData
|
||||
|
||||
from . import LayerData
|
||||
|
||||
import numpy
|
||||
import struct
|
||||
|
||||
class ProcessSlicedObjectListJob(Job):
|
||||
def __init__(self, message):
|
||||
super().__init__(description = 'Processing sliced object', visible = True)
|
||||
self._message = message
|
||||
self._scene = Application.getInstance().getController().getScene()
|
||||
|
||||
def run(self):
|
||||
objectIdMap = {}
|
||||
for node in DepthFirstIterator(self._scene.getRoot()):
|
||||
if type(node) is SceneNode and node.getMeshData():
|
||||
objectIdMap[id(node)] = node
|
||||
|
||||
for object in self._message.objects:
|
||||
mesh = objectIdMap[object.id].getMeshData()
|
||||
|
||||
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 / 10, axis = 1)
|
||||
layerData.addPolygon(layer.id, polygon.type, points)
|
||||
|
||||
mesh.layerData = layerData
|
Loading…
Add table
Add a link
Reference in a new issue