@@ -40,6 +40,9 @@ class AbstractBaseNode:
4040 # All children nodes, initialized as tuple for compliance
4141 children = tuple ()
4242
43+ # Set to false to render scad directly instead of stls
44+ optimize = True
45+
4346 def __init__ (self , * args , name = None , ** kwargs ):
4447 # self.uniq_id uniquely identifies a set of parameters of an instance.
4548 # self.name is used to refer to nodes in tests
@@ -127,9 +130,14 @@ def assemble(self, root=None):
127130
128131 self .validate (rendered )
129132 self .model = self .as_scad (rendered )
133+ if not self .optimize :
134+ self .model = self ._colorize (self .model )
130135 self .generate_scad ()
131136
132- assembled = self .import_optimized ()
137+ if self .optimize :
138+ assembled = self .import_optimized ()
139+ else :
140+ assembled = self .model
133141
134142 for operation in self .operations :
135143 # Apply scad operation
@@ -143,8 +151,19 @@ def import_optimized(self):
143151 if self .rigid and self ._up_to_date (self .stl_file ):
144152 basedir = os .path .relpath (self .basedir , self .root )
145153 local_stl = os .path .join (basedir , self .local_stl )
146- return import_stl (local_stl )
147- return self .model
154+ imported_stl = import_stl (local_stl )
155+ return self ._colorize (imported_stl )
156+ return self ._colorize (self .model )
157+
158+ def _colorize (self , scad_code ):
159+ if self .color is None :
160+ return scad_code
161+ hex_code = self .color .lstrip ('#' )
162+ if len (hex_code ) != 6 :
163+ raise ValueError (f"Invalid self.color at { self } . "
164+ "It should be in the format #RRGGBB" )
165+ colors = [int (hex_code [i :i + 2 ], 16 ) / 255 for i in (0 , 2 , 4 )]
166+ return color (colors , 1 )(scad_code )
148167
149168 @property
150169 def stl (self ):
0 commit comments