-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapart.py
92 lines (83 loc) · 4.51 KB
/
mapart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import argparse
from PIL.Image import Resampling
import src
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(
prog='MapArtGenerator',
description='Generate mapart litematica from image'
)
arg_parser.add_argument('--image', '-i', type=str, required=True,
help='Input image filepath')
arg_parser.add_argument('--blocks', '-b', type=str, required=True,
help='Block count list filepath')
arg_parser.add_argument('--output', '-o', type=str,
help='Output filepath')
arg_parser.add_argument('--map-size', '-ms', type=int, default=1,
choices=[1, 2, 3, 4],
help='Size of map (default: 1)')
arg_parser.add_argument('--width', '-mw', type=int, default=1,
help='Width in maps (default: 1)')
arg_parser.add_argument('--height', '-mh', type=int, default=1,
help='Height in maps (default: 1)')
arg_parser.add_argument('--resampling', '-r', type=str, default='BICUBIC',
choices=['NEAREST', 'BILINEAR', 'BICUBIC',
'BOX', 'LANCZOS', 'HAMMING'],
help='Image resampling method (default: BICUBIC)')
arg_parser.add_argument('--support', '-s', type=str, default="minecraft:stone",
help='Support block id (default: minecraft:stone)')
arg_parser.add_argument('--palette', '-p', type=str, default='1.20',
choices=['1.20'],
help='Version of palette (default: 1.20)')
arg_parser.add_argument('--update', '-u', action='store_true',
help='Update block count list')
arg_parser.add_argument('--preview', '-v', type=str,
help='Preview image filepath')
arg_parser.add_argument('--transparent', '-t', action='store_true',
help='Place glass for transparent map')
arg_parser.add_argument('--name', '-n', type=str, default="MapArt",
help='Litematica name (default: MapArt)')
arg_parser.add_argument('--generator', '-g', type=str,
choices=['plain', 'stairs', 'boundary', 'fast_boundary', 'dropout', 'fast_dropout'], default='stairs',
help='Litematica layering generator type (default: boundary)')
args = arg_parser.parse_args()
print('Generating mapart...')
palette = src.decode_palette(f'palettes/{args.palette}.json')
blocks = src.decode_blocks(args.blocks)
if args.resampling == 'NEAREST':
resampling = Resampling.NEAREST
elif args.resampling == 'BILINEAR':
resampling = Resampling.BILINEAR
elif args.resampling == 'BICUBIC':
resampling = Resampling.BICUBIC
elif args.resampling == 'BOX':
resampling = Resampling.BOX
elif args.resampling == 'LANCZOS':
resampling = Resampling.LANCZOS
elif args.resampling == 'HAMMING':
resampling = Resampling.HAMMING
else:
exit('Invalid resampling type')
data, width, height = src.decode(args.image, palette, args.map_size, args.width,
args.height, resampling, blocks, args.generator != 'plain', args.transparent)
if args.generator == 'plain':
h, max_h = src.heightmap(data, width, height, src.generators.plain, src.optimizers.none)
elif args.generator == 'stairs':
h, max_h = src.heightmap(data, width, height, src.generators.stairs, src.optimizers.none)
elif args.generator == 'boundary':
h, max_h = src.heightmap(data, width, height, src.generators.stairs, src.optimizers.boundary)
elif args.generator == 'fast_boundary':
h, max_h = src.heightmap(data, width, height, src.generators.stairs, src.optimizers.fast_boundary)
elif args.generator == 'dropout':
h, max_h = src.heightmap(data, width, height, src.generators.stairs, src.optimizers.dropout)
elif args.generator == 'fast_dropout':
h, max_h = src.heightmap(data, width, height, src.generators.stairs, src.optimizers.fast_dropout)
else:
exit('Invalid generator type')
if args.preview:
src.generate_preview(args.preview, data, h, max_h, width, height, palette)
path = args.output
if path is None:
path = args.image.rsplit('.', 1)[0]
src.build(path, h, max_h, width, height, args.name, args.support)
if args.update:
src.encode_blocks(args.blocks, blocks)