mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-18 02:25:54 +08:00
Fix the save STL function after numpy upgrade.
This commit is contained in:
parent
8069d0633f
commit
cfbe98b0f7
@ -307,11 +307,16 @@ class projectPlanner(wx.Frame):
|
|||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
|
||||||
def _saveCombinedSTL(self, filename):
|
def _saveCombinedSTL(self, filename):
|
||||||
output = mesh.mesh()
|
totalCount = 0
|
||||||
for item in self.list:
|
for item in self.list:
|
||||||
offset = util3d.Vector3(item.centerX, item.centerY, 0)
|
totalCount += item.vertexCount
|
||||||
for f in item.faces:
|
output = mesh.mesh()
|
||||||
output.addFace(f.v[0] * item.scale + offset, f.v[1] * item.scale + offset, f.v[2] * item.scale + offset)
|
output._prepareVertexCount(totalCount)
|
||||||
|
for item in self.list:
|
||||||
|
offset = numpy.array([item.centerX, item.centerY, 0])
|
||||||
|
for v in item.vertexes:
|
||||||
|
v0 = v * item.scale + offset
|
||||||
|
output.addVertex(v0[0], v0[1], v0[2])
|
||||||
stl.saveAsSTL(output, filename)
|
stl.saveAsSTL(output, filename)
|
||||||
|
|
||||||
def OnSaveProject(self, e):
|
def OnSaveProject(self, e):
|
||||||
|
@ -83,22 +83,24 @@ class mesh(object):
|
|||||||
print "%f: " % (time.time() - t0), "Splitting a model with %d vertexes." % (len(self.vertexes))
|
print "%f: " % (time.time() - t0), "Splitting a model with %d vertexes." % (len(self.vertexes))
|
||||||
removeDict = {}
|
removeDict = {}
|
||||||
tree = util3d.AABBTree()
|
tree = util3d.AABBTree()
|
||||||
off = util3d.Vector3(0.0001,0.0001,0.0001)
|
off = numpy.array([0.0001,0.0001,0.0001])
|
||||||
newVertexList = []
|
newVertexList = []
|
||||||
for v in self.vertexes:
|
for idx in xrange(0, self.vertexCount):
|
||||||
|
v = self.vertexes[idx]
|
||||||
e = util3d.AABB(v-off, v+off)
|
e = util3d.AABB(v-off, v+off)
|
||||||
q = tree.query(e)
|
q = tree.query(e)
|
||||||
if len(q) < 1:
|
if len(q) < 1:
|
||||||
e.vector = v
|
e.idx = idx
|
||||||
tree.insert(e)
|
tree.insert(e)
|
||||||
newVertexList.append(v)
|
newVertexList.append(v)
|
||||||
else:
|
else:
|
||||||
removeDict[v] = q[0].vector
|
removeDict[idx] = q[0].idx
|
||||||
print "%f: " % (time.time() - t0), "Marked %d duplicate vertexes for removal." % (len(removeDict))
|
print "%f: " % (time.time() - t0), "Marked %d duplicate vertexes for removal." % (len(removeDict))
|
||||||
|
|
||||||
#Make facelists so we can quickly remove all the vertexes.
|
#Make facelists so we can quickly remove all the vertexes.
|
||||||
for v in self.vertexes:
|
vertexFaceList = []
|
||||||
v.faceList = []
|
for idx in xrange(0, self.vertexCount):
|
||||||
|
vertexFaceList.append([])
|
||||||
for f in self.faces:
|
for f in self.faces:
|
||||||
f.v[0].faceList.append(f)
|
f.v[0].faceList.append(f)
|
||||||
f.v[1].faceList.append(f)
|
f.v[1].faceList.append(f)
|
||||||
|
@ -49,17 +49,15 @@ def saveAsSTL(mesh, filename):
|
|||||||
#Write the STL binary header. This can contain any info, except for "SOLID" at the start.
|
#Write the STL binary header. This can contain any info, except for "SOLID" at the start.
|
||||||
f.write(("CURA BINARY STL EXPORT. " + time.strftime('%a %d %b %Y %H:%M:%S')).ljust(80, '\000'))
|
f.write(("CURA BINARY STL EXPORT. " + time.strftime('%a %d %b %Y %H:%M:%S')).ljust(80, '\000'))
|
||||||
#Next follow 4 binary bytes containing the amount of faces, and then the face information.
|
#Next follow 4 binary bytes containing the amount of faces, and then the face information.
|
||||||
f.write(struct.pack("<I", len(mesh.faces)))
|
f.write(struct.pack("<I", int(mesh.vertexCount/ 3)))
|
||||||
for face in mesh.faces:
|
for idx in xrange(0, mesh.vertexCount, 3):
|
||||||
v1 = face.v[0]
|
v1 = mesh.origonalVertexes[idx]
|
||||||
v2 = face.v[1]
|
v2 = mesh.origonalVertexes[idx+1]
|
||||||
v3 = face.v[2]
|
v3 = mesh.origonalVertexes[idx+2]
|
||||||
normal = (v2 - v1).cross(v3 - v1)
|
f.write(struct.pack("<fff", 0.0, 0.0, 0.0))
|
||||||
normal.normalize()
|
f.write(struct.pack("<fff", v1[0], v1[1], v1[2]))
|
||||||
f.write(struct.pack("<fff", normal.x, normal.y, normal.z))
|
f.write(struct.pack("<fff", v2[0], v2[1], v2[2]))
|
||||||
f.write(struct.pack("<fff", v1.x, v1.y, v1.z))
|
f.write(struct.pack("<fff", v3[0], v3[1], v3[2]))
|
||||||
f.write(struct.pack("<fff", v2.x, v2.y, v2.z))
|
|
||||||
f.write(struct.pack("<fff", v3.x, v3.y, v3.z))
|
|
||||||
f.write(struct.pack("<H", 0))
|
f.write(struct.pack("<H", 0))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
@ -67,7 +65,7 @@ if __name__ == '__main__':
|
|||||||
for filename in sys.argv[1:]:
|
for filename in sys.argv[1:]:
|
||||||
m = stlModel().load(filename)
|
m = stlModel().load(filename)
|
||||||
print("Loaded %d faces" % (m.vertexCount / 3))
|
print("Loaded %d faces" % (m.vertexCount / 3))
|
||||||
# parts = m.splitToParts()
|
parts = m.splitToParts()
|
||||||
# for p in parts:
|
# for p in parts:
|
||||||
# saveAsSTL(p, "export_%i.stl" % parts.index(p))
|
# saveAsSTL(p, "export_%i.stl" % parts.index(p))
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import math
|
import math
|
||||||
|
import numpy
|
||||||
|
|
||||||
class Vector3(object):
|
class Vector3(object):
|
||||||
def __init__(self, x=0.0, y=0.0, z=0.0):
|
def __init__(self, x=0.0, y=0.0, z=0.0):
|
||||||
@ -83,15 +84,15 @@ class AABB(object):
|
|||||||
self.vMax = vMax
|
self.vMax = vMax
|
||||||
|
|
||||||
def getPerimeter(self):
|
def getPerimeter(self):
|
||||||
return (self.vMax.x - self.vMax.x) + (self.vMax.y - self.vMax.y) + (self.vMax.z - self.vMax.z)
|
return (self.vMax[0] - self.vMax[0]) + (self.vMax[1] - self.vMax[1]) + (self.vMax[2] - self.vMax[2])
|
||||||
|
|
||||||
def combine(self, aabb):
|
def combine(self, aabb):
|
||||||
return AABB(self.vMin.min(aabb.vMin), self.vMax.max(aabb.vMax))
|
return AABB(numpy.minimum(self.vMin, aabb.vMin), numpy.maximum(self.vMax, aabb.vMax))
|
||||||
|
|
||||||
def overlap(self, aabb):
|
def overlap(self, aabb):
|
||||||
if aabb.vMin.x - self.vMax.x > 0.0 or aabb.vMin.y - self.vMax.y > 0.0 or aabb.vMin.z - self.vMax.z > 0.0:
|
if aabb.vMin[0] - self.vMax[0] > 0.0 or aabb.vMin[1] - self.vMax[1] > 0.0 or aabb.vMin[2] - self.vMax[2] > 0.0:
|
||||||
return False
|
return False
|
||||||
if self.vMin.x - aabb.vMax.x > 0.0 or self.vMin.y - aabb.vMax.y > 0.0 or self.vMin.z - aabb.vMax.z > 0.0:
|
if self.vMin[0] - aabb.vMax[0] > 0.0 or self.vMin[1] - aabb.vMax[1] > 0.0 or self.vMin[2] - aabb.vMax[2] > 0.0:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -308,9 +309,9 @@ class AABBTree(object):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
tree = AABBTree()
|
tree = AABBTree()
|
||||||
tree.insert(AABB(Vector3(0,0,0), Vector3(0,0,0)))
|
tree.insert(AABB(numpy.array([0,0,0]), numpy.array([0,0,0])))
|
||||||
tree.insert(AABB(Vector3(1,1,1), Vector3(1,1,1)))
|
tree.insert(AABB(numpy.array([1,1,1]), numpy.array([1,1,1])))
|
||||||
tree.insert(AABB(Vector3(0.5,0.5,0.5), Vector3(0.5,0.5,0.5)))
|
tree.insert(AABB(numpy.array([0.5,0.5,0.5]), numpy.array([0.5,0.5,0.5])))
|
||||||
print(tree)
|
print(tree)
|
||||||
print(tree.query(AABB(Vector3(0,0,0), Vector3(0,0,0))))
|
print(tree.query(AABB(numpy.array([0,0,0]), numpy.array([0,0,0]))))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user