Пример #1
0
 def OnCutMesh(self, e):
     dlg = wx.FileDialog(self,
                         "Open file to cut",
                         os.path.split(
                             profile.getPreference('lastFile'))[0],
                         style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
     dlg.SetWildcard(meshLoader.wildcardFilter())
     if dlg.ShowModal() == wx.ID_OK:
         filename = dlg.GetPath()
         model = meshLoader.loadMesh(filename)
         pd = wx.ProgressDialog(
             'Splitting model.', 'Splitting model into multiple parts.',
             model.vertexCount, self,
             wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME | wx.PD_SMOOTH)
         parts = model.splitToParts(pd.Update)
         for part in parts:
             partFilename = filename[:filename.rfind(
                 '.')] + "_part%d.stl" % (parts.index(part))
             stl.saveAsSTL(part, partFilename)
             item = ProjectObject(self, partFilename)
             self.list.append(item)
             self.selection = item
             self._updateListbox()
             self.OnListSelect(None)
         pd.Destroy()
     self.glCanvas.Refresh()
     dlg.Destroy()
Пример #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)
Пример #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)
Пример #4
0
	def OnCutMesh(self, e):
		dlg=wx.FileDialog(self, "Open file to cut", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
		dlg.SetWildcard(meshLoader.wildcardFilter())
		if dlg.ShowModal() == wx.ID_OK:
			filename = dlg.GetPath()
			model = meshLoader.loadMesh(filename)
			pd = wx.ProgressDialog('Splitting model.', 'Splitting model into multiple parts.', model.vertexCount, self, wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME | wx.PD_SMOOTH)
			parts = model.splitToParts(pd.Update)
			for part in parts:
				partFilename = filename[:filename.rfind('.')] + "_part%d.stl" % (parts.index(part))
				stl.saveAsSTL(part, partFilename)
				item = ProjectObject(self, partFilename)
				self.list.append(item)
				self.selection = item
				self._updateListbox()
				self.OnListSelect(None)
			pd.Destroy()
		self.glCanvas.Refresh()
		dlg.Destroy()
Пример #5
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])