mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 07:03:56 -06:00
Fixed up the 3MF reader to use the changed MeshBuilder and MeshData.
CURA-1633 OverflowError: cannot convert float infinity to integer (loading larger models)
This commit is contained in:
parent
1543e4a6e0
commit
47de254f97
2 changed files with 42 additions and 44 deletions
|
@ -144,6 +144,8 @@ class ConvexHullDecorator(SceneNodeDecorator):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
rounded_hull = None
|
rounded_hull = None
|
||||||
|
mesh = None
|
||||||
|
world_transform = None
|
||||||
if self._node.getMeshData():
|
if self._node.getMeshData():
|
||||||
mesh = self._node.getMeshData()
|
mesh = self._node.getMeshData()
|
||||||
world_transform = self._node.getWorldTransformation()
|
world_transform = self._node.getWorldTransformation()
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# 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.MeshReader import MeshReader
|
from UM.Mesh.MeshReader import MeshReader
|
||||||
from UM.Mesh.MeshData import MeshData
|
from UM.Mesh.MeshBuilder import MeshBuilder
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Math.Matrix import Matrix
|
from UM.Math.Matrix import Matrix
|
||||||
from UM.Math.Vector import Vector
|
from UM.Math.Vector import Vector
|
||||||
|
@ -42,7 +42,7 @@ class ThreeMFReader(MeshReader):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for entry in objects:
|
for entry in objects:
|
||||||
mesh = MeshData()
|
mesh_builder = MeshBuilder()
|
||||||
node = SceneNode()
|
node = SceneNode()
|
||||||
vertex_list = []
|
vertex_list = []
|
||||||
#for vertex in entry.mesh.vertices.vertex:
|
#for vertex in entry.mesh.vertices.vertex:
|
||||||
|
@ -51,71 +51,67 @@ class ThreeMFReader(MeshReader):
|
||||||
Job.yieldThread()
|
Job.yieldThread()
|
||||||
|
|
||||||
triangles = entry.findall(".//3mf:triangle", self._namespaces)
|
triangles = entry.findall(".//3mf:triangle", self._namespaces)
|
||||||
|
mesh_builder.reserveFaceCount(len(triangles))
|
||||||
mesh.reserveFaceCount(len(triangles))
|
|
||||||
|
|
||||||
#for triangle in object.mesh.triangles.triangle:
|
#for triangle in object.mesh.triangles.triangle:
|
||||||
for triangle in triangles:
|
for triangle in triangles:
|
||||||
v1 = int(triangle.get("v1"))
|
v1 = int(triangle.get("v1"))
|
||||||
v2 = int(triangle.get("v2"))
|
v2 = int(triangle.get("v2"))
|
||||||
v3 = int(triangle.get("v3"))
|
v3 = int(triangle.get("v3"))
|
||||||
mesh.addFace(vertex_list[v1][0],vertex_list[v1][1],vertex_list[v1][2],vertex_list[v2][0],vertex_list[v2][1],vertex_list[v2][2],vertex_list[v3][0],vertex_list[v3][1],vertex_list[v3][2])
|
|
||||||
|
mesh_builder.addFaceByPoints(vertex_list[v1][0], vertex_list[v1][1], vertex_list[v1][2],
|
||||||
|
vertex_list[v2][0], vertex_list[v2][1], vertex_list[v2][2],
|
||||||
|
vertex_list[v3][0], vertex_list[v3][1], vertex_list[v3][2])
|
||||||
|
|
||||||
Job.yieldThread()
|
Job.yieldThread()
|
||||||
|
|
||||||
# Rotate the model; We use a different coordinate frame.
|
# Rotate the model; We use a different coordinate frame.
|
||||||
rotation = Matrix()
|
rotation = Matrix()
|
||||||
rotation.setByRotationAxis(-0.5 * math.pi, Vector(1,0,0))
|
rotation.setByRotationAxis(-0.5 * math.pi, Vector(1,0,0))
|
||||||
mesh = mesh.getTransformed(rotation)
|
|
||||||
|
|
||||||
#TODO: We currently do not check for normals and simply recalculate them.
|
#TODO: We currently do not check for normals and simply recalculate them.
|
||||||
mesh.calculateNormals()
|
mesh_builder.calculateNormals()
|
||||||
node.setMeshData(mesh)
|
|
||||||
|
node.setMeshData(mesh_builder.build().getTransformed(rotation))
|
||||||
node.setSelectable(True)
|
node.setSelectable(True)
|
||||||
|
|
||||||
transformation = root.findall("./3mf:build/3mf:item[@objectid='{0}']".format(entry.get("id")), self._namespaces)
|
transformations = root.findall("./3mf:build/3mf:item[@objectid='{0}']".format(entry.get("id")), self._namespaces)
|
||||||
if transformation:
|
transformation = transformations[0] if transformations else None
|
||||||
transformation = transformation[0]
|
if transformation is not None and transformation.get("transform"):
|
||||||
try:
|
splitted_transformation = transformation.get("transform").split()
|
||||||
if transformation.get("transform"):
|
## Transformation is saved as:
|
||||||
splitted_transformation = transformation.get("transform").split()
|
## M00 M01 M02 0.0
|
||||||
## Transformation is saved as:
|
## M10 M11 M12 0.0
|
||||||
## M00 M01 M02 0.0
|
## M20 M21 M22 0.0
|
||||||
## M10 M11 M12 0.0
|
## M30 M31 M32 1.0
|
||||||
## M20 M21 M22 0.0
|
## We switch the row & cols as that is how everyone else uses matrices!
|
||||||
## M30 M31 M32 1.0
|
temp_mat = Matrix()
|
||||||
## We switch the row & cols as that is how everyone else uses matrices!
|
# Rotation & Scale
|
||||||
temp_mat = Matrix()
|
temp_mat._data[0,0] = splitted_transformation[0]
|
||||||
# Rotation & Scale
|
temp_mat._data[1,0] = splitted_transformation[1]
|
||||||
temp_mat._data[0,0] = splitted_transformation[0]
|
temp_mat._data[2,0] = splitted_transformation[2]
|
||||||
temp_mat._data[1,0] = splitted_transformation[1]
|
temp_mat._data[0,1] = splitted_transformation[3]
|
||||||
temp_mat._data[2,0] = splitted_transformation[2]
|
temp_mat._data[1,1] = splitted_transformation[4]
|
||||||
temp_mat._data[0,1] = splitted_transformation[3]
|
temp_mat._data[2,1] = splitted_transformation[5]
|
||||||
temp_mat._data[1,1] = splitted_transformation[4]
|
temp_mat._data[0,2] = splitted_transformation[6]
|
||||||
temp_mat._data[2,1] = splitted_transformation[5]
|
temp_mat._data[1,2] = splitted_transformation[7]
|
||||||
temp_mat._data[0,2] = splitted_transformation[6]
|
temp_mat._data[2,2] = splitted_transformation[8]
|
||||||
temp_mat._data[1,2] = splitted_transformation[7]
|
|
||||||
temp_mat._data[2,2] = splitted_transformation[8]
|
|
||||||
|
|
||||||
# Translation
|
# Translation
|
||||||
temp_mat._data[0,3] = splitted_transformation[9]
|
temp_mat._data[0,3] = splitted_transformation[9]
|
||||||
temp_mat._data[1,3] = splitted_transformation[10]
|
temp_mat._data[1,3] = splitted_transformation[10]
|
||||||
temp_mat._data[2,3] = splitted_transformation[11]
|
temp_mat._data[2,3] = splitted_transformation[11]
|
||||||
|
|
||||||
node.setTransformation(temp_mat)
|
node.setTransformation(temp_mat)
|
||||||
except AttributeError:
|
|
||||||
pass # Empty list was found. Getting transformation is not possible
|
|
||||||
|
|
||||||
result.addChild(node)
|
result.addChild(node)
|
||||||
|
|
||||||
Job.yieldThread()
|
Job.yieldThread()
|
||||||
|
|
||||||
#If there is more then one object, group them.
|
#If there is more then one object, group them.
|
||||||
try:
|
if len(objects) > 1:
|
||||||
if len(objects) > 1:
|
group_decorator = GroupDecorator()
|
||||||
group_decorator = GroupDecorator()
|
result.addDecorator(group_decorator)
|
||||||
result.addDecorator(group_decorator)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Logger.log("e" ,"exception occured in 3mf reader: %s" , e)
|
Logger.log("e" ,"exception occured in 3mf reader: %s" , e)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue