From: daid Date: Thu, 27 Jun 2013 08:03:23 +0000 (+0200) Subject: Change how AMF is saved. Make better use of the index vertexes. X-Git-Tag: 13.10~133 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5f75e344cf017179c8b298b8c5595fa134d0d480;p=cura.git Change how AMF is saved. Make better use of the index vertexes. --- diff --git a/Cura/util/mesh.py b/Cura/util/mesh.py index 5d58f280..f1415fa6 100644 --- a/Cura/util/mesh.py +++ b/Cura/util/mesh.py @@ -200,12 +200,39 @@ class printableObject(object): if scale > 0: self.applyMatrix(numpy.matrix([[scale,0,0],[0,scale,0],[0,0,scale]], numpy.float64)) + #Split splits an object with multiple meshes into different objects, where each object is a part of the original mesh that has + # connected faces. This is useful to split up plate STL files. def split(self, callback): ret = [] for oriMesh in self._meshList: ret += oriMesh.split(callback) return ret + #getVertexIndexList returns an array of vertexes, and an integer array for each mesh in this object. + # the integer arrays are indexes into the vertex array for each triangle in the model. + def getVertexIndexList(self): + vertexMap = {} + vertexList = [] + meshList = [] + for m in self._meshList: + verts = m.getTransformedVertexes(True) + meshIdxList = [] + for idx in xrange(0, len(verts)): + v = verts[idx] + hashNr = int(v[0] * 100) | int(v[1] * 100) << 10 | int(v[2] * 100) << 20 + vIdx = None + if hashNr in vertexMap: + for idx2 in vertexMap[hashNr]: + if numpy.linalg.norm(v - vertexList[idx2]) < 0.001: + vIdx = idx2 + if vIdx is None: + vIdx = len(vertexList) + vertexMap[hashNr] = [vIdx] + vertexList.append(v) + meshIdxList.append(vIdx) + meshList.append(numpy.array(meshIdxList, numpy.int32)) + return numpy.array(vertexList, numpy.float32), meshList + class mesh(object): def __init__(self, obj): self.vertexes = None diff --git a/Cura/util/meshLoaders/amf.py b/Cura/util/meshLoaders/amf.py index f2b407b4..377e1023 100644 --- a/Cura/util/meshLoaders/amf.py +++ b/Cura/util/meshLoaders/amf.py @@ -88,28 +88,26 @@ def saveScene(filename, objects): xml.write(' \n' % (n)) xml.write(' \n') xml.write(' \n') - for m in obj._meshList: - for v in m.getTransformedVertexes(True): - xml.write(' \n') - xml.write(' \n') - xml.write(' %f\n' % (v[0])) - xml.write(' %f\n' % (v[1])) - xml.write(' %f\n' % (v[2])) - xml.write(' \n') - xml.write(' \n') + vertexList, meshList = obj.getVertexIndexList() + for v in vertexList: + xml.write(' \n') + xml.write(' \n') + xml.write(' %f\n' % (v[0])) + xml.write(' %f\n' % (v[1])) + xml.write(' %f\n' % (v[2])) + xml.write(' \n') + xml.write(' \n') xml.write(' \n') - idxOffset = 0 - for m in obj._meshList: + for m in meshList: xml.write(' \n') - for idx in xrange(0, len(m.vertexes), 3): + for idx in xrange(0, len(m), 3): xml.write(' \n') - xml.write(' %i\n' % (idx + idxOffset)) - xml.write(' %i\n' % (idx + idxOffset + 1)) - xml.write(' %i\n' % (idx + idxOffset + 2)) + xml.write(' %i\n' % (m[idx])) + xml.write(' %i\n' % (m[idx+1])) + xml.write(' %i\n' % (m[idx+2])) xml.write(' \n') xml.write(' \n') - idxOffset += len(m.vertexes) xml.write(' \n') xml.write(' \n')