mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-07-07 06:51:52 +08:00
Fail loading the 3MF file if no meshes were found
This way we indicate loading the 3MF file failed instead of indicating success but not actually loading anything. CURA-236
This commit is contained in:
parent
3bbefd588b
commit
463fbae9aa
@ -42,6 +42,10 @@ class ThreeMFReader(MeshReader):
|
|||||||
|
|
||||||
# There can be multiple objects, try to load all of them.
|
# There can be multiple objects, try to load all of them.
|
||||||
objects = root.findall("./3mf:resources/3mf:object", self._namespaces)
|
objects = root.findall("./3mf:resources/3mf:object", self._namespaces)
|
||||||
|
if len(objects) == 0:
|
||||||
|
Logger.log("w", "No objects found in 3MF file %s, either the file is corrupt or you are using an outdated format", file_name)
|
||||||
|
return None
|
||||||
|
|
||||||
for object in objects:
|
for object in objects:
|
||||||
mesh = MeshData()
|
mesh = MeshData()
|
||||||
node = SceneNode()
|
node = SceneNode()
|
||||||
@ -53,18 +57,18 @@ class ThreeMFReader(MeshReader):
|
|||||||
triangles = object.findall(".//3mf:triangle", self._namespaces)
|
triangles = object.findall(".//3mf:triangle", self._namespaces)
|
||||||
|
|
||||||
mesh.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.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])
|
||||||
#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.calculateNormals()
|
||||||
node.setMeshData(mesh)
|
node.setMeshData(mesh)
|
||||||
node.setSelectable(True)
|
node.setSelectable(True)
|
||||||
|
|
||||||
transformation = root.findall("./3mf:build/3mf:item[@objectid='{0}']".format(object.get("id")), self._namespaces)
|
transformation = root.findall("./3mf:build/3mf:item[@objectid='{0}']".format(object.get("id")), self._namespaces)
|
||||||
if transformation:
|
if transformation:
|
||||||
transformation = transformation[0]
|
transformation = transformation[0]
|
||||||
@ -88,25 +92,25 @@ class ThreeMFReader(MeshReader):
|
|||||||
temp_mat._data[0,2] = splitted_transformation[6]
|
temp_mat._data[0,2] = splitted_transformation[6]
|
||||||
temp_mat._data[1,2] = splitted_transformation[7]
|
temp_mat._data[1,2] = splitted_transformation[7]
|
||||||
temp_mat._data[2,2] = splitted_transformation[8]
|
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.setPosition(Vector(temp_mat.at(0,3), temp_mat.at(1,3), temp_mat.at(2,3)))
|
node.setPosition(Vector(temp_mat.at(0,3), temp_mat.at(1,3), temp_mat.at(2,3)))
|
||||||
|
|
||||||
temp_quaternion = Quaternion()
|
temp_quaternion = Quaternion()
|
||||||
temp_quaternion.setByMatrix(temp_mat)
|
temp_quaternion.setByMatrix(temp_mat)
|
||||||
node.setOrientation(temp_quaternion)
|
node.setOrientation(temp_quaternion)
|
||||||
|
|
||||||
# Magical scale extraction
|
# Magical scale extraction
|
||||||
S2 = temp_mat.getTransposed().multiply(temp_mat)
|
S2 = temp_mat.getTransposed().multiply(temp_mat)
|
||||||
scale_x = math.sqrt(S2.at(0,0))
|
scale_x = math.sqrt(S2.at(0,0))
|
||||||
scale_y = math.sqrt(S2.at(1,1))
|
scale_y = math.sqrt(S2.at(1,1))
|
||||||
scale_z = math.sqrt(S2.at(2,2))
|
scale_z = math.sqrt(S2.at(2,2))
|
||||||
node.setScale(Vector(scale_x,scale_y,scale_z))
|
node.setScale(Vector(scale_x,scale_y,scale_z))
|
||||||
|
|
||||||
# We use a different coordinate frame, so rotate.
|
# We use a different coordinate frame, so rotate.
|
||||||
rotation = Quaternion.fromAngleAxis(-0.5 * math.pi, Vector(1,0,0))
|
rotation = Quaternion.fromAngleAxis(-0.5 * math.pi, Vector(1,0,0))
|
||||||
node.rotate(rotation)
|
node.rotate(rotation)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user