本文整理汇总了Python中glutils.DisplayList.invalidate方法的典型用法代码示例。如果您正苦于以下问题:Python DisplayList.invalidate方法的具体用法?Python DisplayList.invalidate怎么用?Python DisplayList.invalidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glutils.DisplayList
的用法示例。
在下文中一共展示了DisplayList.invalidate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BlockView
# 需要导入模块: from glutils import DisplayList [as 别名]
# 或者: from glutils.DisplayList import invalidate [as 别名]
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)
示例2: BlockView
# 需要导入模块: from glutils import DisplayList [as 别名]
# 或者: from glutils.DisplayList import invalidate [as 别名]
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)
示例3: PlayerPositionTool
# 需要导入模块: from glutils import DisplayList [as 别名]
# 或者: from glutils.DisplayList import invalidate [as 别名]
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()
#.........这里部分代码省略.........
示例4: PlayerPositionTool
# 需要导入模块: from glutils import DisplayList [as 别名]
# 或者: from glutils.DisplayList import invalidate [as 别名]
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)
#.........这里部分代码省略.........
示例5: ChunkTool
# 需要导入模块: from glutils import DisplayList [as 别名]
# 或者: from glutils.DisplayList import invalidate [as 别名]
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)
#.........这里部分代码省略.........
示例6: ChunkTool
# 需要导入模块: from glutils import DisplayList [as 别名]
# 或者: from glutils.DisplayList import invalidate [as 别名]
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:
#.........这里部分代码省略.........
示例7: PlayerPositionTool
# 需要导入模块: from glutils import DisplayList [as 别名]
# 或者: from glutils.DisplayList import invalidate [as 别名]
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)
#.........这里部分代码省略.........