def _saveCombinedSTL(self, filename):
		totalCount = 0
		for item in self.list:
			totalCount += item.mesh.vertexCount
		output = mesh.mesh()
		output._prepareVertexCount(totalCount)
		for item in self.list:
			offset = numpy.array([item.centerX, item.centerY, 0])
			for v in item.mesh.vertexes:
				v0 = v * item.scale + offset
				output.addVertex(v0[0], v0[1], v0[2])
		stl.saveAsSTL(output, filename)
Exemplo n.º 2
0
	def _saveCombinedSTL(self, filename):
		totalCount = 0
		for item in self.list:
			totalCount += item.mesh.vertexCount
		output = mesh.mesh()
		output._prepareVertexCount(totalCount)
		for item in self.list:
			vMin = item.getMinimum()
			vMax = item.getMaximum()
			offset = - vMin - (vMax - vMin) / 2
			offset += numpy.array([item.centerX, item.centerY, (vMax[2] - vMin[2]) / 2])
			vertexes = (item.mesh.vertexes * item.matrix).getA() + offset
			for v in vertexes:
				output.addVertex(v[0], v[1], v[2])
		stl.saveAsSTL(output, filename)
Exemplo n.º 3
0
 def _saveCombinedSTL(self, filename):
     totalCount = 0
     for item in self.list:
         totalCount += item.mesh.vertexCount
     output = mesh.mesh()
     output._prepareVertexCount(totalCount)
     for item in self.list:
         vMin = item.getMinimum()
         vMax = item.getMaximum()
         offset = -vMin - (vMax - vMin) / 2
         offset += numpy.array(
             [item.centerX, item.centerY, (vMax[2] - vMin[2]) / 2])
         vertexes = (item.mesh.vertexes * item.matrix).getA() + offset
         for v in vertexes:
             output.addVertex(v[0], v[1], v[2])
     stl.saveAsSTL(output, filename)
Exemplo n.º 4
0
	def OnImport(self, e):
		if self.level is None or self.selectArea is None:
			return

		xMin = min(self.selectArea[0], self.selectArea[2]) + (self.playerPos[0] - 16) * 16
		xMax = max(self.selectArea[0], self.selectArea[2]) + (self.playerPos[0] - 16) * 16
		yMin = min(self.selectArea[1], self.selectArea[3]) + (self.playerPos[1] - 16) * 16
		yMax = max(self.selectArea[1], self.selectArea[3]) + (self.playerPos[1] - 16) * 16

		sx = (xMax - xMin + 1)
		sy = (yMax - yMin + 1)
		blocks = numpy.zeros((sx, sy, 256), numpy.int32)

		cxMin = int(xMin / 16)
		cxMax = int((xMax + 15) / 16)
		cyMin = int(yMin / 16)
		cyMax = int((yMax + 15) / 16)

		for cx in xrange(cxMin, cxMax + 1):
			for cy in xrange(cyMin, cyMax + 1):
				chunk = self.level.getChunk(cx, cy)
				for x in xrange(0, 16):
					bx = x + cx * 16
					if xMin <= bx <= xMax:
						for y in xrange(0, 16):
							by = y + cy * 16
							if yMin <= by <= yMax:
								blocks[bx - xMin, by - yMin] = chunk.Blocks[x, y]
		minZ = 256
		maxZ = 0
		for x in xrange(0, sx):
			for y in xrange(0, sy):
				minZ = min(minZ, numpy.max(numpy.where(blocks[x, y] != 0)))
				maxZ = max(maxZ, numpy.max(numpy.where(blocks[x, y] != 0)))
		minZ += 1

		faceCount = 0
		for x in xrange(0, sx):
			for y in xrange(0, sy):
				for z in xrange(minZ, maxZ + 1):
					if self.isSolid[blocks[x, y, z]]:
						if z == maxZ or not self.isSolid[blocks[x, y, z + 1]]:
							faceCount += 1
						if z == minZ or not self.isSolid[blocks[x, y, z - 1]]:
							faceCount += 1
						if x == 0 or not self.isSolid[blocks[x - 1, y, z]]:
							faceCount += 1
						if x == sx - 1 or not self.isSolid[blocks[x + 1, y, z]]:
							faceCount += 1
						if y == 0 or not self.isSolid[blocks[x, y - 1, z]]:
							faceCount += 1
						if y == sy - 1 or not self.isSolid[blocks[x, y + 1, z]]:
							faceCount += 1
		m = mesh.mesh()
		m._prepareVertexCount(faceCount * 2 * 3)
		for x in xrange(0, sx):
			for y in xrange(0, sy):
				for z in xrange(minZ, maxZ + 1):
					if self.isSolid[blocks[x, y, z]]:
						if z == maxZ or not self.isSolid[blocks[x, y, z + 1]]:
							m.addVertex(x, y, z+1)
							m.addVertex(x+1, y, z+1)
							m.addVertex(x, y+1, z+1)

							m.addVertex(x+1, y+1, z+1)
							m.addVertex(x, y+1, z+1)
							m.addVertex(x+1, y, z+1)

						if z == minZ or not self.isSolid[blocks[x, y, z - 1]]:
							m.addVertex(x, y, z)
							m.addVertex(x, y+1, z)
							m.addVertex(x+1, y, z)

							m.addVertex(x+1, y+1, z)
							m.addVertex(x+1, y, z)
							m.addVertex(x, y+1, z)

						if x == 0 or not self.isSolid[blocks[x - 1, y, z]]:
							m.addVertex(x, y, z)
							m.addVertex(x, y, z+1)
							m.addVertex(x, y+1, z)

							m.addVertex(x, y+1, z+1)
							m.addVertex(x, y+1, z)
							m.addVertex(x, y, z+1)

						if x == sx - 1 or not self.isSolid[blocks[x + 1, y, z]]:
							m.addVertex(x+1, y, z)
							m.addVertex(x+1, y+1, z)
							m.addVertex(x+1, y, z+1)

							m.addVertex(x+1, y+1, z+1)
							m.addVertex(x+1, y, z+1)
							m.addVertex(x+1, y+1, z)

						if y == 0 or not self.isSolid[blocks[x, y - 1, z]]:
							m.addVertex(x, y, z)
							m.addVertex(x+1, y, z)
							m.addVertex(x, y, z+1)

							m.addVertex(x+1, y, z+1)
							m.addVertex(x, y, z+1)
							m.addVertex(x+1, y, z)

						if y == sy - 1 or not self.isSolid[blocks[x, y + 1, z]]:
							m.addVertex(x, y+1, z)
							m.addVertex(x, y+1, z+1)
							m.addVertex(x+1, y+1, z)

							m.addVertex(x+1, y+1, z+1)
							m.addVertex(x+1, y+1, z)
							m.addVertex(x, y+1, z+1)

		stlFilename = os.path.join(os.path.dirname(self.level.filename), 'export.stl')
		stl.saveAsSTL(m, stlFilename)
		self.GetParent()._loadModels([stlFilename])