Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLipu Fei <lipu.fei815@gmail.com>2019-09-04 15:32:53 +0300
committerLipu Fei <lipu.fei815@gmail.com>2019-09-04 15:33:24 +0300
commitcadbde7b92b722a2da87f6240efa0118f9126fb1 (patch)
tree39c33b6234a344856bb5f52c8fcc14090535f0fd /plugins/TrimeshReader
parentf051c48b9e64d36668993421d94a998e37e9433f (diff)
Add workaround for GLTF loading
CURA-6739
Diffstat (limited to 'plugins/TrimeshReader')
-rw-r--r--plugins/TrimeshReader/TrimeshReader.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/plugins/TrimeshReader/TrimeshReader.py b/plugins/TrimeshReader/TrimeshReader.py
index 41992ddbd1..bd34df6114 100644
--- a/plugins/TrimeshReader/TrimeshReader.py
+++ b/plugins/TrimeshReader/TrimeshReader.py
@@ -84,7 +84,17 @@ class TrimeshReader(MeshReader):
# types that Trimesh can read. It will not be checked again.
# \return A scene node that contains the file's contents.
def _read(self, file_name: str) -> Union["SceneNode", List["SceneNode"]]:
- mesh_or_scene = trimesh.load(file_name)
+ # CURA-6739
+ # GLTF files are essentially JSON files. If you directly give a file name to trimesh.load(), it will
+ # try to figure out the format, but for GLTF, it loads it as a binary file with flags "rb", and the json.load()
+ # doesn't like it. For some reason, this seems to happen with 3.5.7, but not 3.7.1. Below is a workaround to
+ # pass a file object that has been opened with "r" instead "rb" to load a GLTF file.
+ if file_name.endswith(".gltf"):
+ mesh_or_scene = trimesh.load(open(file_name, "r", encoding="utf-8"),
+ file_type = file_name.split(".")[-1].lower())
+ else:
+ mesh_or_scene = trimesh.load(file_name)
+
meshes = [] # type: List[Union[trimesh.Trimesh, trimesh.Scene, Any]]
if isinstance(mesh_or_scene, trimesh.Trimesh):
meshes = [mesh_or_scene]