mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-18 01:25:58 +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()
|
||||
|
||||
def _saveCombinedSTL(self, filename):
|
||||
output = mesh.mesh()
|
||||
totalCount = 0
|
||||
for item in self.list:
|
||||
offset = util3d.Vector3(item.centerX, item.centerY, 0)
|
||||
for f in item.faces:
|
||||
output.addFace(f.v[0] * item.scale + offset, f.v[1] * item.scale + offset, f.v[2] * item.scale + offset)
|
||||
totalCount += item.vertexCount
|
||||
output = mesh.mesh()
|
||||
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)
|
||||
|
||||
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))
|
||||
removeDict = {}
|
||||
tree = util3d.AABBTree()
|
||||
off = util3d.Vector3(0.0001,0.0001,0.0001)
|
||||
off = numpy.array([0.0001,0.0001,0.0001])
|
||||
newVertexList = []
|
||||
for v in self.vertexes:
|
||||
for idx in xrange(0, self.vertexCount):
|
||||
v = self.vertexes[idx]
|
||||
e = util3d.AABB(v-off, v+off)
|
||||
q = tree.query(e)
|
||||
if len(q) < 1:
|
||||
e.vector = v
|
||||
e.idx = idx
|
||||
tree.insert(e)
|
||||
newVertexList.append(v)
|
||||
else:
|
||||
removeDict[v] = q[0].vector
|
||||
removeDict[idx] = q[0].idx
|
||||
print "%f: " % (time.time() - t0), "Marked %d duplicate vertexes for removal." % (len(removeDict))
|
||||
|
||||
#Make facelists so we can quickly remove all the vertexes.
|
||||
for v in self.vertexes:
|
||||
v.faceList = []
|
||||
vertexFaceList = []
|
||||
for idx in xrange(0, self.vertexCount):
|
||||
vertexFaceList.append([])
|
||||
for f in self.faces:
|
||||
f.v[0].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.
|
||||
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.
|
||||
f.write(struct.pack("<I", len(mesh.faces)))
|
||||
for face in mesh.faces:
|
||||
v1 = face.v[0]
|
||||
v2 = face.v[1]
|
||||
v3 = face.v[2]
|
||||
normal = (v2 - v1).cross(v3 - v1)
|
||||
normal.normalize()
|
||||
f.write(struct.pack("<fff", normal.x, normal.y, normal.z))
|
||||
f.write(struct.pack("<fff", v1.x, v1.y, v1.z))
|
||||
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("<I", int(mesh.vertexCount/ 3)))
|
||||
for idx in xrange(0, mesh.vertexCount, 3):
|
||||
v1 = mesh.origonalVertexes[idx]
|
||||
v2 = mesh.origonalVertexes[idx+1]
|
||||
v3 = mesh.origonalVertexes[idx+2]
|
||||
f.write(struct.pack("<fff", 0.0, 0.0, 0.0))
|
||||
f.write(struct.pack("<fff", v1[0], v1[1], v1[2]))
|
||||
f.write(struct.pack("<fff", v2[0], v2[1], v2[2]))
|
||||
f.write(struct.pack("<fff", v3[0], v3[1], v3[2]))
|
||||
f.write(struct.pack("<H", 0))
|
||||
f.close()
|
||||
|
||||
@ -67,7 +65,7 @@ if __name__ == '__main__':
|
||||
for filename in sys.argv[1:]:
|
||||
m = stlModel().load(filename)
|
||||
print("Loaded %d faces" % (m.vertexCount / 3))
|
||||
# parts = m.splitToParts()
|
||||
parts = m.splitToParts()
|
||||
# for p in parts:
|
||||
# saveAsSTL(p, "export_%i.stl" % parts.index(p))
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import math
|
||||
import numpy
|
||||
|
||||
class Vector3(object):
|
||||
def __init__(self, x=0.0, y=0.0, z=0.0):
|
||||
@ -83,15 +84,15 @@ class AABB(object):
|
||||
self.vMax = vMax
|
||||
|
||||
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):
|
||||
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):
|
||||
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
|
||||
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 True
|
||||
|
||||
@ -308,9 +309,9 @@ class AABBTree(object):
|
||||
|
||||
if __name__ == '__main__':
|
||||
tree = AABBTree()
|
||||
tree.insert(AABB(Vector3(0,0,0), Vector3(0,0,0)))
|
||||
tree.insert(AABB(Vector3(1,1,1), Vector3(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,0,0]), numpy.array([0,0,0])))
|
||||
tree.insert(AABB(numpy.array([1,1,1]), numpy.array([1,1,1])))
|
||||
tree.insert(AABB(numpy.array([0.5,0.5,0.5]), numpy.array([0.5,0.5,0.5])))
|
||||
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