/
magicavoxel_room_test.py
88 lines (74 loc) · 3.54 KB
/
magicavoxel_room_test.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
#!/usr/bin/env python
import argparse
import logging
from redeclipse import prefabs
# We must override this ASAP since everyone else (e.g. prefabs) also imports the TEXMAN from prefab.
from redeclipse.textures import DefaultThemedTextureManager, PrimaryThemedTextureManager, RainbowPukeTextureManager # noqa
prefabs.TEXMAN = RainbowPukeTextureManager() # noqa
# Back to our normally scheduled imports.
from redeclipse.cli import parse
from redeclipse.entities import Sunlight
from redeclipse.magicavoxel.writer import to_magicavoxel
from redeclipse.prefabs import castle, dungeon, spacestation, original # noqa
from redeclipse.upm import UnusedPositionManager
from redeclipse.vector import CoarseVector
from redeclipse.vector.orientations import EAST
from redeclipse.voxel import VoxelWorld
# from redeclipse.skybox import MinecraftSky
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
def main(magica=False, redeclipse=False):
# Override texman
magica_classes = [
# # Original
original.spawn_room
# # Castle
# castle.castle_gate, castle.castle_gate_simple,
# castle.castle_large, castle.castle_wall_corner,
# castle.castle_wall_end_cliff, castle.castle_wall_entry,
# castle.castle_wall_section, castle.castle_wall_section_long,
# castle.castle_wall_section_long_damaged,
# castle.castle_wall_section_tjoint, castle.castle_wall_tower,
# castle.wooden_bridge,
# # Dungeon
# dungeon.dungeon_2x2, dungeon.dungeon_junction, dungeon.dungeon_stair2,
# dungeon.dungeon_walkway, dungeon.dungeon_walkway3,
# # Space
# spacestation.station_tube1, spacestation.station_tube3, spacestation.station_tube_jumpx,
# spacestation.station_tubeX, spacestation.station_endcap, spacestation.station_right, spacestation.station_ring,
# spacestation.station_ring_vertical, spacestation.station_sphere, spacestation.station_sphere_slice,
# spacestation.station_stair2,
]
for idx, Room in enumerate(magica_classes):
mymap = parse('maps/empty-day.mpz')
upm = UnusedPositionManager(2**8, mirror=4, noclip=True)
v = VoxelWorld(size=2**8)
logging.info("Processing %s" % Room.__name__)
kwargs = Room.randOpts(None)
e = Room(pos=CoarseVector(8 + 3, 8, 1), orientation=EAST, **kwargs)
[m.render(v, mymap) for m in upm.register_room(e)]
for room in upm.endcap(debug=True, possible_endcaps=[]):
room.render(v, mymap)
if magica:
with open('%03d_%s.vox' % (idx, Room.__name__), 'wb') as handle:
to_magicavoxel(v, handle, prefabs.TEXMAN)
if redeclipse:
with open('/home/hxr/.redeclipse/maps/%03d_%s.mpz' % (idx, Room.__name__), 'wb') as mpz_out:
sunlight = Sunlight(
red=128,
green=128,
blue=128,
offset=45, # top
)
mymap.ents.append(sunlight)
prefabs.TEXMAN.emit_conf(mpz_out)
prefabs.TEXMAN.copy_data()
mymap.world = v.to_octree()
mymap.world[0].octsav = 0
mymap.write(mpz_out.name)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Add trees to map')
parser.add_argument('--magica', action='store_true', help='Output magica .vox files')
parser.add_argument('--redeclipse', action='store_true', help='Output redeclipse .mpz files')
args = parser.parse_args()
main(**vars(args))