class BlockView(GLOrtho): def __init__(self, materials, blockInfo=None): GLOrtho.__init__(self) self.list = DisplayList(self._gl_draw) self.blockInfo = blockInfo or materials.Air self.materials = materials listBlockInfo = None def gl_draw(self): if self.listBlockInfo != self.blockInfo: self.list.invalidate() self.listBlockInfo = self.blockInfo self.list.call() def _gl_draw(self): blockInfo = self.blockInfo if blockInfo.ID is 0: return GL.glColor(1.0, 1.0, 1.0, 1.0) GL.glEnable(GL.GL_TEXTURE_2D) GL.glEnable(GL.GL_ALPHA_TEST) self.materials.terrainTexture.bind() GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY) GL.glVertexPointer( 2, GL.GL_FLOAT, 0, array([ -1, -1, -1, 1, 1, 1, 1, -1, ], dtype='float32')) texOrigin = self.materials.blockTextures[blockInfo.ID, blockInfo.blockData, 0] GL.glTexCoordPointer( 2, GL.GL_FLOAT, 0, array([ texOrigin[0], texOrigin[1] + 16, texOrigin[0], texOrigin[1], texOrigin[0] + 16, texOrigin[1], texOrigin[0] + 16, texOrigin[1] + 16 ], dtype='float32')) GL.glDrawArrays(GL.GL_QUADS, 0, 4) GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY) GL.glDisable(GL.GL_ALPHA_TEST) GL.glDisable(GL.GL_TEXTURE_2D) @property def tooltipText(self): return "{0}".format(self.blockInfo.name)
class BlockView(GLOrtho): def __init__(self, materials, blockInfo=None): GLOrtho.__init__(self) self.list = DisplayList(self._gl_draw) self.blockInfo = blockInfo or materials.Air self.materials = materials listBlockInfo = None def gl_draw(self): if self.listBlockInfo != self.blockInfo: self.list.invalidate() self.listBlockInfo = self.blockInfo self.list.call() def _gl_draw(self): blockInfo = self.blockInfo if blockInfo.ID is 0: return GL.glColor(1.0, 1.0, 1.0, 1.0) GL.glEnable(GL.GL_TEXTURE_2D) GL.glEnable(GL.GL_ALPHA_TEST) self.materials.terrainTexture.bind() pixelScale = 0.5 if self.materials.name in ("Pocket", "Alpha") else 1.0 texSize = 16 * pixelScale GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY) GL.glVertexPointer(2, GL.GL_FLOAT, 0, array([-1, -1, - 1, 1, 1, 1, 1, -1, ], dtype='float32')) # hack to get end rod to render properly # we really should use json models? if blockInfo.ID == 198: texOrigin = array([17*16, 20*16]) else: texOrigin = array(self.materials.blockTextures[blockInfo.ID, blockInfo.blockData, 0]) texOrigin = texOrigin.astype(float) * pixelScale GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, array([texOrigin[0], texOrigin[1] + texSize, texOrigin[0], texOrigin[1], texOrigin[0] + texSize, texOrigin[1], texOrigin[0] + texSize, texOrigin[1] + texSize], dtype='float32')) GL.glDrawArrays(GL.GL_QUADS, 0, 4) GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY) GL.glDisable(GL.GL_ALPHA_TEST) GL.glDisable(GL.GL_TEXTURE_2D) @property def tooltipText(self): #&# Prototype for blocks/items names #return str(self.blockInfo.name) return mclangres.translate(self.blockInfo.name)
def drawToolMarkers(self): if self._displayList is None: self._displayList = DisplayList(self._drawToolMarkers) # print len(self._selectedChunks) if self._selectedChunks else None, "!=", len(self.editor.selectedChunks) if self._selectedChunks != self.editor.selectedChunks or True: # xxx self._selectedChunks = set(self.editor.selectedChunks) self._displayList.invalidate() self._displayList.call()
class BlockView(GLOrtho): def __init__(self, materials, blockInfo=None): GLOrtho.__init__(self) self.list = DisplayList(self._gl_draw) self.blockInfo = blockInfo or materials.Air self.materials = materials listBlockInfo = None def gl_draw(self): if self.listBlockInfo != self.blockInfo: self.list.invalidate() self.listBlockInfo = self.blockInfo self.list.call() def _gl_draw(self): blockInfo = self.blockInfo if blockInfo.ID is 0: return GL.glColor(1.0, 1.0, 1.0, 1.0) GL.glEnable(GL.GL_TEXTURE_2D) GL.glEnable(GL.GL_ALPHA_TEST) self.materials.terrainTexture.bind() pixelScale = 0.5 if self.materials.name in ("Pocket", "Alpha") else 1.0 texSize = 16 * pixelScale GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY) GL.glVertexPointer(2, GL.GL_FLOAT, 0, array([-1, -1, - 1, 1, 1, 1, 1, -1, ], dtype='float32')) texOrigin = array(self.materials.blockTextures[blockInfo.ID, blockInfo.blockData, 0]) texOrigin *= pixelScale GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, array([texOrigin[0], texOrigin[1] + texSize, texOrigin[0], texOrigin[1], texOrigin[0] + texSize, texOrigin[1], texOrigin[0] + texSize, texOrigin[1] + texSize], dtype='float32')) GL.glDrawArrays(GL.GL_QUADS, 0, 4) GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY) GL.glDisable(GL.GL_ALPHA_TEST) GL.glDisable(GL.GL_TEXTURE_2D) @property def tooltipText(self): return "{0}".format(self.blockInfo.name)
def __init__(self, *args): EditorTool.__init__(self, *args) self.reloadTextures() textureVertices = numpy.array( ( 24, 16, 24, 8, 32, 8, 32, 16, 8, 16, 8, 8, 16, 8, 16, 16, 24, 0, 16, 0, 16, 8, 24, 8, 16, 0, 8, 0, 8, 8, 16, 8, 8, 8, 0, 8, 0, 16, 8, 16, 16, 16, 24, 16, 24, 8, 16, 8, ), dtype='f4') textureVertices.shape = (24, 2) textureVertices *= 4 textureVertices[:, 1] *= 2 self.texVerts = textureVertices self.playerPos = {} self.playerTexture = {} self.revPlayerPos = {} self.markerList = DisplayList()
def __init__(self, *args): EditorTool.__init__(self, *args) self.reloadTextures() self.nonSavedPlayers = [] textureVerticesHead = numpy.array( ( # Backside of Head 24, 16, # Bottom Left 24, 8, # Top Left 32, 8, # Top Right 32, 16, # Bottom Right # Front of Head 8, 16, 8, 8, 16, 8, 16, 16, # 24, 0, 16, 0, 16, 8, 24, 8, # 16, 0, 8, 0, 8, 8, 16, 8, # 8, 8, 0, 8, 0, 16, 8, 16, 16, 16, 24, 16, 24, 8, 16, 8, ), dtype='f4') textureVerticesHat = numpy.array( ( 56, 16, 56, 8, 64, 8, 64, 16, 48, 16, 48, 8, 40, 8, 40, 16, 56, 0, 48, 0, 48, 8, 56, 8, 48, 0, 40, 0, 40, 8, 48, 8, 40, 8, 32, 8, 32, 16, 40, 16, 48, 16, 56, 16, 56, 8, 48, 8, ), dtype='f4') textureVerticesHead.shape = (24, 2) textureVerticesHat.shape = (24, 2) textureVerticesHead *= 4 textureVerticesHead[:, 1] *= 2 textureVerticesHat *= 4 textureVerticesHat[:, 1] *= 2 self.texVerts = (textureVerticesHead, textureVerticesHat) self.playerPos = {0:{}, -1:{}, 1:{}} self.playerTexture = {} self.revPlayerPos = {0:{}, -1:{}, 1:{}} self.inOtherDimension = {0: [], 1: [], -1: []} self.playercache = PlayerCache() self.markerList = DisplayList()
class PlayerPositionTool(EditorTool): surfaceBuild = True toolIconName = "player" tooltipText = "Players" movingPlayer = None recordMove = True def reloadTextures(self): self.charTex = loadPNGTexture('char.png') @alertException def addPlayer(self): op = PlayerAddOperation(self) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() @alertException def removePlayer(self): player = self.panel.selectedPlayer if player != "[No players]": op = PlayerRemoveOperation(self, player) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() @alertException def movePlayer(self): if self.panel.selectedPlayer != "[No players]": self.movingPlayer = self.panel.selectedPlayer if self.movingPlayer == "Player (Single Player)": self.movingPlayer = "Player" @alertException def movePlayerToCamera(self): player = self.panel.selectedPlayer if player == "Player (Single Player)": player = "Player" if player != "[No players]": pos = self.editor.mainViewport.cameraPosition y = self.editor.mainViewport.yaw p = self.editor.mainViewport.pitch op = PlayerMoveOperation(self, pos, player, (y, p)) self.movingPlayer = None self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() def delete_skin(self, uuid): del self.playerTexture[uuid] self.playerTexture[uuid] = self.charTex @alertException def reloadSkins(self): #result = ask("This pulls skins from the online server, so this may take a while", ["Ok", "Cancel"]) #if result == "Ok": try: for player in self.editor.level.players: if player != "Player" and player in self.playerTexture.keys(): del self.playerTexture[player] # print 6 r = self.playercache.getPlayerSkin(player, force_download=True, instance=self) if isinstance(r, (str, unicode)): r = r.join() self.playerTexture[player] = loadPNGTexture(r) #self.markerList.call(self._drawToolMarkers) except: raise Exception("Could not connect to the skins server, please check your Internet connection and try again.") def gotoPlayerCamera(self): player = self.panel.selectedPlayer if player == "Player (Single Player)": player = "Player" try: pos = self.editor.level.getPlayerPosition(player) y, p = self.editor.level.getPlayerOrientation(player) self.editor.gotoDimension(self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.yaw = y self.editor.mainViewport.pitch = p self.editor.mainViewport.stopMoving() self.editor.mainViewport.invalidate() except pymclevel.PlayerNotFound: pass def gotoPlayer(self): player = self.panel.selectedPlayer if player == "Player (Single Player)": player = "Player" try: if self.editor.mainViewport.pitch < 0: self.editor.mainViewport.pitch = -self.editor.mainViewport.pitch self.editor.mainViewport.cameraVector = self.editor.mainViewport._cameraVector() cv = self.editor.mainViewport.cameraVector pos = self.editor.level.getPlayerPosition(player) pos = map(lambda p, c: p - c * 5, pos, cv) self.editor.gotoDimension(self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.stopMoving() except pymclevel.PlayerNotFound: pass def __init__(self, *args): EditorTool.__init__(self, *args) self.reloadTextures() self.nonSavedPlayers = [] textureVerticesHead = numpy.array( ( # Backside of Head 24, 16, # Bottom Left 24, 8, # Top Left 32, 8, # Top Right 32, 16, # Bottom Right # Front of Head 8, 16, 8, 8, 16, 8, 16, 16, # 24, 0, 16, 0, 16, 8, 24, 8, # 16, 0, 8, 0, 8, 8, 16, 8, # 8, 8, 0, 8, 0, 16, 8, 16, 16, 16, 24, 16, 24, 8, 16, 8, ), dtype='f4') textureVerticesHat = numpy.array( ( 56, 16, 56, 8, 64, 8, 64, 16, 48, 16, 48, 8, 40, 8, 40, 16, 56, 0, 48, 0, 48, 8, 56, 8, 48, 0, 40, 0, 40, 8, 48, 8, 40, 8, 32, 8, 32, 16, 40, 16, 48, 16, 56, 16, 56, 8, 48, 8, ), dtype='f4') textureVerticesHead.shape = (24, 2) textureVerticesHat.shape = (24, 2) textureVerticesHead *= 4 textureVerticesHead[:, 1] *= 2 textureVerticesHat *= 4 textureVerticesHat[:, 1] *= 2 self.texVerts = (textureVerticesHead, textureVerticesHat) self.playerPos = {0:{}, -1:{}, 1:{}} self.playerTexture = {} self.revPlayerPos = {0:{}, -1:{}, 1:{}} self.inOtherDimension = {0: [], 1: [], -1: []} self.playercache = PlayerCache() self.markerList = DisplayList() panel = None def showPanel(self): if not self.panel: self.panel = PlayerPositionPanel(self) self.panel.centery = (self.editor.mainViewport.height - self.editor.toolbar.height) / 2 + self.editor.subwidgets[0].height self.panel.left = self.editor.left self.editor.add(self.panel) def hidePanel(self): if self.panel and self.panel.parent: self.panel.parent.remove(self.panel) self.panel = None def drawToolReticle(self): if self.movingPlayer is None: return pos, direction = self.editor.blockFaceUnderCursor dim = self.editor.level.getPlayerDimension(self.movingPlayer) pos = (pos[0], pos[1] + 2, pos[2]) x, y, z = pos # x,y,z=map(lambda p,d: p+d, pos, direction) GL.glEnable(GL.GL_BLEND) GL.glColor(1.0, 1.0, 1.0, 0.5) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5, self.revPlayerPos[dim][self.movingPlayer], dim) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5, self.revPlayerPos[dim][self.movingPlayer], dim) drawTerrainCuttingWire(BoundingBox((x, y, z), (1, 1, 1))) drawTerrainCuttingWire(BoundingBox((x, y - 1, z), (1, 1, 1))) #drawTerrainCuttingWire( BoundingBox((x,y-2,z), (1,1,1)) ) GL.glDisable(GL.GL_DEPTH_TEST) markerLevel = None def drawToolMarkers(self): if not config.settings.drawPlayerHeads.get(): return if self.markerLevel != self.editor.level: self.markerList.invalidate() self.markerLevel = self.editor.level self.markerList.call(self._drawToolMarkers) def _drawToolMarkers(self): GL.glColor(1.0, 1.0, 1.0, 0.5) GL.glEnable(GL.GL_DEPTH_TEST) GL.glMatrixMode(GL.GL_MODELVIEW) for player in self.editor.level.players: try: pos = self.editor.level.getPlayerPosition(player) yaw, pitch = self.editor.level.getPlayerOrientation(player) dim = self.editor.level.getPlayerDimension(player) self.inOtherDimension[dim].append(player) self.playerPos[dim][pos] = player self.revPlayerPos[dim][player] = pos if player != "Player" and config.settings.downloadPlayerSkins.get(): # print 7 r = self.playercache.getPlayerSkin(player, force_download=False) if not isinstance(r, (str, unicode)): r = r.join() self.playerTexture[player] = loadPNGTexture(r) else: self.playerTexture[player] = self.charTex if dim != self.editor.level.dimNo: continue x, y, z = pos GL.glPushMatrix() GL.glTranslate(x, y, z) GL.glRotate(-yaw, 0, 1, 0) GL.glRotate(pitch, 1, 0, 0) GL.glColor(1, 1, 1, 1) self.drawCharacterHead(0, 0, 0, (x,y,z), self.editor.level.dimNo) GL.glPopMatrix() # GL.glEnable(GL.GL_BLEND) drawTerrainCuttingWire(FloatBox((x - .5, y - .5, z - .5), (1, 1, 1)), c0=(0.3, 0.9, 0.7, 1.0), c1=(0, 0, 0, 0), ) #GL.glDisable(GL.GL_BLEND) except Exception, e: print "Exception in editortools.player.PlayerPositionTool._drawToolMarkers:", repr(e) import traceback print traceback.format_exc() continue GL.glDisable(GL.GL_DEPTH_TEST)
class PlayerPositionTool(EditorTool): surfaceBuild = True toolIconName = "player" tooltipText = "Players" movingPlayer = None recordMove = True def reloadTextures(self): self.charTex = loadPNGTexture('char.png') @alertException def addPlayer(self): op = PlayerAddOperation(self) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() @alertException def removePlayer(self): player = self.panel.selectedPlayer if player != "[No players]": op = PlayerRemoveOperation(self, player) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() @alertException def movePlayer(self): if self.panel.selectedPlayer != "[No players]": self.movingPlayer = self.panel.selectedPlayer @alertException def movePlayerToCamera(self): player = self.panel.selectedPlayer if player != "[No players]": pos = self.editor.mainViewport.cameraPosition y = self.editor.mainViewport.yaw p = self.editor.mainViewport.pitch d = self.editor.level.dimNo op = PlayerMoveOperation(self, pos, player, (y, p)) self.movingPlayer = None self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() def delete_skin(self, uuid): del self.playerTexture[uuid] self.playerTexture[uuid] = loadPNGTexture('char.png') @alertException def reloadSkins(self): #result = ask("This pulls skins from the online server, so this may take a while", ["Ok", "Cancel"]) #if result == "Ok": try: for player in self.editor.level.players: if player != "Player" and player != "[No players]" and player in self.playerTexture.keys(): del self.playerTexture[player] self.playerTexture[player] = loadPNGTexture(version_utils.getPlayerSkin(player, force=True, instance=self)) except: raise Exception("Could not connect to the skins server, please check your Internet connection and try again.") def gotoPlayerCamera(self): player = self.panel.selectedPlayer try: pos = self.editor.level.getPlayerPosition(player) y, p = self.editor.level.getPlayerOrientation(player) self.editor.gotoDimension(self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.yaw = y self.editor.mainViewport.pitch = p self.editor.mainViewport.stopMoving() self.editor.mainViewport.invalidate() except pymclevel.PlayerNotFound: pass def gotoPlayer(self): player = self.panel.selectedPlayer try: if self.editor.mainViewport.pitch < 0: self.editor.mainViewport.pitch = -self.editor.mainViewport.pitch self.editor.mainViewport.cameraVector = self.editor.mainViewport._cameraVector() cv = self.editor.mainViewport.cameraVector pos = self.editor.level.getPlayerPosition(player) pos = map(lambda p, c: p - c * 5, pos, cv) self.editor.gotoDimension(self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.stopMoving() except pymclevel.PlayerNotFound: pass def __init__(self, *args): EditorTool.__init__(self, *args) self.reloadTextures() textureVertices = numpy.array( ( 24, 16, 24, 8, 32, 8, 32, 16, 8, 16, 8, 8, 16, 8, 16, 16, 24, 0, 16, 0, 16, 8, 24, 8, 16, 0, 8, 0, 8, 8, 16, 8, 8, 8, 0, 8, 0, 16, 8, 16, 16, 16, 24, 16, 24, 8, 16, 8, ), dtype='f4') textureVertices.shape = (24, 2) textureVertices *= 4 textureVertices[:, 1] *= 2 self.texVerts = textureVertices self.playerPos = {} self.playerTexture = {} self.revPlayerPos = {} self.markerList = DisplayList() panel = None def showPanel(self): if not self.panel: self.panel = PlayerPositionPanel(self) self.panel.left = self.editor.left self.panel.centery = self.editor.centery self.editor.add(self.panel) def hidePanel(self): if self.panel and self.panel.parent: self.panel.parent.remove(self.panel) self.panel = None def drawToolReticle(self): if self.movingPlayer is None: return pos, direction = self.editor.blockFaceUnderCursor pos = (pos[0], pos[1] + 2, pos[2]) x, y, z = pos # x,y,z=map(lambda p,d: p+d, pos, direction) GL.glEnable(GL.GL_BLEND) GL.glColor(1.0, 1.0, 1.0, 0.5) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5, self.revPlayerPos[self.movingPlayer]) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5, self.revPlayerPos[self.movingPlayer]) drawTerrainCuttingWire(BoundingBox((x, y, z), (1, 1, 1))) drawTerrainCuttingWire(BoundingBox((x, y - 1, z), (1, 1, 1))) #drawTerrainCuttingWire( BoundingBox((x,y-2,z), (1,1,1)) ) GL.glDisable(GL.GL_DEPTH_TEST) markerLevel = None def drawToolMarkers(self): if self.markerLevel != self.editor.level: self.markerList.invalidate() self.markerLevel = self.editor.level self.markerList.call(self._drawToolMarkers) def _drawToolMarkers(self): GL.glColor(1.0, 1.0, 1.0, 0.5) GL.glEnable(GL.GL_DEPTH_TEST) GL.glMatrixMode(GL.GL_MODELVIEW) for player in self.editor.level.players: try: pos = self.editor.level.getPlayerPosition(player) yaw, pitch = self.editor.level.getPlayerOrientation(player) dim = self.editor.level.getPlayerDimension(player) if dim != self.editor.level.dimNo: continue self.playerPos[pos] = player self.revPlayerPos[player] = pos if player != "Player": self.playerTexture[player] = loadPNGTexture(version_utils.getPlayerSkin(player, force=False)) x, y, z = pos GL.glPushMatrix() GL.glTranslate(x, y, z) GL.glRotate(-yaw, 0, 1, 0) GL.glRotate(pitch, 1, 0, 0) GL.glColor(1, 1, 1, 1) self.drawCharacterHead(0, 0, 0, (x,y,z)) GL.glPopMatrix() # GL.glEnable(GL.GL_BLEND) drawTerrainCuttingWire(FloatBox((x - .5, y - .5, z - .5), (1, 1, 1)), c0=(0.3, 0.9, 0.7, 1.0), c1=(0, 0, 0, 0), ) #GL.glDisable(GL.GL_BLEND) except Exception, e: print repr(e) continue GL.glDisable(GL.GL_DEPTH_TEST)
class ChunkTool(EditorTool): toolIconName = "chunk" tooltipText = "Chunk Control" @property def statusText(self): return _( "Click and drag to select chunks. Hold {0} to deselect chunks. Hold {1} to select chunks." ).format(_(config.keys.deselectChunks.get()), _(config.keys.selectChunks.get())) def toolEnabled(self): return isinstance(self.editor.level, pymclevel.ChunkedLevelMixin) _selectedChunks = None _displayList = None def drawToolMarkers(self): if self._displayList is None: self._displayList = DisplayList(self._drawToolMarkers) # print len(self._selectedChunks) if self._selectedChunks else None, "!=", len(self.editor.selectedChunks) if self._selectedChunks != self.editor.selectedChunks or True: # xxx self._selectedChunks = set(self.editor.selectedChunks) self._displayList.invalidate() self._displayList.call() def _drawToolMarkers(self): lines = ( ((-1, 0), (0, 0, 0, 1), []), ((1, 0), (1, 0, 1, 1), []), ((0, -1), (0, 0, 1, 0), []), ((0, 1), (0, 1, 1, 1), []), ) for ch in self._selectedChunks: cx, cz = ch for (dx, dz), points, positions in lines: n = (cx + dx, cz + dz) if n not in self._selectedChunks: positions.append([ch]) color = self.editor.selectionTool.selectionColor + (0.3, ) GL.glColor(*color) with gl.glEnable(GL.GL_BLEND): import renderer sizedChunks = renderer.chunkMarkers(self._selectedChunks) for size, chunks in sizedChunks.iteritems(): if not len(chunks): continue chunks = numpy.array(chunks, dtype='float32') chunkPosition = numpy.zeros(shape=(chunks.shape[0], 4, 3), dtype='float32') chunkPosition[..., (0, 2)] = numpy.array( ((0, 0), (0, 1), (1, 1), (1, 0)), dtype='float32') chunkPosition[..., (0, 2)] *= size chunkPosition[..., (0, 2)] += chunks[:, newaxis, :] chunkPosition *= 16 chunkPosition[..., 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, chunkPosition.ravel()) # chunkPosition *= 8 GL.glDrawArrays(GL.GL_QUADS, 0, len(chunkPosition) * 4) for d, points, positions in lines: if 0 == len(positions): continue vertexArray = numpy.zeros((len(positions), 4, 3), dtype='float32') vertexArray[..., [0, 2]] = positions vertexArray.shape = len(positions), 2, 2, 3 vertexArray[..., 0, 0, 0] += points[0] vertexArray[..., 0, 0, 2] += points[1] vertexArray[..., 0, 1, 0] += points[2] vertexArray[..., 0, 1, 2] += points[3] vertexArray[..., 1, 0, 0] += points[2] vertexArray[..., 1, 0, 2] += points[3] vertexArray[..., 1, 1, 0] += points[0] vertexArray[..., 1, 1, 2] += points[1] vertexArray *= 16 vertexArray[..., 1, :, 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArray) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) with gl.glEnable(GL.GL_BLEND, GL.GL_DEPTH_TEST): GL.glDepthMask(False) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glDepthMask(True) @property def worldTooltipText(self): box = self.editor.selectionTool.selectionBoxInProgress() if box: box = box.chunkBox(self.editor.level) l, w = box.length // 16, box.width // 16 return _("%s x %s chunks") % (l, w) def toolSelected(self): self.editor.selectionToChunks() self.panel = ChunkToolPanel(self) self.panel.centery = self.editor.centery self.panel.left = 10 self.editor.add(self.panel) def toolDeselected(self): self.editor.chunksToSelection() def cancel(self): self.editor.remove(self.panel) def selectedChunks(self): return self.editor.selectedChunks @alertException def destroyChunks(self, chunks=None): if "No" == ask("Really delete these chunks? This cannot be undone.", ("Yes", "No")): return if chunks is None: chunks = self.selectedChunks() chunks = list(chunks) def _destroyChunks(): i = 0 chunkCount = len(chunks) for cx, cz in chunks: i += 1 yield (i, chunkCount) if self.editor.level.containsChunk(cx, cz): try: self.editor.level.deleteChunk(cx, cz) except Exception, e: print "Error during chunk delete: ", e with setWindowCaption("DELETING - "): showProgress("Deleting chunks...", _destroyChunks()) self.editor.renderer.invalidateChunkMarkers() self.editor.renderer.discardAllChunks()
def __init__(self, materials, blockInfo=None): GLOrtho.__init__(self) self.list = DisplayList(self._gl_draw) self.blockInfo = blockInfo or materials.Air self.materials = materials
class PlayerPositionTool(EditorTool): surfaceBuild = True toolIconName = "player" tooltipText = "Players" movingPlayer = None recordMove = True def reloadTextures(self): self.charTex = loadPNGTexture('char.png') @alertException def addPlayer(self): op = PlayerAddOperation(self) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() @alertException def removePlayer(self): player = self.panel.selectedPlayer if player != "[No players]": op = PlayerRemoveOperation(self, player) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() @alertException def movePlayer(self): if self.panel.selectedPlayer != "[No players]": self.movingPlayer = self.panel.selectedPlayer if self.movingPlayer == "Player (Single Player)": self.movingPlayer = "Player" @alertException def movePlayerToCamera(self): player = self.panel.selectedPlayer if player == "Player (Single Player)": player = "Player" if player != "[No players]": pos = self.editor.mainViewport.cameraPosition y = self.editor.mainViewport.yaw p = self.editor.mainViewport.pitch op = PlayerMoveOperation(self, pos, player, (y, p)) self.movingPlayer = None self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() def delete_skin(self, uuid): del self.playerTexture[uuid] self.playerTexture[uuid] = self.charTex @alertException def reloadSkins(self): # result = ask("This pulls skins from the online server, so this may take a while", ["Ok", "Cancel"]) # if result == "Ok": try: for player in self.editor.level.players: if player != "Player" and player in list(self.playerTexture.keys()): del self.playerTexture[player] # print 6 r = self.playercache.getPlayerSkin(player, force_download=True, instance=self) if isinstance(r, str): r = r.join() self.playerTexture[player] = loadPNGTexture(r) # self.markerList.call(self._drawToolMarkers) except: raise Exception("Could not connect to the skins server, please check your Internet connection and try again.") def gotoPlayerCamera(self): player = self.panel.selectedPlayer if player == "Player (Single Player)": player = "Player" try: pos = self.editor.level.getPlayerPosition(player) y, p = self.editor.level.getPlayerOrientation(player) self.editor.gotoDimension(self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.yaw = y self.editor.mainViewport.pitch = p self.editor.mainViewport.stopMoving() self.editor.mainViewport.invalidate() except pymclevel.PlayerNotFound: pass def gotoPlayer(self): player = self.panel.selectedPlayer if player == "Player (Single Player)": player = "Player" try: if self.editor.mainViewport.pitch < 0: self.editor.mainViewport.pitch = -self.editor.mainViewport.pitch self.editor.mainViewport.cameraVector = self.editor.mainViewport._cameraVector() cv = self.editor.mainViewport.cameraVector pos = self.editor.level.getPlayerPosition(player) pos = list(map(lambda p, c: p - c * 5, pos, cv)) self.editor.gotoDimension(self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.stopMoving() except pymclevel.PlayerNotFound: pass def __init__(self, *args): EditorTool.__init__(self, *args) self.reloadTextures() self.nonSavedPlayers = [] textureVerticesHead = numpy.array( ( # Backside of Head 24, 16, # Bottom Left 24, 8, # Top Left 32, 8, # Top Right 32, 16, # Bottom Right # Front of Head 8, 16, 8, 8, 16, 8, 16, 16, # 24, 0, 16, 0, 16, 8, 24, 8, # 16, 0, 8, 0, 8, 8, 16, 8, # 8, 8, 0, 8, 0, 16, 8, 16, 16, 16, 24, 16, 24, 8, 16, 8, ), dtype='f4') textureVerticesHat = numpy.array( ( 56, 16, 56, 8, 64, 8, 64, 16, 48, 16, 48, 8, 40, 8, 40, 16, 56, 0, 48, 0, 48, 8, 56, 8, 48, 0, 40, 0, 40, 8, 48, 8, 40, 8, 32, 8, 32, 16, 40, 16, 48, 16, 56, 16, 56, 8, 48, 8, ), dtype='f4') textureVerticesHead.shape = (24, 2) textureVerticesHat.shape = (24, 2) textureVerticesHead *= 4 textureVerticesHead[:, 1] *= 2 textureVerticesHat *= 4 textureVerticesHat[:, 1] *= 2 self.texVerts = (textureVerticesHead, textureVerticesHat) self.playerPos = {0: {}, -1: {}, 1: {}} self.playerTexture = {} self.revPlayerPos = {0: {}, -1: {}, 1: {}} self.inOtherDimension = {0: [], 1: [], -1: []} self.playercache = PlayerCache() self.markerList = DisplayList() panel = None def showPanel(self): if not self.panel: self.panel = PlayerPositionPanel(self) self.panel.centery = (self.editor.mainViewport.height - self.editor.toolbar.height) / 2 + self.editor.subwidgets[0].height self.panel.left = self.editor.left self.editor.add(self.panel) def hidePanel(self): if self.panel and self.panel.parent: self.panel.parent.remove(self.panel) self.panel = None def drawToolReticle(self): if self.movingPlayer is None: return pos, direction = self.editor.blockFaceUnderCursor dim = self.editor.level.getPlayerDimension(self.movingPlayer) pos = (pos[0], pos[1] + 2, pos[2]) x, y, z = pos # x,y,z=map(lambda p,d: p+d, pos, direction) GL.glEnable(GL.GL_BLEND) GL.glColor(1.0, 1.0, 1.0, 0.5) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5, self.revPlayerPos[dim][self.movingPlayer], dim) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5, self.revPlayerPos[dim][self.movingPlayer], dim) drawTerrainCuttingWire(BoundingBox((x, y, z), (1, 1, 1))) drawTerrainCuttingWire(BoundingBox((x, y - 1, z), (1, 1, 1))) # drawTerrainCuttingWire( BoundingBox((x,y-2,z), (1,1,1)) ) GL.glDisable(GL.GL_DEPTH_TEST) markerLevel = None def drawToolMarkers(self): if not config.settings.drawPlayerHeads.get(): return if self.markerLevel != self.editor.level: self.markerList.invalidate() self.markerLevel = self.editor.level self.markerList.call(self._drawToolMarkers) def _drawToolMarkers(self): GL.glColor(1.0, 1.0, 1.0, 0.5) GL.glEnable(GL.GL_DEPTH_TEST) GL.glMatrixMode(GL.GL_MODELVIEW) for player in self.editor.level.players: try: pos = self.editor.level.getPlayerPosition(player) yaw, pitch = self.editor.level.getPlayerOrientation(player) dim = self.editor.level.getPlayerDimension(player) self.inOtherDimension[dim].append(player) self.playerPos[dim][pos] = player self.revPlayerPos[dim][player] = pos if player != "Player" and config.settings.downloadPlayerSkins.get(): # print 7 r = self.playercache.getPlayerSkin(player, force_download=False) if not isinstance(r, str): r = r.join() self.playerTexture[player] = loadPNGTexture(r) else: self.playerTexture[player] = self.charTex if dim != self.editor.level.dimNo: continue x, y, z = pos GL.glPushMatrix() GL.glTranslate(x, y, z) GL.glRotate(-yaw, 0, 1, 0) GL.glRotate(pitch, 1, 0, 0) GL.glColor(1, 1, 1, 1) self.drawCharacterHead(0, 0, 0, (x, y, z), self.editor.level.dimNo) GL.glPopMatrix() # GL.glEnable(GL.GL_BLEND) drawTerrainCuttingWire(FloatBox((x - .5, y - .5, z - .5), (1, 1, 1)), c0=(0.3, 0.9, 0.7, 1.0), c1=(0, 0, 0, 0), ) # GL.glDisable(GL.GL_BLEND) except Exception as e: print("Exception in editortools.player.PlayerPositionTool._drawToolMarkers:", repr(e)) import traceback print(traceback.format_exc()) continue GL.glDisable(GL.GL_DEPTH_TEST) def drawCharacterHead(self, x, y, z, realCoords=None, dim=0): GL.glEnable(GL.GL_CULL_FACE) origin = (x - 0.25, y - 0.25, z - 0.25) size = (0.5, 0.5, 0.5) box = FloatBox(origin, size) hat_origin = (x - 0.275, y - 0.275, z - 0.275) hat_size = (0.55, 0.55, 0.55) hat_box = FloatBox(hat_origin, hat_size) if realCoords is not None and self.playerPos[dim][realCoords] != "Player" and config.settings.downloadPlayerSkins.get(): drawCube(box, texture=self.playerTexture[self.playerPos[dim][realCoords]], textureVertices=self.texVerts[0]) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) drawCube(hat_box, texture=self.playerTexture[self.playerPos[dim][realCoords]], textureVertices=self.texVerts[1]) GL.glDisable(GL.GL_BLEND) else: drawCube(box, texture=self.charTex, textureVertices=self.texVerts[0]) GL.glDisable(GL.GL_CULL_FACE) # @property # def statusText(self): # if not self.panel: # return "" # player = self.panel.selectedPlayer # if player == "Player": # return "Click to move the player" # # return _("Click to move the player \"{0}\"").format(player) @alertException def mouseDown(self, evt, pos, direction): if self.movingPlayer is None: return pos = (pos[0] + 0.5, pos[1] + 2.75, pos[2] + 0.5) op = PlayerMoveOperation(self, pos, self.movingPlayer) self.movingPlayer = None if self.recordMove: self.editor.addOperation(op) addingMoving = False else: self.editor.performWithRetry(op) # Prevent recording of Undo when adding player self.recordMove = True addingMoving = True if op.canUndo and not addingMoving: self.editor.addUnsavedEdit() def keyDown(self, evt): keyname = evt.dict.get('keyname', None) or self.editor.get_root().getKey(evt) if not self.recordMove: if not pygame.key.get_focused(): return if keyname == "Escape": self.recordMove = True if self.panel and self.panel.__class__ == PlayerPositionPanel: self.panel.key_down(evt) def keyUp(self, evt): pass def levelChanged(self): self.markerList.invalidate() @alertException def toolSelected(self): self.showPanel() self.movingPlayer = None @alertException def toolReselected(self): if self.panel: self.gotoPlayer()
class PlayerPositionTool(EditorTool): surfaceBuild = True toolIconName = "player" tooltipText = "Players" movingPlayer = None recordMove = True def reloadTextures(self): self.charTex = loadPNGTexture('char.png') @alertException def addPlayer(self): op = PlayerAddOperation(self) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() @alertException def removePlayer(self): player = self.panel.selectedPlayer if player != "[No players]": op = PlayerRemoveOperation(self, player) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() @alertException def movePlayer(self): if self.panel.selectedPlayer != "[No players]": self.movingPlayer = self.panel.selectedPlayer @alertException def movePlayerToCamera(self): player = self.panel.selectedPlayer if player != "[No players]": pos = self.editor.mainViewport.cameraPosition y = self.editor.mainViewport.yaw p = self.editor.mainViewport.pitch op = PlayerMoveOperation(self, pos, player, (y, p)) self.movingPlayer = None self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() def delete_skin(self, uuid): del self.playerTexture[uuid] self.playerTexture[uuid] = loadPNGTexture('char.png') @alertException def reloadSkins(self): #result = ask("This pulls skins from the online server, so this may take a while", ["Ok", "Cancel"]) #if result == "Ok": try: for player in self.editor.level.players: if player != "Player" and player != "[No players]" and player in self.playerTexture.keys(): del self.playerTexture[player] self.playerTexture[player] = loadPNGTexture(version_utils.getPlayerSkin(player, force=True, instance=self)) except: raise Exception("Could not connect to the skins server, please check your Internet connection and try again.") def gotoPlayerCamera(self): player = self.panel.selectedPlayer try: pos = self.editor.level.getPlayerPosition(player) y, p = self.editor.level.getPlayerOrientation(player) self.editor.gotoDimension(self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.yaw = y self.editor.mainViewport.pitch = p self.editor.mainViewport.stopMoving() self.editor.mainViewport.invalidate() except pymclevel.PlayerNotFound: pass def gotoPlayer(self): player = self.panel.selectedPlayer try: if self.editor.mainViewport.pitch < 0: self.editor.mainViewport.pitch = -self.editor.mainViewport.pitch self.editor.mainViewport.cameraVector = self.editor.mainViewport._cameraVector() cv = self.editor.mainViewport.cameraVector pos = self.editor.level.getPlayerPosition(player) pos = map(lambda p, c: p - c * 5, pos, cv) self.editor.gotoDimension(self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.stopMoving() except pymclevel.PlayerNotFound: pass def __init__(self, *args): EditorTool.__init__(self, *args) self.reloadTextures() textureVerticesHead = numpy.array( ( # Backside of Head 24, 16, # Bottom Left 24, 8, # Top Left 32, 8, # Top Right 32, 16, # Bottom Right # Front of Head 8, 16, 8, 8, 16, 8, 16, 16, # 24, 0, 16, 0, 16, 8, 24, 8, # 16, 0, 8, 0, 8, 8, 16, 8, # 8, 8, 0, 8, 0, 16, 8, 16, 16, 16, 24, 16, 24, 8, 16, 8, ), dtype='f4') textureVerticesHat = numpy.array( ( 56, 16, 56, 8, 64, 8, 64, 16, 48, 16, 48, 8, 40, 8, 40, 16, 56, 0, 48, 0, 48, 8, 56, 8, 48, 0, 40, 0, 40, 8, 48, 8, 40, 8, 32, 8, 32, 16, 40, 16, 48, 16, 56, 16, 56, 8, 48, 8, ), dtype='f4') textureVerticesHead.shape = (24, 2) textureVerticesHat.shape = (24, 2) textureVerticesHead *= 4 textureVerticesHead[:, 1] *= 2 textureVerticesHat *= 4 textureVerticesHat[:, 1] *= 2 self.texVerts = (textureVerticesHead, textureVerticesHat) self.playerPos = {} self.playerTexture = {} self.revPlayerPos = {} self.markerList = DisplayList() panel = None def showPanel(self): if not self.panel: self.panel = PlayerPositionPanel(self) self.panel.centery = (self.editor.mainViewport.height - self.editor.toolbar.height) / 2 + self.editor.subwidgets[0].height self.panel.left = self.editor.left self.editor.add(self.panel) def hidePanel(self): if self.panel and self.panel.parent: self.panel.parent.remove(self.panel) self.panel = None def drawToolReticle(self): if self.movingPlayer is None: return pos, direction = self.editor.blockFaceUnderCursor pos = (pos[0], pos[1] + 2, pos[2]) x, y, z = pos # x,y,z=map(lambda p,d: p+d, pos, direction) GL.glEnable(GL.GL_BLEND) GL.glColor(1.0, 1.0, 1.0, 0.5) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5, self.revPlayerPos[self.movingPlayer]) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5, self.revPlayerPos[self.movingPlayer]) drawTerrainCuttingWire(BoundingBox((x, y, z), (1, 1, 1))) drawTerrainCuttingWire(BoundingBox((x, y - 1, z), (1, 1, 1))) #drawTerrainCuttingWire( BoundingBox((x,y-2,z), (1,1,1)) ) GL.glDisable(GL.GL_DEPTH_TEST) markerLevel = None def drawToolMarkers(self): if self.markerLevel != self.editor.level: self.markerList.invalidate() self.markerLevel = self.editor.level self.markerList.call(self._drawToolMarkers) def _drawToolMarkers(self): GL.glColor(1.0, 1.0, 1.0, 0.5) GL.glEnable(GL.GL_DEPTH_TEST) GL.glMatrixMode(GL.GL_MODELVIEW) for player in self.editor.level.players: try: pos = self.editor.level.getPlayerPosition(player) yaw, pitch = self.editor.level.getPlayerOrientation(player) dim = self.editor.level.getPlayerDimension(player) if dim != self.editor.level.dimNo: continue self.playerPos[pos] = player self.revPlayerPos[player] = pos if player != "Player" and config.settings.downloadPlayerSkins.get(): self.playerTexture[player] = loadPNGTexture(version_utils.getPlayerSkin(player, force=False)) else: self.playerTexture[player] = self.charTex x, y, z = pos GL.glPushMatrix() GL.glTranslate(x, y, z) GL.glRotate(-yaw, 0, 1, 0) GL.glRotate(pitch, 1, 0, 0) GL.glColor(1, 1, 1, 1) self.drawCharacterHead(0, 0, 0, (x,y,z)) GL.glPopMatrix() # GL.glEnable(GL.GL_BLEND) drawTerrainCuttingWire(FloatBox((x - .5, y - .5, z - .5), (1, 1, 1)), c0=(0.3, 0.9, 0.7, 1.0), c1=(0, 0, 0, 0), ) #GL.glDisable(GL.GL_BLEND) except Exception, e: print repr(e) continue GL.glDisable(GL.GL_DEPTH_TEST)
class PlayerPositionTool(EditorTool): surfaceBuild = True toolIconName = "player" tooltipText = "Move Player" movingPlayer = None def reloadTextures(self): self.charTex = loadPNGTexture('char.png') @alertException def movePlayer(self): self.movingPlayer = self.panel.selectedPlayer @alertException def movePlayerToCamera(self): player = self.panel.selectedPlayer pos = self.editor.mainViewport.cameraPosition y = self.editor.mainViewport.yaw p = self.editor.mainViewport.pitch d = self.editor.level.dimNo op = PlayerMoveOperation(self, pos, player, (y, p)) self.movingPlayer = None op.perform() self.editor.addOperation(op) self.editor.addUnsavedEdit() def gotoPlayerCamera(self): player = self.panel.selectedPlayer try: pos = self.editor.level.getPlayerPosition(player) y, p = self.editor.level.getPlayerOrientation(player) self.editor.gotoDimension( self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.yaw = y self.editor.mainViewport.pitch = p self.editor.mainViewport.stopMoving() self.editor.mainViewport.invalidate() except pymclevel.PlayerNotFound: pass def gotoPlayer(self): player = self.panel.selectedPlayer try: if self.editor.mainViewport.pitch < 0: self.editor.mainViewport.pitch = -self.editor.mainViewport.pitch self.editor.mainViewport.cameraVector = self.editor.mainViewport._cameraVector( ) cv = self.editor.mainViewport.cameraVector pos = self.editor.level.getPlayerPosition(player) pos = map(lambda p, c: p - c * 5, pos, cv) self.editor.gotoDimension( self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.stopMoving() except pymclevel.PlayerNotFound: pass def __init__(self, *args): EditorTool.__init__(self, *args) self.reloadTextures() textureVertices = numpy.array(( 24, 16, 24, 8, 32, 8, 32, 16, 8, 16, 8, 8, 16, 8, 16, 16, 24, 0, 16, 0, 16, 8, 24, 8, 16, 0, 16, 8, 8, 8, 8, 0, 8, 8, 0, 8, 0, 16, 8, 16, 16, 16, 24, 16, 24, 8, 16, 8, ), dtype='f4') textureVertices.shape = (24, 2) textureVertices *= 4 textureVertices[:, 1] *= 2 self.texVerts = textureVertices self.markerList = DisplayList() panel = None def showPanel(self): if not self.panel: self.panel = PlayerPositionPanel(self) self.panel.left = self.editor.left self.panel.centery = self.editor.centery self.editor.add(self.panel) def hidePanel(self): if self.panel and self.panel.parent: self.panel.parent.remove(self.panel) self.panel = None def drawToolReticle(self): if self.movingPlayer is None: return pos, direction = self.editor.blockFaceUnderCursor pos = (pos[0], pos[1] + 2, pos[2]) x, y, z = pos # x,y,z=map(lambda p,d: p+d, pos, direction) GL.glEnable(GL.GL_BLEND) GL.glColor(1.0, 1.0, 1.0, 0.5) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5) drawTerrainCuttingWire(BoundingBox((x, y, z), (1, 1, 1))) drawTerrainCuttingWire(BoundingBox((x, y - 1, z), (1, 1, 1))) #drawTerrainCuttingWire( BoundingBox((x,y-2,z), (1,1,1)) ) GL.glDisable(GL.GL_DEPTH_TEST) markerLevel = None def drawToolMarkers(self): if self.markerLevel != self.editor.level: self.markerList.invalidate() self.markerLevel = self.editor.level self.markerList.call(self._drawToolMarkers) def _drawToolMarkers(self): GL.glColor(1.0, 1.0, 1.0, 0.5) GL.glEnable(GL.GL_DEPTH_TEST) GL.glMatrixMode(GL.GL_MODELVIEW) for player in self.editor.level.players: try: pos = self.editor.level.getPlayerPosition(player) yaw, pitch = self.editor.level.getPlayerOrientation(player) dim = self.editor.level.getPlayerDimension(player) if dim != self.editor.level.dimNo: continue x, y, z = pos GL.glPushMatrix() GL.glTranslate(x, y, z) GL.glRotate(-yaw, 0, 1, 0) GL.glRotate(pitch, 1, 0, 0) GL.glColor(1, 1, 1, 1) self.drawCharacterHead(0, 0, 0) GL.glPopMatrix() # GL.glEnable(GL.GL_BLEND) drawTerrainCuttingWire( FloatBox((x - .5, y - .5, z - .5), (1, 1, 1)), c0=(0.3, 0.9, 0.7, 1.0), c1=(0, 0, 0, 0), ) #GL.glDisable(GL.GL_BLEND) except Exception, e: print repr(e) continue GL.glDisable(GL.GL_DEPTH_TEST)
class ChunkTool(EditorTool): toolIconName = "chunk" tooltipText = "Chunk Control" @property def statusText(self): return _("Click and drag to select chunks. Hold {0} to deselect chunks. Hold {1} to select chunks.").format(_(config.keys.deselectChunks.get()), _(config.keys.selectChunks.get())) def toolEnabled(self): return isinstance(self.editor.level, pymclevel.ChunkedLevelMixin) _selectedChunks = None _displayList = None def drawToolMarkers(self): if self._displayList is None: self._displayList = DisplayList(self._drawToolMarkers) # print len(self._selectedChunks) if self._selectedChunks else None, "!=", len(self.editor.selectedChunks) if self._selectedChunks != self.editor.selectedChunks or True: # xxx self._selectedChunks = set(self.editor.selectedChunks) self._displayList.invalidate() self._displayList.call() def _drawToolMarkers(self): lines = ( ((-1, 0), (0, 0, 0, 1), []), ((1, 0), (1, 0, 1, 1), []), ((0, -1), (0, 0, 1, 0), []), ((0, 1), (0, 1, 1, 1), []), ) for ch in self._selectedChunks: cx, cz = ch for (dx, dz), points, positions in lines: n = (cx + dx, cz + dz) if n not in self._selectedChunks: positions.append([ch]) color = self.editor.selectionTool.selectionColor + (0.3, ) GL.glColor(*color) with gl.glEnable(GL.GL_BLEND): import renderer sizedChunks = renderer.chunkMarkers(self._selectedChunks) for size, chunks in sizedChunks.iteritems(): if not len(chunks): continue chunks = numpy.array(chunks, dtype='float32') chunkPosition = numpy.zeros(shape=(chunks.shape[0], 4, 3), dtype='float32') chunkPosition[..., (0, 2)] = numpy.array(((0, 0), (0, 1), (1, 1), (1, 0)), dtype='float32') chunkPosition[..., (0, 2)] *= size chunkPosition[..., (0, 2)] += chunks[:, newaxis, :] chunkPosition *= 16 chunkPosition[..., 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, chunkPosition.ravel()) # chunkPosition *= 8 GL.glDrawArrays(GL.GL_QUADS, 0, len(chunkPosition) * 4) for d, points, positions in lines: if 0 == len(positions): continue vertexArray = numpy.zeros((len(positions), 4, 3), dtype='float32') vertexArray[..., [0, 2]] = positions vertexArray.shape = len(positions), 2, 2, 3 vertexArray[..., 0, 0, 0] += points[0] vertexArray[..., 0, 0, 2] += points[1] vertexArray[..., 0, 1, 0] += points[2] vertexArray[..., 0, 1, 2] += points[3] vertexArray[..., 1, 0, 0] += points[2] vertexArray[..., 1, 0, 2] += points[3] vertexArray[..., 1, 1, 0] += points[0] vertexArray[..., 1, 1, 2] += points[1] vertexArray *= 16 vertexArray[..., 1, :, 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArray) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) with gl.glEnable(GL.GL_BLEND, GL.GL_DEPTH_TEST): GL.glDepthMask(False) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glDepthMask(True) @property def worldTooltipText(self): box = self.editor.selectionTool.selectionBoxInProgress() if box: box = box.chunkBox(self.editor.level) l, w = box.length // 16, box.width // 16 return _("%s x %s chunks") % (l, w) def toolSelected(self): self.editor.selectionToChunks() self.panel = ChunkToolPanel(self) self.panel.centery = self.editor.centery self.panel.left = 10 self.editor.add(self.panel) def toolDeselected(self): self.editor.chunksToSelection() def cancel(self): self.editor.remove(self.panel) def selectedChunks(self): return self.editor.selectedChunks @alertException def destroyChunks(self, chunks=None): if "No" == ask("Really delete these chunks? This cannot be undone.", ("Yes", "No")): return if chunks is None: chunks = self.selectedChunks() chunks = list(chunks) def _destroyChunks(): i = 0 chunkCount = len(chunks) for cx, cz in chunks: i += 1 yield (i, chunkCount) if self.editor.level.containsChunk(cx, cz): try: self.editor.level.deleteChunk(cx, cz) except Exception, e: print "Error during chunk delete: ", e with setWindowCaption("DELETING - "): showProgress("Deleting chunks...", _destroyChunks()) self.editor.renderer.invalidateChunkMarkers() self.editor.renderer.discardAllChunks()
class ChunkTool(EditorTool): toolIconName = "chunk" tooltipText = "Chunk Control" @property def statusText(self): return _( "Click and drag to select chunks. Hold {0} to deselect chunks. Hold {1} to select chunks." ).format(_(config.keys.deselectChunks.get()), _(config.keys.selectChunks.get())) def toolEnabled(self): return isinstance(self.editor.level, pymclevel.ChunkedLevelMixin) _selectedChunks = None _displayList = None def drawToolMarkers(self): if self._displayList is None: self._displayList = DisplayList(self._drawToolMarkers) # print len(self._selectedChunks) if self._selectedChunks else None, "!=", len(self.editor.selectedChunks) if self._selectedChunks != self.editor.selectedChunks or True: # xxx # TODO Pod self._selectedChunks = set(self.editor.selectedChunks) self._displayList.invalidate() self._displayList.call() def _drawToolMarkers(self): lines = ( ((-1, 0), (0, 0, 0, 1), []), ((1, 0), (1, 0, 1, 1), []), ((0, -1), (0, 0, 1, 0), []), ((0, 1), (0, 1, 1, 1), []), ) for ch in self._selectedChunks: cx, cz = ch for (dx, dz), points, positions in lines: n = (cx + dx, cz + dz) if n not in self._selectedChunks: positions.append([ch]) color = self.editor.selectionTool.selectionColor + (0.3, ) GL.glColor(*color) with gl.glEnable(GL.GL_BLEND): #import renderer sizedChunks = renderer.chunkMarkers(self._selectedChunks) for size, chunks in sizedChunks.iteritems(): if not len(chunks): continue chunks = numpy.array(chunks, dtype='float32') chunkPosition = numpy.zeros(shape=(chunks.shape[0], 4, 3), dtype='float32') chunkPosition[..., (0, 2)] = numpy.array( ((0, 0), (0, 1), (1, 1), (1, 0)), dtype='float32') chunkPosition[..., (0, 2)] *= size chunkPosition[..., (0, 2)] += chunks[:, newaxis, :] chunkPosition *= 16 chunkPosition[..., 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, chunkPosition.ravel()) # chunkPosition *= 8 GL.glDrawArrays(GL.GL_QUADS, 0, len(chunkPosition) * 4) for d, points, positions in lines: if 0 == len(positions): continue vertexArray = numpy.zeros((len(positions), 4, 3), dtype='float32') vertexArray[..., [0, 2]] = positions vertexArray.shape = len(positions), 2, 2, 3 vertexArray[..., 0, 0, 0] += points[0] vertexArray[..., 0, 0, 2] += points[1] vertexArray[..., 0, 1, 0] += points[2] vertexArray[..., 0, 1, 2] += points[3] vertexArray[..., 1, 0, 0] += points[2] vertexArray[..., 1, 0, 2] += points[3] vertexArray[..., 1, 1, 0] += points[0] vertexArray[..., 1, 1, 2] += points[1] vertexArray *= 16 vertexArray[..., 1, :, 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArray) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) with gl.glEnable(GL.GL_BLEND, GL.GL_DEPTH_TEST): GL.glDepthMask(False) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glDepthMask(True) @property def worldTooltipText(self): box = self.editor.selectionTool.selectionBoxInProgress() if box: box = box.chunkBox(self.editor.level) l, w = box.length // 16, box.width // 16 return _("%s x %s chunks") % (l, w) else: if config.settings.viewMode.get() == "Chunk": point, face = self.editor.chunkViewport.blockFaceUnderCursor else: point, face = self.editor.mainViewport.blockFaceUnderCursor if point: return "Chunk ({}, {})".format(point[0] // 16, point[2] // 16) def toolSelected(self): self.editor.selectionToChunks() self.panel = ChunkToolPanel(self) self.panel.centery = self.editor.centery self.panel.left = 10 self.editor.add(self.panel) def toolDeselected(self): self.editor.chunksToSelection() def cancel(self): self.editor.remove(self.panel) def selectedChunks(self): return self.editor.selectedChunks @alertException def destroyChunks(self, chunks=None): if "No" == ask("Really delete these chunks? This cannot be undone.", ("Yes", "No")): return if chunks is None: chunks = self.selectedChunks() chunks = list(chunks) def _destroyChunks(): i = 0 chunkCount = len(chunks) for cx, cz in chunks: i += 1 yield (i, chunkCount) if self.editor.level.containsChunk(cx, cz): try: self.editor.level.deleteChunk(cx, cz) except Exception as e: print "Error during chunk delete: ", e with setWindowCaption("DELETING - "): showProgress("Deleting chunks...", _destroyChunks()) self.editor.renderer.invalidateChunkMarkers() self.editor.renderer.discardAllChunks() # self.editor.addUnsavedEdit() @alertException def pruneChunks(self): if "No" == ask( "Save these chunks and remove the rest? This cannot be undone.", ("Yes", "No")): return self.editor.saveFile() def _pruneChunks(): maxChunks = self.editor.level.chunkCount selectedChunks = self.selectedChunks() for i, cPos in enumerate(list(self.editor.level.allChunks)): if cPos not in selectedChunks: try: self.editor.level.deleteChunk(*cPos) except Exception as e: print "Error during chunk delete: ", e yield i, maxChunks with setWindowCaption("PRUNING - "): showProgress("Pruning chunks...", _pruneChunks()) self.editor.renderer.invalidateChunkMarkers() self.editor.discardAllChunks() # self.editor.addUnsavedEdit() @alertException def relightChunks(self): def _relightChunks(): for i in self.editor.level.generateLightsIter( self.selectedChunks()): yield i with setWindowCaption("RELIGHTING - "): showProgress(_("Lighting {0} chunks...").format( len(self.selectedChunks())), _relightChunks(), cancel=True) self.editor.invalidateChunks(self.selectedChunks()) self.editor.addUnsavedEdit() @alertException def createChunks(self): panel = GeneratorPanel() col = [panel] label = Label( "Create chunks using the settings above? This cannot be undone.") col.append(Row([Label("")])) col.append(label) col = Column(col) if Dialog(client=col, responses=["OK", "Cancel"]).present() == "Cancel": return chunks = self.selectedChunks() createChunks = panel.generate(self.editor.level, chunks) try: with setWindowCaption("CREATING - "): showProgress("Creating {0} chunks...".format(len(chunks)), createChunks, cancel=True) except Exception as e: traceback.print_exc() alert(_("Failed to start the chunk generator. {0!r}").format(e)) finally: self.editor.renderer.invalidateChunkMarkers() self.editor.renderer.loadNearbyChunks() @alertException def repopChunks(self): for cpos in self.selectedChunks(): try: chunk = self.editor.level.getChunk(*cpos) chunk.TerrainPopulated = False except pymclevel.ChunkNotPresent: continue self.editor.renderer.invalidateChunks(self.selectedChunks(), layers=["TerrainPopulated"]) @alertException def dontRepopChunks(self): for cpos in self.selectedChunks(): try: chunk = self.editor.level.getChunk(*cpos) chunk.TerrainPopulated = True except pymclevel.ChunkNotPresent: continue self.editor.renderer.invalidateChunks(self.selectedChunks(), layers=["TerrainPopulated"]) def mouseDown(self, *args): return self.editor.selectionTool.mouseDown(*args) def mouseUp(self, evt, *args): self.editor.selectionTool.mouseUp(evt, *args) def keyDown(self, evt): self.editor.selectionTool.keyDown(evt) def keyUp(self, evt): self.editor.selectionTool.keyUp(evt)
class BlockView(GLOrtho): def __init__(self, materials, blockInfo=None): GLOrtho.__init__(self) self.list = DisplayList(self._gl_draw) self.blockInfo = blockInfo or materials.Air self.materials = materials listBlockInfo = None def gl_draw(self): if self.listBlockInfo != self.blockInfo: self.list.invalidate() self.listBlockInfo = self.blockInfo self.list.call() def _gl_draw(self): blockInfo = self.blockInfo if blockInfo.ID is 0: return GL.glColor(1.0, 1.0, 1.0, 1.0) GL.glEnable(GL.GL_TEXTURE_2D) GL.glEnable(GL.GL_ALPHA_TEST) self.materials.terrainTexture.bind() pixelScale = 0.5 if self.materials.name in ("Pocket", "Alpha") else 1.0 texSize = 16 * pixelScale GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY) GL.glVertexPointer( 2, GL.GL_FLOAT, 0, array([ -1, -1, -1, 1, 1, 1, 1, -1, ], dtype='float32')) # hack to get end rod to render properly # we really should use json models? if blockInfo.ID == 198: texOrigin = array([17 * 16, 20 * 16]) else: texOrigin = array(self.materials.blockTextures[blockInfo.ID, blockInfo.blockData, 0]) texOrigin = texOrigin.astype(float) * pixelScale GL.glTexCoordPointer( 2, GL.GL_FLOAT, 0, array([ texOrigin[0], texOrigin[1] + texSize, texOrigin[0], texOrigin[1], texOrigin[0] + texSize, texOrigin[1], texOrigin[0] + texSize, texOrigin[1] + texSize ], dtype='float32')) GL.glDrawArrays(GL.GL_QUADS, 0, 4) GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY) GL.glDisable(GL.GL_ALPHA_TEST) GL.glDisable(GL.GL_TEXTURE_2D) @property def tooltipText(self): #&# Prototype for blocks/items names #return str(self.blockInfo.name) return mclangres.translate(self.blockInfo.name)
class ChunkTool(EditorTool): toolIconName = "chunk" tooltipText = "Chunk Control" @property def statusText(self): return _("Click and drag to select chunks. Hold {0} to deselect chunks. Hold {1} to select chunks.").format(_(config.keys.deselectChunks.get()), _(config.keys.selectChunks.get())) def toolEnabled(self): return isinstance(self.editor.level, pymclevel.ChunkedLevelMixin) _selectedChunks = None _displayList = None def drawToolMarkers(self): if self._displayList is None: self._displayList = DisplayList(self._drawToolMarkers) # print len(self._selectedChunks) if self._selectedChunks else None, "!=", len(self.editor.selectedChunks) if self._selectedChunks != self.editor.selectedChunks or True: # xxx # TODO Pod self._selectedChunks = set(self.editor.selectedChunks) self._displayList.invalidate() self._displayList.call() def _drawToolMarkers(self): lines = ( ((-1, 0), (0, 0, 0, 1), []), ((1, 0), (1, 0, 1, 1), []), ((0, -1), (0, 0, 1, 0), []), ((0, 1), (0, 1, 1, 1), []), ) for ch in self._selectedChunks: cx, cz = ch for (dx, dz), points, positions in lines: n = (cx + dx, cz + dz) if n not in self._selectedChunks: positions.append([ch]) color = self.editor.selectionTool.selectionColor + (0.3, ) GL.glColor(*color) with gl.glEnable(GL.GL_BLEND): #import renderer sizedChunks = renderer.chunkMarkers(self._selectedChunks) for size, chunks in sizedChunks.iteritems(): if not len(chunks): continue chunks = numpy.array(chunks, dtype='float32') chunkPosition = numpy.zeros(shape=(chunks.shape[0], 4, 3), dtype='float32') chunkPosition[..., (0, 2)] = numpy.array(((0, 0), (0, 1), (1, 1), (1, 0)), dtype='float32') chunkPosition[..., (0, 2)] *= size chunkPosition[..., (0, 2)] += chunks[:, newaxis, :] chunkPosition *= 16 chunkPosition[..., 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, chunkPosition.ravel()) # chunkPosition *= 8 GL.glDrawArrays(GL.GL_QUADS, 0, len(chunkPosition) * 4) for d, points, positions in lines: if 0 == len(positions): continue vertexArray = numpy.zeros((len(positions), 4, 3), dtype='float32') vertexArray[..., [0, 2]] = positions vertexArray.shape = len(positions), 2, 2, 3 vertexArray[..., 0, 0, 0] += points[0] vertexArray[..., 0, 0, 2] += points[1] vertexArray[..., 0, 1, 0] += points[2] vertexArray[..., 0, 1, 2] += points[3] vertexArray[..., 1, 0, 0] += points[2] vertexArray[..., 1, 0, 2] += points[3] vertexArray[..., 1, 1, 0] += points[0] vertexArray[..., 1, 1, 2] += points[1] vertexArray *= 16 vertexArray[..., 1, :, 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArray) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) with gl.glEnable(GL.GL_BLEND, GL.GL_DEPTH_TEST): GL.glDepthMask(False) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glDepthMask(True) @property def worldTooltipText(self): box = self.editor.selectionTool.selectionBoxInProgress() if box: box = box.chunkBox(self.editor.level) l, w = box.length // 16, box.width // 16 return _("%s x %s chunks") % (l, w) else: if config.settings.viewMode.get() == "Chunk": point, face = self.editor.chunkViewport.blockFaceUnderCursor else: point, face = self.editor.mainViewport.blockFaceUnderCursor if point: return "Chunk ({}, {})".format(point[0] // 16, point[2] // 16) def toolSelected(self): self.editor.selectionToChunks() self.panel = ChunkToolPanel(self) self.panel.centery = self.editor.centery self.panel.left = 10 self.editor.add(self.panel) def toolDeselected(self): self.editor.chunksToSelection() def cancel(self): self.editor.remove(self.panel) def selectedChunks(self): return self.editor.selectedChunks @alertException def destroyChunks(self, chunks=None): if "No" == ask("Really delete these chunks? This cannot be undone.", ("Yes", "No")): return if chunks is None: chunks = self.selectedChunks() chunks = list(chunks) def _destroyChunks(): i = 0 chunkCount = len(chunks) for cx, cz in chunks: i += 1 yield (i, chunkCount) if self.editor.level.containsChunk(cx, cz): try: self.editor.level.deleteChunk(cx, cz) except Exception as e: print "Error during chunk delete: ", e with setWindowCaption("DELETING - "): showProgress("Deleting chunks...", _destroyChunks()) self.editor.renderer.invalidateChunkMarkers() self.editor.renderer.discardAllChunks() # self.editor.addUnsavedEdit() @alertException def pruneChunks(self): if "No" == ask("Save these chunks and remove the rest? This cannot be undone.", ("Yes", "No")): return self.editor.saveFile() def _pruneChunks(): maxChunks = self.editor.level.chunkCount selectedChunks = self.selectedChunks() for i, cPos in enumerate(list(self.editor.level.allChunks)): if cPos not in selectedChunks: try: self.editor.level.deleteChunk(*cPos) except Exception as e: print "Error during chunk delete: ", e yield i, maxChunks with setWindowCaption("PRUNING - "): showProgress("Pruning chunks...", _pruneChunks()) self.editor.renderer.invalidateChunkMarkers() self.editor.discardAllChunks() # self.editor.addUnsavedEdit() @alertException def relightChunks(self): def _relightChunks(): for i in self.editor.level.generateLightsIter(self.selectedChunks()): yield i with setWindowCaption("RELIGHTING - "): showProgress(_("Lighting {0} chunks...").format(len(self.selectedChunks())), _relightChunks(), cancel=True) self.editor.invalidateChunks(self.selectedChunks()) self.editor.addUnsavedEdit() @alertException def createChunks(self): panel = GeneratorPanel() col = [panel] label = Label("Create chunks using the settings above? This cannot be undone.") col.append(Row([Label("")])) col.append(label) col = Column(col) if Dialog(client=col, responses=["OK", "Cancel"]).present() == "Cancel": return chunks = self.selectedChunks() createChunks = panel.generate(self.editor.level, chunks) try: with setWindowCaption("CREATING - "): showProgress("Creating {0} chunks...".format(len(chunks)), createChunks, cancel=True) except Exception as e: traceback.print_exc() alert(_("Failed to start the chunk generator. {0!r}").format(e)) finally: self.editor.renderer.invalidateChunkMarkers() self.editor.renderer.loadNearbyChunks() @alertException def repopChunks(self): for cpos in self.selectedChunks(): try: chunk = self.editor.level.getChunk(*cpos) chunk.TerrainPopulated = False except pymclevel.ChunkNotPresent: continue self.editor.renderer.invalidateChunks(self.selectedChunks(), layers=["TerrainPopulated"]) @alertException def dontRepopChunks(self): for cpos in self.selectedChunks(): try: chunk = self.editor.level.getChunk(*cpos) chunk.TerrainPopulated = True except pymclevel.ChunkNotPresent: continue self.editor.renderer.invalidateChunks(self.selectedChunks(), layers=["TerrainPopulated"]) def mouseDown(self, *args): return self.editor.selectionTool.mouseDown(*args) def mouseUp(self, evt, *args): self.editor.selectionTool.mouseUp(evt, *args) def keyDown(self, evt): self.editor.selectionTool.keyDown(evt) def keyUp(self, evt): self.editor.selectionTool.keyUp(evt)
def __init__(self, *args): EditorTool.__init__(self, *args) self.reloadTextures() textureVertices = numpy.array(( 24, 16, 24, 8, 32, 8, 32, 16, 8, 16, 8, 8, 16, 8, 16, 16, 24, 0, 16, 0, 16, 8, 24, 8, 16, 0, 16, 8, 8, 8, 8, 0, 8, 8, 0, 8, 0, 16, 8, 16, 16, 16, 24, 16, 24, 8, 16, 8, ), dtype='f4') textureVertices.shape = (24, 2) textureVertices *= 4 textureVertices[:, 1] *= 2 self.texVerts = textureVertices self.markerList = DisplayList()
def __init__(self, *args): EditorTool.__init__(self, *args) self.reloadTextures() textureVerticesHead = numpy.array( ( # Backside of Head 24, 16, # Bottom Left 24, 8, # Top Left 32, 8, # Top Right 32, 16, # Bottom Right # Front of Head 8, 16, 8, 8, 16, 8, 16, 16, # 24, 0, 16, 0, 16, 8, 24, 8, # 16, 0, 8, 0, 8, 8, 16, 8, # 8, 8, 0, 8, 0, 16, 8, 16, 16, 16, 24, 16, 24, 8, 16, 8, ), dtype='f4') textureVerticesHat = numpy.array( ( 56, 16, 56, 8, 64, 8, 64, 16, 48, 16, 48, 8, 40, 8, 40, 16, 56, 0, 48, 0, 48, 8, 56, 8, 48, 0, 40, 0, 40, 8, 48, 8, 40, 8, 32, 8, 32, 16, 40, 16, 48, 16, 56, 16, 56, 8, 48, 8, ), dtype='f4') textureVerticesHead.shape = (24, 2) textureVerticesHat.shape = (24, 2) textureVerticesHead *= 4 textureVerticesHead[:, 1] *= 2 textureVerticesHat *= 4 textureVerticesHat[:, 1] *= 2 self.texVerts = (textureVerticesHead, textureVerticesHat) self.playerPos = {} self.playerTexture = {} self.revPlayerPos = {} self.markerList = DisplayList()
class PlayerPositionTool(EditorTool): surfaceBuild = True toolIconName = "player" tooltipText = "Move Player" movingPlayer = None def reloadTextures(self): self.charTex = loadPNGTexture('char.png') @alertException def movePlayer(self): self.movingPlayer = self.panel.selectedPlayer @alertException def movePlayerToCamera(self): player = self.panel.selectedPlayer pos = self.editor.mainViewport.cameraPosition y = self.editor.mainViewport.yaw p = self.editor.mainViewport.pitch d = self.editor.level.dimNo op = PlayerMoveOperation(self, pos, player, (y, p)) self.movingPlayer = None op.perform() self.editor.addOperation(op) self.editor.addUnsavedEdit() def gotoPlayerCamera(self): player = self.panel.selectedPlayer try: pos = self.editor.level.getPlayerPosition(player) y, p = self.editor.level.getPlayerOrientation(player) self.editor.gotoDimension(self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.yaw = y self.editor.mainViewport.pitch = p self.editor.mainViewport.stopMoving() self.editor.mainViewport.invalidate() except pymclevel.PlayerNotFound: pass def gotoPlayer(self): player = self.panel.selectedPlayer try: if self.editor.mainViewport.pitch < 0: self.editor.mainViewport.pitch = -self.editor.mainViewport.pitch self.editor.mainViewport.cameraVector = self.editor.mainViewport._cameraVector() cv = self.editor.mainViewport.cameraVector pos = self.editor.level.getPlayerPosition(player) pos = map(lambda p, c: p - c * 5, pos, cv) self.editor.gotoDimension(self.editor.level.getPlayerDimension(player)) self.editor.mainViewport.cameraPosition = pos self.editor.mainViewport.stopMoving() except pymclevel.PlayerNotFound: pass def __init__(self, *args): EditorTool.__init__(self, *args) self.reloadTextures() textureVertices = numpy.array( ( 24, 16, 24, 8, 32, 8, 32, 16, 8, 16, 8, 8, 16, 8, 16, 16, 24, 0, 16, 0, 16, 8, 24, 8, 16, 0, 16, 8, 8, 8, 8, 0, 8, 8, 0, 8, 0, 16, 8, 16, 16, 16, 24, 16, 24, 8, 16, 8, ), dtype='f4') textureVertices.shape = (24, 2) textureVertices *= 4 textureVertices[:, 1] *= 2 self.texVerts = textureVertices self.markerList = DisplayList() panel = None def showPanel(self): if not self.panel: self.panel = PlayerPositionPanel(self) self.panel.left = self.editor.left self.panel.centery = self.editor.centery self.editor.add(self.panel) def hidePanel(self): if self.panel and self.panel.parent: self.panel.parent.remove(self.panel) self.panel = None def drawToolReticle(self): if self.movingPlayer is None: return pos, direction = self.editor.blockFaceUnderCursor pos = (pos[0], pos[1] + 2, pos[2]) x, y, z = pos #x,y,z=map(lambda p,d: p+d, pos, direction) GL.glEnable(GL.GL_BLEND) GL.glColor(1.0, 1.0, 1.0, 0.5) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) self.drawCharacterHead(x + 0.5, y + 0.75, z + 0.5) drawTerrainCuttingWire(BoundingBox((x, y, z), (1, 1, 1))) drawTerrainCuttingWire(BoundingBox((x, y - 1, z), (1, 1, 1))) #drawTerrainCuttingWire( BoundingBox((x,y-2,z), (1,1,1)) ) GL.glDisable(GL.GL_DEPTH_TEST) markerLevel = None def drawToolMarkers(self): if self.markerLevel != self.editor.level: self.markerList.invalidate() self.markerLevel = self.editor.level self.markerList.call(self._drawToolMarkers) def _drawToolMarkers(self): GL.glColor(1.0, 1.0, 1.0, 0.5) GL.glEnable(GL.GL_DEPTH_TEST) GL.glMatrixMode(GL.GL_MODELVIEW) for player in self.editor.level.players: try: pos = self.editor.level.getPlayerPosition(player) yaw, pitch = self.editor.level.getPlayerOrientation(player) dim = self.editor.level.getPlayerDimension(player) if dim != self.editor.level.dimNo: continue x, y, z = pos GL.glPushMatrix() GL.glTranslate(x, y, z) GL.glRotate(-yaw, 0, 1, 0) GL.glRotate(pitch, 1, 0, 0) GL.glColor(1, 1, 1, 1) self.drawCharacterHead(0, 0, 0) GL.glPopMatrix() #GL.glEnable(GL.GL_BLEND) drawTerrainCuttingWire(FloatBox((x - .5, y - .5, z - .5), (1, 1, 1)), c0=(0.3, 0.9, 0.7, 1.0), c1=(0, 0, 0, 0), ) #GL.glDisable(GL.GL_BLEND) except Exception, e: print repr(e) continue GL.glDisable(GL.GL_DEPTH_TEST)