chiark / gitweb /
plugins: Support user configuration of default values
[cura.git] / Cura / util / meshLoader.py
1 """
2 The meshLoader module contains a universal interface for loading 3D files.
3 Depending on the file extension the proper meshLoader is called to load the file.
4 """
5 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
6
7 import os
8
9 from Cura.util.meshLoaders import stl
10 from Cura.util.meshLoaders import obj
11 from Cura.util.meshLoaders import dae
12 from Cura.util.meshLoaders import amf
13
14 def loadSupportedExtensions():
15         """ return a list of supported file extensions for loading. """
16         return ['.stl', '.obj', '.dae', '.amf']
17
18 def saveSupportedExtensions():
19         """ return a list of supported file extensions for saving. """
20         return ['.amf', '.stl']
21
22 def loadMeshes(filename):
23         """
24         loadMeshes loads 1 or more printableObjects from a file.
25         STL files are a single printableObject with a single mesh, these are most common.
26         OBJ files usually contain a single mesh, but they can contain multiple meshes
27         AMF can contain whole scenes of objects with each object having multiple meshes.
28         DAE files are a mess, but they can contain scenes of objects as well as grouped meshes
29         """
30         ext = os.path.splitext(filename)[1].lower()
31         if ext == '.stl':
32                 return stl.loadScene(filename)
33         if ext == '.obj':
34                 return obj.loadScene(filename)
35         if ext == '.dae':
36                 return dae.loadScene(filename)
37         if ext == '.amf':
38                 return amf.loadScene(filename)
39         print 'Error: Unknown model extension: %s' % (ext)
40         return []
41
42 def saveMeshes(filename, objects):
43         """
44         Save a list of objects into the file given by the filename. Use the filename extension to find out the file format.
45         """
46         ext = os.path.splitext(filename)[1].lower()
47         if ext == '.stl':
48                 stl.saveScene(filename, objects)
49                 return
50         if ext == '.amf':
51                 amf.saveScene(filename, objects)
52                 return
53         print 'Error: Unknown model extension: %s' % (ext)