예제 #1
0
    def exportStlZ(self, model):
        bw = blockWork.blockWork(model)
        self.printStuff('start export stl Z 2.x...')
        fh = open(self.getSaveDest() + '.stl', 'wb')
        writer = stlWriter.Binary_STL_Writer(fh)

        #collectedBlocks = set()
        collectedBlocks = {}
        zTubes = {}
        for visBlock in model.shown:
            if not visBlock in collectedBlocks:
                x = None
                y = None
                z = None
                minZ = None
                maxZ = None

                for block in bw.getConnectedBlocksDirection(visBlock, cZ=True):
                    x, y, z = block
                    if maxZ is None or z > maxZ:
                        maxZ = z

                    if minZ is None or z < minZ:
                        minZ = z
                    #collectedBlocks.add(block)
                    collectedBlocks[block] = 0

                zTubes[(x, y, z)] = (minZ, maxZ)

        for tube in zTubes:
            x, y, z = tube
            #print tube, zTubes[tube][0], zTubes[tube][1]
            if zTubes[tube][0] == zTubes[tube][1]:
                writer.add_faces(self.getCubeFaces(x, y, zTubes[tube][0]))
            else:
                # we need the difference between the coords!
                writer.add_faces(
                    self.getCubeFaces(x, y, zTubes[tube][0],
                                      zTubes[tube][1] - zTubes[tube][0]))

        writer.close()
        self.printStuff('export stl completed')
예제 #2
0
	def exportStlZ(self, model):
		bw = blockWork.blockWork(model)
		self.printStuff('start export stl Z 2.x...')
		fh = open(self.getSaveDest() + '.stl', 'wb')
		writer = stlWriter.Binary_STL_Writer(fh)
		
		#collectedBlocks = set()
		collectedBlocks = {}
		zTubes =  {}
		for visBlock in model.shown:
			if not visBlock in collectedBlocks:
				x = None
				y = None
				z = None
				minZ = None
				maxZ = None
			
				for block in bw.getConnectedBlocksDirection(visBlock, cZ=True):
					x, y, z = block
					if maxZ is None or z > maxZ:
						maxZ = z
					
					if minZ is None or z < minZ:
						minZ = z
					#collectedBlocks.add(block)
					collectedBlocks[block] = 0
				
				zTubes[(x, y, z)] = (minZ, maxZ)
		
		for tube in zTubes:
			x, y, z = tube
			#print tube, zTubes[tube][0], zTubes[tube][1]
			if zTubes[tube][0] == zTubes[tube][1]:
				writer.add_faces(self.getCubeFaces(x, y, zTubes[tube][0]))
			else:
				# we need the difference between the coords!
				writer.add_faces(self.getCubeFaces(x, y, zTubes[tube][0], zTubes[tube][1]-zTubes[tube][0]))
				
		writer.close()
		self.printStuff('export stl completed')
예제 #3
0
파일: DICraft.py 프로젝트: leonslg/DICraft
    def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)

        # Whether or not the window exclusively captures the mouse.
        self.exclusive = False

        # When flying gravity has no effect and speed is increased.
        self.flying = True

        # First element is -1 when moving forward, 1 when moving back, and 0
        # otherwise. The second element is -1 when moving left, 1 when moving
        # right, and 0 otherwise.
        self.strafe = [0, 0]

        # Current (x, y, z) position in the world, specified with floats.
        self.position = (-2, -2, 1)

        # First element is rotation of the player in the x-z plane (ground
        # plane) measured from the z-axis down. The second is the rotation
        # angle from the ground plane up.
        self.rotation = (100, 0)

        # Which sector the player is currently in.
        self.sector = None

        # The crosshairs at the center of the screen.
        self.reticle = None

        # Velocity in the y (upward) direction.
        self.dy = 0

        # A list of blocks the player can place. Hit num keys to cycle.
        self.inventory = []
        for i in range(0, len(MATERIALS), 10):
            # print "inventory:",i, MATERIALS[i]
            self.inventory.append(i)

            # The current block the user can place. Hit num keys to cycle.
        self.block = self.inventory[0]

        # Convenience list of num keys.
        self.num_keys = [key._1, key._2, key._3, key._4, key._5, key._6, key._7, key._8, key._9, key._0]

        # the block that is currently focused
        self.focusedBlock = None

        # Instance of the model that handles the world.
        self.model = Model()

        # Instance of world modificator "blockwork"
        self.blockWork = blockWork.blockWork(self.model)

        self.labelDict = {}

        # The label that is displayed in the top left of the canvas.
        self.labelDict["worldInfo"] = pyglet.text.Label(
            "",
            font_name="Arial",
            font_size=16,
            x=10,
            y=self.height - 10,
            anchor_x="left",
            anchor_y="top",
            color=(0, 0, 0, 255),
        )

        # fix label while rendering the world
        self.labelDict["loabel"] = pyglet.text.Label(
            "!RENDERING WORLD, STAY TUNED!",
            font_name="Arial",
            font_size=16,
            x=self.width / 2,
            y=self.height / 2,
            anchor_x="center",
            anchor_y="top",
            color=(0, 0, 0, 255),
        )

        # notifications from engine
        self.labelDict["notify"] = pyglet.text.Label(
            "",
            font_name="Arial",
            font_size=16,
            x=self.width / 2,
            y=self.height / 2,
            anchor_x="center",
            anchor_y="top",
            color=(0, 0, 0, 255),
        )

        # focues block label
        self.labelDict["focusedBlock"] = pyglet.text.Label(
            "", font_name="Arial", font_size=12, x=5, y=25, anchor_x="left", anchor_y="top", color=(0, 0, 0, 255)
        )

        # This call schedules the `update()` method to be called 60 times a
        # second. This is the main game event loop.
        pyglet.clock.schedule_interval(self.update, 1.0 / 60)

        # interaction speed during mouse down events
        self.mouseInteractionSpeed = 0.35

        # start in window mode!
        self.fullScreen = False

        # a master timer for all the timers!
        self.mt = multiTimer.multiTimer()

        # check args for parameters
        for arg in sys.argv:
            if arg.startswith("rmVol="):
                # collect and remove "small" volumes
                self.blockWork.removeSmallVolumes(self.blockWork.getVolumes(), int(arg.replace("rmVol=", "")))  # 10000)
            elif arg.startswith("fillCavities="):
                # fill empty space
                self.blockWork.fillHoles(int(arg.replace("fillCavities=", "")))

                # add timer and bool for the initial loading text while rendereing the world
                # for the first time
        self.renderWorld = True
        self.mt.start("renderWorld")
