1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
9 from Cura.util import mesh
14 for line in lines.split('\r'):
17 m._prepareFaceCount(int(cnt) / 3)
18 f.seek(5, os.SEEK_SET)
20 data = [None,None,None]
22 for line in lines.split('\r'):
24 data[cnt] = line.split()[1:]
27 m._addFace(float(data[0][0]), float(data[0][1]), float(data[0][2]), float(data[1][0]), float(data[1][1]), float(data[1][2]), float(data[2][0]), float(data[2][1]), float(data[2][2]))
30 def _loadBinary(m, f):
33 faceCount = struct.unpack('<I', f.read(4))[0]
34 m._prepareFaceCount(faceCount)
35 for idx in xrange(0, faceCount):
36 data = struct.unpack("<ffffffffffffH", f.read(50))
37 m._addFace(data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11])
39 def loadScene(filename):
40 obj = mesh.printableObject(os.path.basename(filename))
43 f = open(filename, "rb")
44 if f.read(5).lower() == "solid":
47 f.seek(5, os.SEEK_SET)
52 obj._postProcessAfterLoad()
55 def saveScene(filename, objects):
56 f = open(filename, 'wb')
57 #Write the STL binary header. This can contain any info, except for "SOLID" at the start.
58 f.write(("CURA BINARY STL EXPORT. " + time.strftime('%a %d %b %Y %H:%M:%S')).ljust(80, '\000'))
62 for m in obj._meshList:
63 vertexCount += m.vertexCount
65 #Next follow 4 binary bytes containing the amount of faces, and then the face information.
66 f.write(struct.pack("<I", int(vertexCount / 3)))
68 for m in obj._meshList:
69 vertexes = m.getTransformedVertexes(True)
70 for idx in xrange(0, m.vertexCount, 3):
74 f.write(struct.pack("<fff", 0.0, 0.0, 0.0))
75 f.write(struct.pack("<fff", v1[0], v1[1], v1[2]))
76 f.write(struct.pack("<fff", v2[0], v2[1], v2[2]))
77 f.write(struct.pack("<fff", v3[0], v3[1], v3[2]))
78 f.write(struct.pack("<H", 0))