extract color variables for rendering
This commit is contained in:
parent
eb256132de
commit
f85bcc173a
1 changed files with 49 additions and 36 deletions
|
@ -9,6 +9,14 @@ from c3nav.mapdata.render.renderdata import LevelRenderData
|
||||||
from c3nav.mapdata.render.utils import get_full_levels, get_min_altitude
|
from c3nav.mapdata.render.utils import get_full_levels, get_min_altitude
|
||||||
from c3nav.mapdata.utils.color import color_to_rgb, rgb_to_color
|
from c3nav.mapdata.utils.color import color_to_rgb, rgb_to_color
|
||||||
|
|
||||||
|
RENDER_COLOR_BACKGROUND = "#DCDCDC"
|
||||||
|
RENDER_COLOR_WALL_FILL = "#aaaaaa"
|
||||||
|
RENDER_COLOR_WALL_BORDER = "#666666"
|
||||||
|
RENDER_COLOR_DOOR_FILL = "#ffffff"
|
||||||
|
RENDER_COLOR_GROUND_FILL = "#eeeeee"
|
||||||
|
RENDER_COLOR_OBSTACLES_DEFAULT_FILL = "#b7b7b7"
|
||||||
|
RENDER_COLOR_OBSTACLES_DEFAULT_BORDER = "#888888"
|
||||||
|
|
||||||
|
|
||||||
class MapRenderer:
|
class MapRenderer:
|
||||||
def __init__(self, level, minx, miny, maxx, maxy, scale=1, access_permissions=None, full_levels=False,
|
def __init__(self, level, minx, miny, maxx, maxy, scale=1, access_permissions=None, full_levels=False,
|
||||||
|
@ -39,7 +47,8 @@ class MapRenderer:
|
||||||
level_render_data = LevelRenderData.get(self.level)
|
level_render_data = LevelRenderData.get(self.level)
|
||||||
|
|
||||||
engine = engine_cls(self.width, self.height, self.minx, self.miny, float(level_render_data.base_altitude),
|
engine = engine_cls(self.width, self.height, self.minx, self.miny, float(level_render_data.base_altitude),
|
||||||
scale=self.scale, buffer=1, background='#DCDCDC', center=center, min_width=self.min_width)
|
scale=self.scale, buffer=1, background=RENDER_COLOR_BACKGROUND,
|
||||||
|
center=center, min_width=self.min_width)
|
||||||
|
|
||||||
if hasattr(engine, 'custom_render'):
|
if hasattr(engine, 'custom_render'):
|
||||||
engine.custom_render(level_render_data, access_permissions, self.full_levels)
|
engine.custom_render(level_render_data, access_permissions, self.full_levels)
|
||||||
|
@ -72,17 +81,17 @@ class MapRenderer:
|
||||||
).union(add_walls)
|
).union(add_walls)
|
||||||
|
|
||||||
if not_full_levels:
|
if not_full_levels:
|
||||||
engine.add_geometry(geoms.walls_base, fill=FillAttribs('#aaaaaa'), category='walls')
|
engine.add_geometry(geoms.walls_base, fill=FillAttribs(RENDER_COLOR_WALL_FILL), category='walls')
|
||||||
engine.add_geometry(geoms.walls_bottom.fit(scale=geoms.min_altitude-min_altitude,
|
engine.add_geometry(geoms.walls_bottom.fit(scale=geoms.min_altitude-min_altitude,
|
||||||
offset=min_altitude-int(0.7*1000)),
|
offset=min_altitude-int(0.7*1000)),
|
||||||
fill=FillAttribs('#aaaaaa'), category='walls')
|
fill=FillAttribs(RENDER_COLOR_WALL_FILL), category='walls')
|
||||||
for i, altitudearea in enumerate(geoms.altitudeareas):
|
for i, altitudearea in enumerate(geoms.altitudeareas):
|
||||||
base = altitudearea.base.difference(crop_areas)
|
base = altitudearea.base.difference(crop_areas)
|
||||||
bottom = altitudearea.bottom.difference(crop_areas)
|
bottom = altitudearea.bottom.difference(crop_areas)
|
||||||
engine.add_geometry(base, fill=FillAttribs('#eeeeee'), category='ground', item=i)
|
engine.add_geometry(base, fill=FillAttribs(RENDER_COLOR_GROUND_FILL), category='ground', item=i)
|
||||||
engine.add_geometry(bottom.fit(scale=geoms.min_altitude - min_altitude,
|
engine.add_geometry(bottom.fit(scale=geoms.min_altitude - min_altitude,
|
||||||
offset=min_altitude - int(0.7 * 1000)),
|
offset=min_altitude - int(0.7 * 1000)),
|
||||||
fill=FillAttribs('#aaaaaa'), category='ground')
|
fill=FillAttribs(RENDER_COLOR_WALL_FILL), category='ground')
|
||||||
|
|
||||||
# render altitude areas in default ground color and add ground colors to each one afterwards
|
# render altitude areas in default ground color and add ground colors to each one afterwards
|
||||||
# shadows are directly calculated and added by the engine
|
# shadows are directly calculated and added by the engine
|
||||||
|
@ -90,7 +99,7 @@ class MapRenderer:
|
||||||
geometry = altitudearea.geometry.difference(crop_areas)
|
geometry = altitudearea.geometry.difference(crop_areas)
|
||||||
if not_full_levels:
|
if not_full_levels:
|
||||||
geometry = geometry.filter(bottom=False)
|
geometry = geometry.filter(bottom=False)
|
||||||
engine.add_geometry(geometry, altitude=altitudearea.altitude, fill=FillAttribs('#eeeeee'),
|
engine.add_geometry(geometry, altitude=altitudearea.altitude, fill=FillAttribs(RENDER_COLOR_GROUND_FILL),
|
||||||
category='ground', item=i)
|
category='ground', item=i)
|
||||||
|
|
||||||
j = 0
|
j = 0
|
||||||
|
@ -104,27 +113,27 @@ class MapRenderer:
|
||||||
engine.add_geometry(hybrid_union(areas), fill=FillAttribs(color),
|
engine.add_geometry(hybrid_union(areas), fill=FillAttribs(color),
|
||||||
category='ground_%s' % hexcolor, item=j)
|
category='ground_%s' % hexcolor, item=j)
|
||||||
|
|
||||||
# add obstacles after everything related to ground for the nice right order
|
# add obstacles after everything related to ground for the nice right order
|
||||||
for i, altitudearea in enumerate(geoms.altitudeareas):
|
for i, altitudearea in enumerate(geoms.altitudeareas):
|
||||||
for height, height_obstacles in altitudearea.obstacles.items():
|
for height, height_obstacles in altitudearea.obstacles.items():
|
||||||
for color, color_obstacles in height_obstacles.items():
|
for color, color_obstacles in height_obstacles.items():
|
||||||
for obstacle in color_obstacles:
|
for obstacle in color_obstacles:
|
||||||
if color:
|
if color:
|
||||||
fill_rgb = color_to_rgb(color)
|
fill_rgb = color_to_rgb(color)
|
||||||
stroke_color = rgb_to_color((*((0.75*i) for i in fill_rgb[:3]), fill_rgb[3]))
|
stroke_color = rgb_to_color((*((0.75*i) for i in fill_rgb[:3]), fill_rgb[3]))
|
||||||
engine.add_geometry(
|
engine.add_geometry(
|
||||||
obstacle,
|
obstacle,
|
||||||
fill=FillAttribs(color),
|
fill=FillAttribs(color),
|
||||||
stroke=StrokeAttribs(stroke_color, 0.05, min_px=0.2),
|
stroke=StrokeAttribs(stroke_color, 0.05, min_px=0.2),
|
||||||
category='obstacles'
|
category='obstacles'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
engine.add_geometry(
|
engine.add_geometry(
|
||||||
obstacle,
|
obstacle,
|
||||||
fill=FillAttribs('#B7B7B7'),
|
fill=FillAttribs(RENDER_COLOR_OBSTACLES_DEFAULT_FILL),
|
||||||
stroke=StrokeAttribs('#888888', 0.05, min_px=0.2),
|
stroke=StrokeAttribs(RENDER_COLOR_OBSTACLES_DEFAULT_BORDER, 0.05, min_px=0.2),
|
||||||
category='obstacles'
|
category='obstacles'
|
||||||
)
|
)
|
||||||
|
|
||||||
# add walls, stroke_px makes sure that all walls are at least 1px thick on all zoom levels,
|
# add walls, stroke_px makes sure that all walls are at least 1px thick on all zoom levels,
|
||||||
walls = None
|
walls = None
|
||||||
|
@ -133,29 +142,33 @@ class MapRenderer:
|
||||||
|
|
||||||
walls_extended = geoms.walls_extended and full_levels
|
walls_extended = geoms.walls_extended and full_levels
|
||||||
if walls is not None:
|
if walls is not None:
|
||||||
engine.add_geometry(walls.filter(bottom=not not_full_levels,
|
engine.add_geometry(
|
||||||
top=not walls_extended),
|
walls.filter(bottom=not not_full_levels,
|
||||||
height=geoms.default_height, fill=FillAttribs('#aaaaaa'), category='walls')
|
top=not walls_extended),
|
||||||
|
height=geoms.default_height, fill=FillAttribs(RENDER_COLOR_WALL_FILL), category='walls'
|
||||||
|
)
|
||||||
|
|
||||||
for short_wall in geoms.short_walls:
|
for short_wall in geoms.short_walls:
|
||||||
engine.add_geometry(short_wall.filter(bottom=not not_full_levels),
|
engine.add_geometry(short_wall.filter(bottom=not not_full_levels),
|
||||||
fill=FillAttribs('#aaaaaa'), category='walls')
|
fill=FillAttribs(RENDER_COLOR_WALL_FILL), category='walls')
|
||||||
|
|
||||||
if walls_extended:
|
if walls_extended:
|
||||||
engine.add_geometry(geoms.walls_extended, fill=FillAttribs('#aaaaaa'), category='walls')
|
engine.add_geometry(geoms.walls_extended, fill=FillAttribs(RENDER_COLOR_WALL_FILL), category='walls')
|
||||||
|
|
||||||
doors_extended = geoms.doors_extended and full_levels
|
doors_extended = geoms.doors_extended and full_levels
|
||||||
if not geoms.doors.is_empty:
|
if not geoms.doors.is_empty:
|
||||||
engine.add_geometry(geoms.doors.difference(add_walls).filter(top=not doors_extended),
|
engine.add_geometry(geoms.doors.difference(add_walls).filter(top=not doors_extended),
|
||||||
fill=FillAttribs('#ffffff'),
|
fill=FillAttribs(RENDER_COLOR_DOOR_FILL),
|
||||||
stroke=StrokeAttribs('#ffffff', 0.05, min_px=0.2),
|
stroke=StrokeAttribs(RENDER_COLOR_DOOR_FILL, 0.05, min_px=0.2),
|
||||||
category='doors')
|
category='doors')
|
||||||
|
|
||||||
if doors_extended:
|
if doors_extended:
|
||||||
engine.add_geometry(geoms.doors_extended, fill=FillAttribs('#aaaaaa'), category='doors')
|
engine.add_geometry(geoms.doors_extended, fill=FillAttribs(RENDER_COLOR_WALL_FILL), category='doors')
|
||||||
|
|
||||||
if walls is not None:
|
if walls is not None:
|
||||||
engine.add_geometry(walls, stroke=StrokeAttribs('#666666', 0.05, min_px=0.2), category='walls')
|
engine.add_geometry(walls,
|
||||||
|
stroke=StrokeAttribs(RENDER_COLOR_WALL_BORDER, 0.1, min_px=1),
|
||||||
|
category='walls')
|
||||||
|
|
||||||
if geoms.on_top_of_id is None:
|
if geoms.on_top_of_id is None:
|
||||||
not_full_levels = not self.full_levels and engine.is_3d
|
not_full_levels = not self.full_levels and engine.is_3d
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue