def makeChunkVertices(self, chunk, _limitBox): neighbors = self.chunkUpdate.neighboringChunks def getpop(face): ch = neighbors.get(face) if ch: return getattr(ch, "TerrainPopulated", True) else: return True pop = getattr(chunk, "TerrainPopulated", True) yield if pop: return visibleFaces = [ getpop(faces.FaceXIncreasing), getpop(faces.FaceXDecreasing), True, True, getpop(faces.FaceZIncreasing), getpop(faces.FaceZDecreasing), ] visibleFaces = numpy.array(visibleFaces, dtype='bool') verts = self.vertexTemplate[visibleFaces] buffer = VertexArrayBuffer(0, textures=False, lights=False) buffer.buffer = verts self.vertexArrays.append(buffer) yield
def _computeVertices(self, positions, colors, offset=False, chunkPosition=(0, 0)): cx, cz = chunkPosition x = cx << 4 z = cz << 4 bounds = self.chunkUpdate.updateTask.worldScene.bounds if bounds: positions = [p for p in positions if p in bounds] vertexBuffer = VertexArrayBuffer(len(positions) * 6, lights=False) vertexBuffer.buffer.shape = (len(positions), 6) + vertexBuffer.buffer.shape[-2:] if len(positions): positions = numpy.array(positions, dtype=float) positions[:, (0, 2)] -= (x, z) if offset: positions -= 0.5 vertexBuffer.rgba[:] = colors vertexBuffer.vertex[:] = positions[:, numpy.newaxis, numpy.newaxis, :] vertexBuffer.vertex[:] += standardCubeTemplates[_XYZ] vertexBuffer.buffer.shape = (len(positions) * 6, ) + vertexBuffer.buffer.shape[-2:] return vertexBuffer
def LineStripNode(points, rgba): vertexArray = VertexArrayBuffer(len(points), GL.GL_LINE_STRIP, False, False) vertexArray.vertex[:] = points vertexArray.rgba[:] = rgba node = VertexNode([vertexArray]) return node
def makeChunkVertices(self, chunk, _limitBox): neighbors = self.chunkUpdate.neighboringChunks def getpop(face): ch = neighbors.get(face) if ch: return getattr(ch, "TerrainPopulated", True) else: return True pop = getattr(chunk, "TerrainPopulated", True) yield if pop: return visibleFaces = [ getpop(faces.FaceXIncreasing), getpop(faces.FaceXDecreasing), True, True, getpop(faces.FaceZIncreasing), getpop(faces.FaceZDecreasing), ] visibleFaces = numpy.array(visibleFaces, dtype='bool') verts = self.vertexTemplate[visibleFaces] buffer = VertexArrayBuffer(0, textures=False, lights=False) buffer.buffer = verts self.sceneNode = scenegraph.VertexNode(buffer) yield
def renderSceneNodes(self): vertexArray = VertexArrayBuffer(2, GL.GL_LINES, False, False) vertexArray.vertex[:] = [self.p1, self.p2] vertexArray.vertex[:] += 0.5 # draw using box centers vertexArray.rgba[:] = self.glColor node = VertexNode([vertexArray]) # xxx LineNode return [node]
def renderSceneNodes(self): vertexArray = VertexArrayBuffer(2, GL.GL_LINES, False, False) vertexArray.vertex[:] = [self.p1, self.p2] vertexArray.vertex[:] += 0.5 # draw using box centers vertexArray.rgba[:] = 255, 64, 64, 128 node = VertexNode([vertexArray]) # xxx LineNode return [node]
def makeChunkVertices(self, chunk, _limitBox): positions = chunk.sectionPositions() buffer = VertexArrayBuffer((len(positions), 6, 4), GL.GL_LINE_STRIP, textures=False, lights=False) for i, cy in enumerate(positions): buffer.buffer[i, :] = self.vertexTemplate buffer.vertex[i, ..., 1] += cy * 16 self.sceneNode = VertexNode(buffer) yield
def renderSceneNodes(self, symbol_list): points = [] for cell in symbol_list: if not isinstance(cell, Cell): continue points.append(cell.origin) vertexArray = VertexArrayBuffer(len(points), GL.GL_LINE_STRIP, False, False) vertexArray.vertex[:] = points vertexArray.vertex[:] += 0.5 # draw using box centers vertexArray.rgba[:] = [(255, 0, 255, 255)] node = VertexNode([vertexArray]) # xxx LineNode return [node]
def _computeVertices(self, positions, colors, offset=False, chunkPosition=(0, 0)): cx, cz = chunkPosition x = cx << 4 z = cz << 4 bounds = self.chunkUpdate.updateTask.worldScene.bounds if bounds: positions = [p for p in positions if p in bounds] vertexBuffer = VertexArrayBuffer(len(positions) * 6, lights=False, textures=False) vertexBuffer.buffer.shape = (len(positions), 6) + vertexBuffer.buffer.shape[-2:] if len(positions): positions = numpy.array(positions, dtype=float) positions[:, (0, 2)] -= (x, z) if offset: positions -= 0.5 vertexBuffer.rgba[:] = colors vertexBuffer.vertex[:] = positions[:, numpy.newaxis, numpy.newaxis, :] vertexBuffer.vertex[:] += standardCubeTemplates[_XYZ] vertexBuffer.buffer.shape = (len(positions) * 6, ) + vertexBuffer.buffer.shape[-2:] return vertexBuffer
def buildSection(self, sectionMask, cy): vertexArrays = [] for (face, exposedFaceMask) in enumerate(self.exposedBlockMasks(sectionMask)): blockIndices = sectionMask[1:-1, 1:-1, 1:-1] & exposedFaceMask vertexBuffer = VertexArrayBuffer.fromIndices(face, blockIndices, False, False) if not len(vertexBuffer.vertex): continue vertexBuffer.rgb[:] = faceShades[face] vertexBuffer.alpha[:] = 0x77 vertexBuffer.vertex[..., 1] += cy << 4 vertexArrays.append(vertexBuffer) return vertexArrays
def makeChunkVertices(self, chunk, limitBox): """ :param chunk: :type chunk: WorldEditorChunk :param limitBox: :return: :raise: """ dim = chunk.dimension cx, cz = chunk.chunkPosition if not hasattr(chunk, 'HeightMap') or chunk.HeightMap is None: return heightMap = chunk.HeightMap chunkWidth = chunkLength = 16 chunkHeight = chunk.dimension.bounds.height z, x = list(numpy.indices((chunkLength, chunkWidth))) y = (heightMap - 1)[:chunkLength, :chunkWidth] numpy.clip(y, 0, chunkHeight - 1, y) nonZeroHeights = y > 0 heights = y.reshape((16, 16)) x = x[nonZeroHeights] if not len(x): return z = z[nonZeroHeights] y = y[nonZeroHeights] # Get the top block in each column blockResult = dim.getBlocks(x + (cx * 16), y, z + (cz * 16), return_Data=True) topBlocks = blockResult.Blocks topBlockData = blockResult.Data # Get the block above each column top. We'll recolor the top face of the column if a flower or another # transparent block is on top. aboveY = y + 1 numpy.clip(aboveY, 0, chunkHeight - 1, aboveY) blocksAbove = dim.getBlocks(x + (cx * 16), aboveY, z + (cz * 16)).Blocks flatcolors = dim.blocktypes.mapColor[topBlocks, topBlockData][:, numpy.newaxis, :] yield vertexBuffer = VertexArrayBuffer(len(x), textures=False, lights=False) vertexBuffer.vertex[..., 0] = x[:, numpy.newaxis] vertexBuffer.vertex[..., 1] = y[:, numpy.newaxis] vertexBuffer.vertex[..., 2] = z[:, numpy.newaxis] va0 = vertexBuffer.copy() va0.vertex[:] += standardCubeTemplates[faces.FaceYIncreasing, ..., :3] overmask = blocksAbove > 0 colors = dim.blocktypes.mapColor[:, 0][blocksAbove[overmask]][:, numpy.newaxis] flatcolors[overmask] = colors if self.detailLevel == 2: heightfactor = (y / float(chunk.dimension.bounds.height)) * 0.33 + 0.66 flatcolors[..., :3] *= heightfactor[:, numpy.newaxis, numpy.newaxis] # xxx implicit cast from byte to float and back va0.rgb[:] = flatcolors yield if self.detailLevel == 2: self.sceneNode = scenegraph.VertexNode(va0) return # Calculate how deep each column needs to go to be flush with the adjacent column; # If columns extend all the way down, performance suffers due to fill rate. depths = numpy.zeros((chunkWidth, chunkLength), dtype='uint16') depths[1:-1, 1:-1] = reduce(numpy.minimum, (heights[1:-1, :-2], heights[1:-1, 2:], heights[:-2, 1:-1], heights[2:, 1:-1])) depths = depths[nonZeroHeights] yield va1 = vertexBuffer.copy() va1.vertex[..., :3] += standardCubeTemplates[faces.FaceXIncreasing, ..., :3] va1.vertex[:, 0, 1] = depths va1.vertex[:, 0, 1] = depths # stretch to floor va1.vertex[:, (2, 3), 1] -= 0.5 # drop down to prevent intersection pixels flatcolors *= 0.8 va1.rgb[:] = flatcolors grassmask = topBlocks == 2 # color grass sides with dirt's color va1.rgb[grassmask] = dim.blocktypes.mapColor[:, 0][[3]][:, numpy.newaxis] va2 = va1.copy() va1.vertex[:, (1, 2), 0] -= 1.0 # turn diagonally va2.vertex[:, (0, 3), 0] -= 1.0 # turn diagonally nodes = [scenegraph.VertexNode(v) for v in (va1, va2, va0)] self.sceneNode = scenegraph.Node() for node in nodes: self.sceneNode.addChild(node)
def makeChunkVertices(self, chunk, limitBox): """ :param chunk: :type chunk: WorldEditorChunk :param limitBox: :return: :raise: """ dim = chunk.dimension cx, cz = chunk.chunkPosition if not hasattr(chunk, 'HeightMap') or chunk.HeightMap is None: return heightMap = chunk.HeightMap chunkWidth = chunkLength = 16 chunkHeight = chunk.dimension.bounds.height z, x = list(numpy.indices((chunkLength, chunkWidth))) y = (heightMap - 1)[:chunkLength, :chunkWidth] numpy.clip(y, 0, chunkHeight - 1, y) nonZeroHeights = y > 0 heights = y.reshape((16, 16)) x = x[nonZeroHeights] if not len(x): return z = z[nonZeroHeights] y = y[nonZeroHeights] # Get the top block in each column blockResult = dim.getBlocks(x + (cx * 16), y, z + (cz * 16), return_Data=True) topBlocks = blockResult.Blocks topBlockData = blockResult.Data # Get the block above each column top. We'll recolor the top face of the column if a flower or another # transparent block is on top. aboveY = y + 1 numpy.clip(aboveY, 0, chunkHeight - 1, aboveY) blocksAbove = dim.getBlocks(x + (cx * 16), aboveY, z + (cz * 16)).Blocks flatcolors = dim.blocktypes.mapColor[topBlocks, topBlockData][:, numpy.newaxis, :] # flatcolors[:,:,:3] *= (0.6 + (h * (0.4 / float(chunkHeight-1)))) [topBlocks != 0][:, numpy.newaxis, numpy.newaxis] yield vertexBuffer = VertexArrayBuffer(len(x), textures=False, lights=False) vertexBuffer.vertex[..., 0] = x[:, numpy.newaxis] vertexBuffer.vertex[..., 1] = y[:, numpy.newaxis] vertexBuffer.vertex[..., 2] = z[:, numpy.newaxis] va0 = vertexBuffer.copy() va0.vertex[:] += standardCubeTemplates[faces.FaceYIncreasing, ..., :3] overmask = blocksAbove > 0 colors = dim.blocktypes.mapColor[:, 0][ blocksAbove[overmask]][:, numpy.newaxis] flatcolors[overmask] = colors if self.detailLevel == 2: heightfactor = (y / float(chunk.dimension.bounds.height)) * 0.33 + 0.66 flatcolors[ ..., : 3] *= heightfactor[:, numpy.newaxis, numpy. newaxis] # xxx implicit cast from byte to float and back va0.rgb[:] = flatcolors yield if self.detailLevel == 2: self.vertexArrays = [va0] return # Calculate how deep each column needs to go to be flush with the adjacent column; # If columns extend all the way down, performance suffers due to fill rate. depths = numpy.zeros((chunkWidth, chunkLength), dtype='uint16') depths[1:-1, 1:-1] = reduce(numpy.minimum, (heights[1:-1, :-2], heights[1:-1, 2:], heights[:-2, 1:-1], heights[2:, 1:-1])) depths = depths[nonZeroHeights] yield va1 = vertexBuffer.copy() va1.vertex[..., :3] += standardCubeTemplates[faces.FaceXIncreasing, ..., :3] va1.vertex[:, 0, 1] = depths va1.vertex[:, 0, 1] = depths # stretch to floor va1.vertex[:, (2, 3), 1] -= 0.5 # drop down to prevent intersection pixels flatcolors *= 0.8 va1.rgb[:] = flatcolors grassmask = topBlocks == 2 # color grass sides with dirt's color va1.rgb[grassmask] = dim.blocktypes.mapColor[:, 0][[3]][:, numpy.newaxis] va2 = va1.copy() va1.vertex[:, (1, 2), 0] -= 1.0 # turn diagonally va2.vertex[:, (0, 3), 0] -= 1.0 # turn diagonally vertexArrays = [va1, va2, va0] self.vertexArrays = vertexArrays
def axis(self, axis): self._axis = axis self.dirty = True gridSize = 64 left = -gridSize//2 right = gridSize//2 gridArrayBuffer = VertexArrayBuffer((gridSize * 4,), GL.GL_LINES, textures=False, lights=False) gridArrayBuffer.rgba[:] = 255, 255, 255, 100 # y=0, move by translating gridArrayBuffer.vertex[:, axis] = 0 axis1 = (axis-1) % 3 axis2 = (axis+1) % 3 # left edge gridArrayBuffer.vertex[0:gridSize*2:2, axis2] = left gridArrayBuffer.vertex[0:gridSize*2:2, axis1] = range(left, right) # right edge gridArrayBuffer.vertex[1:gridSize*2:2, axis2] = right-1 gridArrayBuffer.vertex[1:gridSize*2:2, axis1] = range(left, right) # bottom edge gridArrayBuffer.vertex[gridSize*2::2, axis1] = left gridArrayBuffer.vertex[gridSize*2::2, axis2] = range(left, right) # top edge gridArrayBuffer.vertex[gridSize*2+1::2, axis1] = right-1 gridArrayBuffer.vertex[gridSize*2+1::2, axis2] = range(left, right) if self.vertexNode: self.removeChild(self.vertexNode) self.vertexNode = VertexNode([gridArrayBuffer]) self.addChild(self.vertexNode)
def axis(self, axis): self._axis = axis self.dirty = True gridSize = 64 left = -gridSize // 2 right = gridSize // 2 gridArrayBuffer = VertexArrayBuffer((gridSize * 4, ), GL.GL_LINES, textures=False, lights=False) gridArrayBuffer.rgba[:] = 255, 255, 255, 100 # y=0, move by translating gridArrayBuffer.vertex[:, axis] = 0 axis1 = (axis - 1) % 3 axis2 = (axis + 1) % 3 # left edge gridArrayBuffer.vertex[0:gridSize * 2:2, axis2] = left gridArrayBuffer.vertex[0:gridSize * 2:2, axis1] = range(left, right) # right edge gridArrayBuffer.vertex[1:gridSize * 2:2, axis2] = right - 1 gridArrayBuffer.vertex[1:gridSize * 2:2, axis1] = range(left, right) # bottom edge gridArrayBuffer.vertex[gridSize * 2::2, axis1] = left gridArrayBuffer.vertex[gridSize * 2::2, axis2] = range(left, right) # top edge gridArrayBuffer.vertex[gridSize * 2 + 1::2, axis1] = right - 1 gridArrayBuffer.vertex[gridSize * 2 + 1::2, axis2] = range(left, right) if self.vertexNode: self.translateNode.removeChild(self.vertexNode) self.vertexNode = VertexNode([gridArrayBuffer]) self.translateNode.addChild(self.vertexNode)