Beispiel #1
0
    def makeChunkVertices(self, chunk, limitBox):
        entityPositions = []
        entityColors = []
        colorMap = {
            "Item": (0x22, 0xff, 0x22, 0x5f),
            "XPOrb": (0x88, 0xff, 0x88, 0x5f),
            "Painting": (134, 96, 67, 0x5f),
        }
        for i, entityRef in enumerate(chunk.Entities):
            if i % 10 == 0:
                yield
            color = colorMap.get(entityRef.id)
            if color is None:
                continue
            pos = entityRef.Position
            if limitBox and pos not in limitBox:
                continue

            entityPositions.append(pos)
            entityColors.append(color)

        items = self._computeVertices(
            entityPositions,
            numpy.array(entityColors, dtype='uint8')[:, numpy.newaxis,
                                                     numpy.newaxis],
            offset=True,
            chunkPosition=chunk.chunkPosition)
        yield
        self.sceneNode = scenegraph.VertexNode(items)
Beispiel #2
0
    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
Beispiel #3
0
    def makeChunkVertices(self, chunk, limitBox):
        if hasattr(chunk, "TileTicks"):
            ticks = chunk.TileTicks
            if len(ticks):
                self.sceneNode = scenegraph.VertexNode(
                    self._computeVertices([[t[i].value for i in "xyz"]
                                           for t in ticks],
                                          (0xff, 0xff, 0xff, 0x44),
                                          chunkPosition=chunk.chunkPosition))

        yield
Beispiel #4
0
    def makeChunkVertices(self, chunk, limitBox):
        tilePositions = []
        for i, ref in enumerate(chunk.TileEntities):
            if i % 10 == 0:
                yield

            if limitBox and ref.Position not in limitBox:
                continue
            tilePositions.append(ref.Position)

        tiles = self._computeVertices(tilePositions, (0xff, 0xff, 0x33, 0x44),
                                      chunkPosition=chunk.chunkPosition)
        yield
        self.sceneNode = scenegraph.VertexNode(tiles)
Beispiel #5
0
    def makeChunkVertices(self, chunk, limitBox):
        monsterPositions = []
        for i, entityRef in enumerate(chunk.Entities):
            if i % 10 == 0:
                yield
            ID = entityRef.id

            if ID in self.notMonsters:
                continue
            pos = entityRef.Position
            if limitBox and pos not in limitBox:
                continue
            monsterPositions.append(pos)

        monsters = self._computeVertices(monsterPositions,
                                         (0xff, 0x22, 0x22, 0x44),
                                         offset=True,
                                         chunkPosition=chunk.chunkPosition)
        yield
        self.sceneNode = scenegraph.VertexNode(monsters)
Beispiel #6
0
    def workOnChunk(self, chunk, visibleSections=None):
        work = 0
        cPos = chunk.chunkPosition

        chunkInfo = self.worldScene.getChunkRenderInfo(cPos)

        chunkInfo.visibleSections = visibleSections
        try:
            chunkUpdate = chunkupdate.ChunkUpdate(self, chunkInfo, chunk)
            for _ in chunkUpdate:
                work += 1
                if (work % SceneUpdateTask.workFactor) == 0:
                    yield

            chunkInfo.invalidLayers = set()
            meshesByRS = collections.defaultdict(list)
            for mesh in chunkUpdate.blockMeshes:
                meshesByRS[mesh.renderstate].append(mesh)

            for renderstate in renderstates.allRenderstates:
                groupNode = self.worldScene.getRenderstateGroup(renderstate)
                meshes = meshesByRS[renderstate]
                if len(meshes):
                    arrays = sum([mesh.vertexArrays for mesh in meshes], [])
                    if len(arrays):
                        chunkNode = ChunkNode(cPos)
                        groupNode.addChunkNode(chunkNode)
                        node = scenegraph.VertexNode(arrays)
                        chunkNode.addChild(node)
                    else:
                        groupNode.discardChunkNode(*cPos)

                        # Need a way to signal WorldScene that this chunk didn't need updating in this renderstate,
                        # but it should keep the old vertex arrays for the state.
                        # Alternately, signal WorldScene that the chunk did update for the renderstate and no
                        # vertex arrays resulted. Return a mesh with zero length vertexArrays
                        #else:
                        #    groupNode.discardChunkNode(*cPos)

        except Exception as e:
            logging.exception(u"Rendering chunk %s failed: %r", cPos, e)
Beispiel #7
0
    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 = scenegraph.VertexNode([gridArrayBuffer])
        self.translateNode.addChild(self.vertexNode)
Beispiel #8
0
    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 = QuadVertexArrayBuffer(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)