support for colors in openscad export

This commit is contained in:
Laura Klünder 2017-11-14 15:02:56 +01:00
parent d6b94b0167
commit 19123f0844
3 changed files with 6 additions and 2 deletions

View file

@ -18,9 +18,11 @@ class Base3DEngine(RenderEngine):
self._current_group = None
self.groups = OrderedDict()
self.vertices = OrderedDict()
self.colors = OrderedDict()
self.np_scale = np.array((self.scale, self.scale, self.scale))
self.np_offset = np.array((-self.minx * self.scale, -self.miny * self.scale, 0))
if center:
self.np_offset -= np.array(((self.maxx - self.minx) * self.scale / 2,
(self.maxy - self.miny) * self.scale / 2,
@ -37,6 +39,7 @@ class Base3DEngine(RenderEngine):
if key not in self.vertices:
self.groups[self._current_group].append(key)
self.vertices.setdefault(key, []).append(self._place_geometry(geometry))
self.colors.setdefault(key, self.color_to_rgb(fill.color))
@staticmethod
def _append_to_vertices(vertices, append=None):

View file

@ -34,7 +34,8 @@ class OpenSCADEngine(Base3DEngine):
b'}\n\n')
for group, subgroups in self.groups.items():
result += (b'module ' + group.replace('-', 'minus').encode() + b'() {\n' +
b'\n'.join((b' %s();' % subgroup.replace('-', 'minus').encode())
b'\n'.join((b' color([%.2f, %.2f, %.2f]) %s();' %
(*self.colors[subgroup][:3], subgroup.replace('-', 'minus').encode()))
for subgroup in subgroups) + b'\n' +
b'}\n')
result += b'\n'

View file

@ -111,7 +111,7 @@ class MapRenderer:
scale = (bottom - min_altitude) / int(0.7 * 1000)
offset = min_altitude - bottom * scale
engine.add_geometry(altitudearea.geometry.fit(scale=scale, offset=offset).filter(top=False),
fill=FillAttribs('#aaaaaa'), category='ground')
fill=FillAttribs('#eeeeee'), category='ground')
# render altitude areas in default ground color and add ground colors to each one afterwards
# shadows are directly calculated and added by the engine