support for colors in openscad export
This commit is contained in:
parent
d6b94b0167
commit
19123f0844
3 changed files with 6 additions and 2 deletions
|
@ -18,9 +18,11 @@ class Base3DEngine(RenderEngine):
|
||||||
self._current_group = None
|
self._current_group = None
|
||||||
self.groups = OrderedDict()
|
self.groups = OrderedDict()
|
||||||
self.vertices = OrderedDict()
|
self.vertices = OrderedDict()
|
||||||
|
self.colors = OrderedDict()
|
||||||
|
|
||||||
self.np_scale = np.array((self.scale, self.scale, self.scale))
|
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))
|
self.np_offset = np.array((-self.minx * self.scale, -self.miny * self.scale, 0))
|
||||||
|
|
||||||
if center:
|
if center:
|
||||||
self.np_offset -= np.array(((self.maxx - self.minx) * self.scale / 2,
|
self.np_offset -= np.array(((self.maxx - self.minx) * self.scale / 2,
|
||||||
(self.maxy - self.miny) * self.scale / 2,
|
(self.maxy - self.miny) * self.scale / 2,
|
||||||
|
@ -37,6 +39,7 @@ class Base3DEngine(RenderEngine):
|
||||||
if key not in self.vertices:
|
if key not in self.vertices:
|
||||||
self.groups[self._current_group].append(key)
|
self.groups[self._current_group].append(key)
|
||||||
self.vertices.setdefault(key, []).append(self._place_geometry(geometry))
|
self.vertices.setdefault(key, []).append(self._place_geometry(geometry))
|
||||||
|
self.colors.setdefault(key, self.color_to_rgb(fill.color))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _append_to_vertices(vertices, append=None):
|
def _append_to_vertices(vertices, append=None):
|
||||||
|
|
|
@ -34,7 +34,8 @@ class OpenSCADEngine(Base3DEngine):
|
||||||
b'}\n\n')
|
b'}\n\n')
|
||||||
for group, subgroups in self.groups.items():
|
for group, subgroups in self.groups.items():
|
||||||
result += (b'module ' + group.replace('-', 'minus').encode() + b'() {\n' +
|
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' +
|
for subgroup in subgroups) + b'\n' +
|
||||||
b'}\n')
|
b'}\n')
|
||||||
result += b'\n'
|
result += b'\n'
|
||||||
|
|
|
@ -111,7 +111,7 @@ class MapRenderer:
|
||||||
scale = (bottom - min_altitude) / int(0.7 * 1000)
|
scale = (bottom - min_altitude) / int(0.7 * 1000)
|
||||||
offset = min_altitude - bottom * scale
|
offset = min_altitude - bottom * scale
|
||||||
engine.add_geometry(altitudearea.geometry.fit(scale=scale, offset=offset).filter(top=False),
|
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
|
# 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue