Skip to content

Instantly share code, notes, and snippets.

@brownan
Created October 15, 2013 00:50
Show Gist options
  • Save brownan/6984867 to your computer and use it in GitHub Desktop.
Save brownan/6984867 to your computer and use it in GitHub Desktop.
import sys
import math
import numpy
from overviewer.world import ChunkDoesntExist
from overviewer import blockdefinitions
from overviewer.oil import Matrix
from overviewer import textures
from overviewer.isometricrenderer import IsometricRenderer
from overviewer import dispatcher
from overviewer import observer
from overviewer.canvas import SingleImageCanvas
"""This script takes a block ID and a data value and renders a single image
rendering of that block.
This is also a test of the entire rendering stack. The only fake object is the
following RegionSet object which only has a single block in it.
"""
class FakeRegionSet(object):
def __init__(self, blockid, data=0):
self.blockid = blockid
self.data = data
def get_chunk(self, x, z):
if x == z == 0:
chunk_data = {}
section = {}
chunk_data['Sections'] = [section]
blocks = numpy.ones((16,16,16), dtype=numpy.uint16) * self.blockid
section['Blocks'] = blocks
skylight = numpy.ones((16,16,16), dtype=numpy.uint8) * 0xF
section['SkyLight'] = skylight
blocklight = numpy.ones((16,16,16), dtype=numpy.uint8) * 0xF
section['BlockLight'] = blocklight
data = numpy.zeros((16,16,16), dtype=numpy.uint8)
data[0,0,0] = self.data
section['Data'] = data
return chunk_data
else:
raise ChunkDoesntExist("Chunk {0},{1} doesn't exist".format(x,z))
def iterate_chunks(self):
return [(0,0,0)]
def get_chunk_mtime(self, x, z):
if x == z == 0:
return 0
return None
def main():
blockid = int(sys.argv[1])
data = int(sys.argv[2]) if len(sys.argv) > 2 else 0
regionset = FakeRegionSet(blockid, data)
blockdefs = blockdefinitions.get_default()
tex = textures.get_default()
# Standard viewing angle: ~35 degrees, straight down the diagonal of a cube
matrix = Matrix().rotate(math.atan2(1,math.sqrt(2)),0,0).rotate(0,math.radians(45),0).scale(17,17,17)
workers = []
renderer = IsometricRenderer(regionset, tex, blockdefs, matrix)
xmin, ymin, xmax, ymax = renderer.get_full_rect()
canvas = SingleImageCanvas((xmin, ymin), (xmax-xmin, ymax-ymin), renderer,
"output_{0}.png".format(0))
#from IPython import embed; embed()
workers.append(canvas)
d = dispatcher.Dispatcher()
d.dispatch_all(workers, observer.ProgressBarObserver())
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment