From 6124ffd0edcae99c47bfaedc36bfb4781fcded2f Mon Sep 17 00:00:00 2001 From: Ryan Rector Date: Sun, 10 Jul 2011 21:06:09 -0600 Subject: [PATCH] Early work on rotating stubborn textures --- rendernode.py | 3 ++- textures.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/rendernode.py b/rendernode.py index 6f6c76e..10db6c6 100644 --- a/rendernode.py +++ b/rendernode.py @@ -65,7 +65,8 @@ def pool_initializer(rendernode): # make sure textures are generated for this process # and initialize c_overviewer - textures.generate(path=rendernode.options.get('textures_path', None)) + textures.generate(north_direction=rendernode.options.get('north_direction', None), + path=rendernode.options.get('textures_path', None)) c_overviewer.init_chunk_render() # load biome data in each process, if needed diff --git a/textures.py b/textures.py index 5e2db3b..61ea8af 100644 --- a/textures.py +++ b/textures.py @@ -500,7 +500,7 @@ def generate_texture_tuple(img, blockid): blockmap list and specialblockmap dictionary.""" return (img.convert("RGB"), img.split()[3], generate_opaque_mask(img)) -def generate_special_texture(blockID, data): +def generate_special_texture(blockID, data, north_direction): """Generates a special texture, such as a correctly facing minecraft track""" #print "%s has ancillary data: %X" %(blockID, data) # TODO ladders, stairs, levers, buttons, and signs @@ -594,6 +594,11 @@ def generate_special_texture(blockID, data): if blockID == 26: # bed + if north_direction == 'upper-right': + if (data & 0x3) == 0: data = data & 0x8 | 0x2 + elif (data & 0x3) == 1: data = data & 0x8 | 0x3 + elif (data & 0x3) == 2: data = data & 0x8 | 0x0 + elif (data & 0x3) == 3: data = data & 0x8 | 0x1 increment = 5 left_face = None right_face = None @@ -708,6 +713,11 @@ def generate_special_texture(blockID, data): if blockID in (50,75,76): # torch, off redstone torch, on redstone torch + if north_direction == 'upper-right': + if data == 1: data = 2 + elif data == 2: data = 1 + elif data == 3: data = 4 + elif data == 4: data = 3 # choose the proper texture if blockID == 50: # torch @@ -777,6 +787,11 @@ def generate_special_texture(blockID, data): if blockID in (53,67): # wooden and cobblestone stairs. + if north_direction == 'upper-right': + if data == 0: data = 1 + elif data == 1: data = 0 + elif data == 2: data = 3 + elif data == 3: data = 2 if blockID == 53: # wooden texture = terrain_images[4] @@ -988,6 +1003,11 @@ def generate_special_texture(blockID, data): if blockID in (61, 62, 23): #furnace and burning furnace + if north_direction == 'upper-right': + if data == 2: data = 3 + elif data == 3: data = 2 + elif data == 4: data = 5 + elif data == 5: data = 4 top = terrain_images[62] side = terrain_images[45] @@ -1018,6 +1038,8 @@ def generate_special_texture(blockID, data): # cut the planks to the size of a signpost ImageDraw.Draw(texture).rectangle((0,12,15,15),outline=(0,0,0,0),fill=(0,0,0,0)) + if north_direction == 'upper-right': + data = (data + 8) % 16 # If the signpost is looking directly to the image, draw some # random dots, they will look as text. if data in (0,1,2,3,4,5,15): @@ -1070,6 +1092,11 @@ def generate_special_texture(blockID, data): # mask out the high bits to figure out the orientation img = Image.new("RGBA", (24,24), (38,92,255,0)) + if north_direction == 'upper-right': + if (data & 0x3) == 0: data = data & 0xc | 0x2 + elif (data & 0x3) == 1: data = data & 0xc | 0x3 + elif (data & 0x3) == 2: data = data & 0xc | 0x0 + elif (data & 0x3) == 3: data = data & 0xc | 0x1 if (data & 0x03) == 0: if not swung: tex = transform_image_side(raw_door) @@ -1108,6 +1135,11 @@ def generate_special_texture(blockID, data): if blockID == 65: # ladder + if north_direction == 'upper-right': + if data == 2: data = 3 + elif data == 3: data = 2 + elif data == 4: data = 5 + elif data == 5: data = 4 img = Image.new("RGBA", (24,24), (38,92,255,0)) raw_texture = terrain_images[83] #print "ladder is facing: %d" % data @@ -1154,6 +1186,17 @@ def generate_special_texture(blockID, data): raw_straight = terrain_images[128] raw_corner = terrain_images[112] + if north_direction == 'upper-right': + if data == 2: data = 3 + elif data == 3: data = 2 + elif data == 4: data = 5 + elif data == 5: data = 4 + + elif data == 6: data = 8 + elif data == 7: data = 9 + elif data == 8: data = 6 + elif data == 9: data = 7 + ## use transform_image to scale and shear if data == 0: track = transform_image(raw_straight, blockID) @@ -1202,6 +1245,11 @@ def generate_special_texture(blockID, data): if blockID == 68: # wall sign + if north_direction == 'upper-right': + if data == 2: data = 3 + elif data == 3: data = 2 + elif data == 4: data = 5 + elif data == 5: data = 4 texture = terrain_images[4].copy() # cut the planks to the size of a signpost ImageDraw.Draw(texture).rectangle((0,12,15,15),outline=(0,0,0,0),fill=(0,0,0,0)) @@ -1332,6 +1380,11 @@ def generate_special_texture(blockID, data): if blockID in (86,91): # pumpkins, jack-o-lantern + if north_direction == 'upper-right': + if data == 0: data = 2 + elif data == 1: data = 3 + elif data == 2: data = 0 + elif data == 3: data = 1 top = terrain_images[102] frontID = 119 if blockID == 86 else 120 front = terrain_images[frontID] @@ -1393,6 +1446,11 @@ def generate_special_texture(blockID, data): if blockID in (93, 94): # redstone repeaters, ON and OFF # NOTE: this function uses the redstone torches generated above, # this must run after the function of the torches. + if north_direction == 'upper-right': + if (data & 0x3) == 0: data = data & 0xc | 0x2 + elif (data & 0x3) == 1: data = data & 0xc | 0x3 + elif (data & 0x3) == 2: data = data & 0xc | 0x0 + elif (data & 0x3) == 3: data = data & 0xc | 0x1 top = terrain_images[131] if blockID == 93 else terrain_images[147] side = terrain_images[5] @@ -1509,6 +1567,11 @@ def generate_special_texture(blockID, data): if blockID == 96: # trapdoor + if north_direction == 'upper-right': + if (data & 0x3) == 0: data = data & 0x4 | 0x1 + elif (data & 0x3) == 1: data = data & 0x4 | 0x0 + elif (data & 0x3) == 2: data = data & 0x4 | 0x3 + elif (data & 0x3) == 3: data = data & 0x4 | 0x2 texture = terrain_images[84] if data & 0x4 == 0x4: # opened trapdoor if data & 0x3 == 0: # west @@ -1664,7 +1727,7 @@ biome_tall_fern_texture = None biome_leaf_texture = None specialblockmap = None -def generate(path=None): +def generate(north_direction, path=None): global _find_file_local_path _find_file_local_path = path @@ -1689,4 +1752,4 @@ def generate(path=None): specialblockmap = {} for blockID in special_blocks: for data in special_map[blockID]: - specialblockmap[(blockID, data)] = generate_special_texture(blockID, data) + specialblockmap[(blockID, data)] = generate_special_texture(blockID, data, north_direction)