예제 #4
0
	def __init__(self, *args, **kwargs):
		super(Window, self).__init__(*args, **kwargs)

		# Whether or not the window exclusively captures the mouse.
		self.exclusive = False

		# When flying gravity has no effect and speed is increased.
		self.flying = True

		# First element is -1 when moving forward, 1 when moving back, and 0
		# otherwise. The second element is -1 when moving left, 1 when moving
		# right, and 0 otherwise.
		self.strafe = [0, 0]

		# Current (x, y, z) position in the world, specified with floats.
		self.position = (-2, -2, 1)

		# First element is rotation of the player in the x-z plane (ground
		# plane) measured from the z-axis down. The second is the rotation
		# angle from the ground plane up.
		self.rotation = (100, 0)

		# Which sector the player is currently in.
		self.sector = None

		# The crosshairs at the center of the screen.
		self.reticle = None

		# Velocity in the y (upward) direction.
		self.dy = 0

		# A list of blocks the player can place. Hit num keys to cycle.
		self.inventory = []
		for i in range(0, len(MATERIALS), 10):
			#print "inventory:",i, MATERIALS[i]
			self.inventory.append(i)

		# The current block the user can place. Hit num keys to cycle.
		self.block = self.inventory[0]

		# Convenience list of num keys.
		self.num_keys = [
			key._1, key._2, key._3, key._4, key._5,
			key._6, key._7, key._8, key._9, key._0]

		# the block that is currently focused
		self.focusedBlock = None

		# Instance of the model that handles the world.
		self.model = Model()
		
		# Instance of world modificator "blockwork"
		self.blockWork = blockWork.blockWork(self.model)

		self.labelDict = {}

		# The label that is displayed in the top left of the canvas.
		self.labelDict['worldInfo'] = pyglet.text.Label('', font_name='Arial', font_size=16,
			x=10, y=self.height - 10, anchor_x='left', anchor_y='top',
			color=(0, 0, 0, 255))

		# fix label while rendering the world
		self.labelDict['loabel'] = pyglet.text.Label("!RENDERING WORLD, STAY TUNED!", font_name='Arial', font_size=16,
			x=self.width / 2, y=self.height / 2 , anchor_x='center', anchor_y='top',
			color=(0, 0, 0, 255))
			
		# notifications from engine
		self.labelDict['notify'] = pyglet.text.Label("", font_name='Arial', font_size=16,
			x=self.width / 2, y=self.height / 2 , anchor_x='center', anchor_y='top',
			color=(0, 0, 0, 255))
		
		# focues block label
		self.labelDict['focusedBlock'] = pyglet.text.Label("", font_name='Arial', font_size=12,
			x=5, y=25, anchor_x='left', anchor_y='top',
			color=(0, 0, 0, 255))

		# This call schedules the `update()` method to be called 60 times a
		# second. This is the main game event loop.
		pyglet.clock.schedule_interval(self.update, 1.0 / 60)
		
		# interaction speed during mouse down events
		self.mouseInteractionSpeed = 0.35
		
		# start in window mode!
		self.fullScreen = False
		
		# a master timer for all the timers!
		self.mt = multiTimer.multiTimer()
		
		# check args for parameters
		for arg in sys.argv:
			if arg.startswith("rmVol="):
				# collect and remove "small" volumes
				self.blockWork.removeSmallVolumes(self.blockWork.getVolumes(), int(arg.replace("rmVol=", ""))) #10000)
			elif arg.startswith("fillCavities="):
				# fill empty space
				self.blockWork.fillHoles(int(arg.replace("fillCavities=", "")))
		
		# add timer and bool for the initial loading text while rendereing the world
		# for the first time
		self.renderWorld = True
		self.mt.start("renderWorld")