Exemplo n.º 1
0
def render(f, world, extents = None):
    if extents is None:
        actualExtents = world.extents
    else:
        actualExtents = extents

    blockDefs = getMinecraftBlocksById()

    def getBlockDef(blockId):
        if blockId in blockDefs:
            return blockDefs[blockId]
        else:
            return BlockDef(blockId, 'Default')

    def getCombineOperator(blockDef):
        if blockDef.transparent:
            return 'merge'
        else:
            return 'union'

    def writeBoundedBy(chunk):
        # for the question: why do we generate bounding boxes?
        #
        # from the povray documentation: 'Unbounded unions are always split
        # into their component parts so that automatic bounding works better.'
        #
        # http://www.povray.org/documentation/view/3.6.1/223/#s02_01_02_08_03

        cExtents = chunk.extents

        if cExtents is None:
            return

        # TODO use sphere bounding when we got cubic shapes
        # i guess spheres are faster than boxes?

        f.write('bounded_by { box { <%s, %s, %s>, <%s, %s, %s> } } \n' % (-cExtents[1][0] + 1, cExtents[0][1], cExtents[0][2], -cExtents[0][0] + 1, cExtents[1][1], cExtents[1][2]))


    def writeChunk(chunk, combineOperator, blockId):
        # write chunk subchunks
        for subChunk in chunk.chunks:
            chunksLen = len(subChunk.chunks)
            blocksLen = len(subChunk.blocks)

            if chunksLen == 0 and blocksLen == 0:
                continue

            requireBlock = not ((chunksLen == 0 and blocksLen == 1) or (chunksLen == 1 and blocksLen == 0))

            if requireBlock:
                f.write('%s {\n' % combineOperator)

            writeChunk(subChunk, combineOperator, blockId)

            if requireBlock:
                writeBoundedBy(subChunk)
                f.write('}\n')

        # write chunk blocks
        for blockPos in chunk.blocks:
            f.write('object{ Block%sObject translate <%s, %s, %s>}\n' % (blockId, -blockPos[0], blockPos[1], blockPos[2]))
    
    for blockId, chunk in ChunkGenerator(6).generateChunks(world, actualExtents):
        blockDef = getBlockDef(blockId)
        combineOperator = getCombineOperator(blockDef)

        f.write('// Block%s\n' % blockId)
        f.write('%s {\n' % combineOperator)

        writeChunk(chunk, combineOperator, blockId)
        writeBoundedBy(chunk)
        
        f.write('\tmaterial { Block%sMaterial }\n' % blockId)

        f.write('}\n')
Exemplo n.º 2
0
    def __init__(self, chunkAxisLen):
        assert chunkAxisLen > 0

        self.chunkAxisLen = chunkAxisLen
        self._blockDefs = getMinecraftBlocksById()
        self._defaultBlockDef = Block(-1, 'Default')
Exemplo n.º 3
0
def render(f, world, extents=None):
    if extents is None:
        actualExtents = world.extents
    else:
        actualExtents = extents

    blockDefs = getMinecraftBlocksById()

    def getBlockDef(blockId):
        if blockId in blockDefs:
            return blockDefs[blockId]
        else:
            return BlockDef(blockId, "Default")

    def getCombineOperator(blockDef):
        if blockDef.transparent:
            return "merge"
        else:
            return "union"

    def writeBoundedBy(chunk):
        # for the question: why do we generate bounding boxes?
        #
        # from the povray documentation: 'Unbounded unions are always split
        # into their component parts so that automatic bounding works better.'
        #
        # http://www.povray.org/documentation/view/3.6.1/223/#s02_01_02_08_03

        cExtents = chunk.extents

        if cExtents is None:
            return

        # TODO use sphere bounding when we got cubic shapes
        # i guess spheres are faster than boxes?

        f.write(
            "bounded_by { box { <%s, %s, %s>, <%s, %s, %s> } } \n"
            % (-cExtents[1][0] + 1, cExtents[0][1], cExtents[0][2], -cExtents[0][0] + 1, cExtents[1][1], cExtents[1][2])
        )

    def writeChunk(chunk, combineOperator, blockId):
        # write chunk subchunks
        for subChunk in chunk.chunks:
            chunksLen = len(subChunk.chunks)
            blocksLen = len(subChunk.blocks)

            if chunksLen == 0 and blocksLen == 0:
                continue

            requireBlock = not ((chunksLen == 0 and blocksLen == 1) or (chunksLen == 1 and blocksLen == 0))

            if requireBlock:
                f.write("%s {\n" % combineOperator)

            writeChunk(subChunk, combineOperator, blockId)

            if requireBlock:
                writeBoundedBy(subChunk)
                f.write("}\n")

        # write chunk blocks
        for blockPos in chunk.blocks:
            f.write(
                "object{ Block%sObject translate <%s, %s, %s>}\n" % (blockId, -blockPos[0], blockPos[1], blockPos[2])
            )

    for blockId, chunk in ChunkGenerator(6).generateChunks(world, actualExtents):
        blockDef = getBlockDef(blockId)
        combineOperator = getCombineOperator(blockDef)

        f.write("// Block%s\n" % blockId)
        f.write("%s {\n" % combineOperator)

        writeChunk(chunk, combineOperator, blockId)
        writeBoundedBy(chunk)

        f.write("\tmaterial { Block%sMaterial }\n" % blockId)

        f.write("}\n")
Exemplo n.º 4
0
    def __init__(self, chunkAxisLen):
        assert chunkAxisLen > 0

        self.chunkAxisLen = chunkAxisLen
        self._blockDefs = getMinecraftBlocksById()
        self._defaultBlockDef = Block(-1, "Default")