Skip to content

Commit

Permalink
README updates, extract module dimensions and panel dimensions, attem…
Browse files Browse the repository at this point in the history
…pt including them in readme
  • Loading branch information
scottbez1 committed Jun 13, 2024
1 parent bd32f5d commit 8a89491
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 62 deletions.
75 changes: 56 additions & 19 deletions .github/workflows/3d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,75 @@ jobs:
- name: Install dependencies
run: ./3d/scripts/dependencies.sh

- name: Generate 2d output
- name: 'Generate 2d output :: 52 flap :: generic'
run: |
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python -u 3d/scripts/generate_2d.py --render-raster
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector.svg
cp 3d/build/laser_parts/raster.png 3d/build/outputs/3d_laser_raster.png
./scripts/annotate_image.sh 3d/build/outputs/3d_laser_raster.png
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python -u 3d/scripts/generate_2d.py --calculate-dimensions --render-raster
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-52.svg
cp 3d/build/laser_parts/raster.png 3d/build/outputs/3d_laser_raster-52.png
./scripts/annotate_image.sh 3d/build/outputs/3d_laser_raster-52.png
cp 3d/build/laser_parts/combined_module_dimensions.svg 3d/build/outputs/3d_laser_vector-52-module_dimensions.svg
- name: Generate 2d output (Ponoko 3mm MDF)
- name: 'Generate 2d output :: 52 flap :: Ponoko 3mm MDF)'
run: |
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python3 -u 3d/scripts/generate_2d.py --calculate-dimensions --kerf-preset ponoko-3mm-mdf
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-ponoko-3mm-mdf_1x.svg
cp 3d/build/laser_parts/combined_dimensions.txt 3d/build/outputs/3d_laser_vector-ponoko-3mm-mdf_1x_dimensions.txt
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-52-ponoko-3mm-mdf_1x.svg
cp 3d/build/laser_parts/combined_panel_dimensions.svg 3d/build/outputs/3d_laser_vector-52-ponoko-3mm-mdf_1x_dimensions.svg
- name: Generate 2d output (Ponoko 3mm Acrylic)
- name: 'Generate 2d output :: 52 flap :: Ponoko 3mm Acrylic'
run: |
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python3 -u 3d/scripts/generate_2d.py --calculate-dimensions --kerf-preset ponoko-3mm-acrylic
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-ponoko-3mm-acrylic_1x.svg
cp 3d/build/laser_parts/combined_dimensions.txt 3d/build/outputs/3d_laser_vector-ponoko-3mm-acrylic_1x_dimensions.txt
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-52-ponoko-3mm-acrylic_1x.svg
cp 3d/build/laser_parts/combined_panel_dimensions.svg 3d/build/outputs/3d_laser_vector-52-ponoko-3mm-acrylic_1x_dimensions.svg
- name: Generate 2d output (Elecrow 3mm Wood)
- name: 'Generate 2d output :: 52 flap :: Elecrow 3mm Wood'
run: |
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python3 -u 3d/scripts/generate_2d.py --kerf-preset elecrow-3mm-wood --render-elecrow
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-elecrow-3mm-wood_1x.svg
cp 3d/build/laser_parts/combined_dimensions.txt 3d/build/outputs/3d_laser_vector-elecrow-3mm-wood_1x_dimensions.txt
cp 3d/build/laser_parts/elecrow.zip 3d/build/outputs/3d_laser_vector-elecrow-3mm-wood_1x.zip
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-52-elecrow-3mm-wood_1x.svg
cp 3d/build/laser_parts/combined_panel_dimensions.svg 3d/build/outputs/3d_laser_vector-52-elecrow-3mm-wood_1x_dimensions.svg
cp 3d/build/laser_parts/elecrow.zip 3d/build/outputs/3d_laser_vector-52-elecrow-3mm-wood_1x.zip
- name: Generate 2d output (Elecrow 3mm Acrylic)
- name: 'Generate 2d output :: 52 flap :: Elecrow 3mm Acrylic'
run: |
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python3 -u 3d/scripts/generate_2d.py --kerf-preset elecrow-3mm-acrylic --render-elecrow
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-elecrow-3mm-acrylic_1x.svg
cp 3d/build/laser_parts/combined_dimensions.txt 3d/build/outputs/3d_laser_vector-elecrow-3mm-acrylic_1x_dimensions.txt
cp 3d/build/laser_parts/elecrow.zip 3d/build/outputs/3d_laser_vector-elecrow-3mm-acrylic_1x.zip
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-52-elecrow-3mm-acrylic_1x.svg
cp 3d/build/laser_parts/combined_panel_dimensions.svg 3d/build/outputs/3d_laser_vector-52-elecrow-3mm-acrylic_1x_dimensions.svg
cp 3d/build/laser_parts/elecrow.zip 3d/build/outputs/3d_laser_vector-52-elecrow-3mm-acrylic_1x.zip
- name: 'Generate 2d output :: 40 flap :: generic'
run: |
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python -u 3d/scripts/generate_2d.py --calculate-dimensions --render-raster --num-flaps 40
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-40.svg
cp 3d/build/laser_parts/raster.png 3d/build/outputs/3d_laser_raster-40.png
./scripts/annotate_image.sh 3d/build/outputs/3d_laser_raster-40.png
cp 3d/build/laser_parts/combined_module_dimensions.svg 3d/build/outputs/3d_laser_vector-40-module_dimensions.svg
- name: 'Generate 2d output :: 40 flap :: Ponoko 3mm MDF)'
run: |
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python3 -u 3d/scripts/generate_2d.py --calculate-dimensions --kerf-preset ponoko-3mm-mdf --num-flaps 40
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-40-ponoko-3mm-mdf_1x.svg
cp 3d/build/laser_parts/combined_panel_dimensions.svg 3d/build/outputs/3d_laser_vector-40-ponoko-3mm-mdf_1x_dimensions.svg
- name: 'Generate 2d output :: 40 flap :: Ponoko 3mm Acrylic'
run: |
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python3 -u 3d/scripts/generate_2d.py --calculate-dimensions --kerf-preset ponoko-3mm-acrylic --num-flaps 40
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-40-ponoko-3mm-acrylic_1x.svg
cp 3d/build/laser_parts/combined_panel_dimensions.svg 3d/build/outputs/3d_laser_vector-40-ponoko-3mm-acrylic_1x_dimensions.svg
- name: 'Generate 2d output :: 40 flap :: Elecrow 3mm Wood'
run: |
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python3 -u 3d/scripts/generate_2d.py --kerf-preset elecrow-3mm-wood --render-elecrow --num-flaps 40
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-40-elecrow-3mm-wood_1x.svg
cp 3d/build/laser_parts/combined_panel_dimensions.svg 3d/build/outputs/3d_laser_vector-40-elecrow-3mm-wood_1x_dimensions.svg
cp 3d/build/laser_parts/elecrow.zip 3d/build/outputs/3d_laser_vector-40-elecrow-3mm-wood_1x.zip
- name: 'Generate 2d output :: 40 flap :: Elecrow 3mm Acrylic'
run: |
xvfb-run --auto-servernum --server-args "-screen 0 1024x768x24" python3 -u 3d/scripts/generate_2d.py --kerf-preset elecrow-3mm-acrylic --render-elecrow --num-flaps 40
cp 3d/build/laser_parts/combined.svg 3d/build/outputs/3d_laser_vector-40-elecrow-3mm-acrylic_1x.svg
cp 3d/build/laser_parts/combined_panel_dimensions.svg 3d/build/outputs/3d_laser_vector-40-elecrow-3mm-acrylic_1x_dimensions.svg
cp 3d/build/laser_parts/elecrow.zip 3d/build/outputs/3d_laser_vector-40-elecrow-3mm-acrylic_1x.zip
- name: Generate animated gif
run: |
Expand Down
18 changes: 14 additions & 4 deletions 3d/scripts/generate_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'Inkscape)')
parser.add_argument('--calculate-dimensions', action='store_true', help='Calculate overall cut file dimensions ('
'requires Inkscape)')
parser.add_argument('--num-flaps', type=int, help='Override NUM_FLAPS')
parser.add_argument('--thickness', type=float, help='Override panel thickness value')
parser.add_argument('--no-etch', action='store_true', help='Do not render laser-etched features')
parser.add_argument('--mirror', action='store_true', help='Mirror the assembly so the outside faces are facing up. '
Expand Down Expand Up @@ -106,12 +107,15 @@
extra_variables['kerf_width'] = KERF_PRESETS[args.kerf_preset]
if args.thickness is not None:
extra_variables['thickness'] = args.thickness
if args.num_flaps is not None:
extra_variables['num_flaps'] = args.num_flaps

print('Variables:\n' + json.dumps(extra_variables, indent=4))

renderer = Renderer(os.path.join(source_parts_dir, 'splitflap.scad'), laser_parts_directory, extra_variables)
renderer.clean()
svg_output = renderer.render_svgs(panelize_quantity=args.panelize)
svg_output, output_data = renderer.render_svgs(panelize_quantity=args.panelize)
logging.debug(f'Output data: {output_data}')

processor = SvgProcessor(svg_output)

Expand All @@ -124,6 +128,11 @@
logging.info(f'\n\n\nDone rendering to SVG: {svg_output}')

if args.calculate_dimensions:
DIMENSION_SVG_TEMPLATE = '<svg height="40" width="1280" xmlns="http://www.w3.org/2000/svg"><text x="4" y="32" fill="black" style="font-style:normal;font-variant:normal;font-weight:normal;font-size:28;line-height:1.25;font-family:sans-serif;">DIMENSIONS_PLACEHOLDER</text></svg>'
module_dimensions_file = os.path.join(laser_parts_directory, os.path.splitext(os.path.basename(svg_output))[0] + '_module_dimensions.svg')
with open(module_dimensions_file, 'w') as f:
f.write(DIMENSION_SVG_TEMPLATE.replace('DIMENSIONS_PLACEHOLDER', f'{output_data["enclosure_width"]}mm width, {output_data["enclosure_height"]}mm height, {output_data["enclosure_length"]}mm depth'))

svg_for_dimensions = os.path.join(laser_parts_directory, os.path.splitext(os.path.basename(svg_output))[0] + '_dimensions.svg')
processor.apply_dimension_calculation_style()
processor.write(svg_for_dimensions)
Expand All @@ -142,9 +151,10 @@
svg_for_dimensions,
]))
height_mm = height_px * 25.4 / 96 # Assuming 96dpi...
dimensions_file = os.path.join(laser_parts_directory, os.path.splitext(os.path.basename(svg_output))[0] + '_dimensions.txt')
with open(dimensions_file, 'w') as f:
f.write(f'{width_mm:.2f}mm x {height_mm:.2f}mm')

panel_dimensions_file = os.path.join(laser_parts_directory, os.path.splitext(os.path.basename(svg_output))[0] + '_panel_dimensions.svg')
with open(panel_dimensions_file, 'w') as f:
f.write(DIMENSION_SVG_TEMPLATE.replace('DIMENSIONS_PLACEHOLDER', f'{width_mm:.2f}mm x {height_mm:.2f}mm'))

if args.render_elecrow:
elecrow_svg = os.path.join(laser_parts_directory, 'elecrow.svg')
Expand Down
9 changes: 5 additions & 4 deletions 3d/scripts/projection_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _get_variables(self, variables):
v.update(variables)
return v

def _get_num_components(self):
def _get_extracted_outputs(self):
stdout, stderr = openscad.run(
self.input_file,
os.path.join(self.output_folder, 'dummy.png'),
Expand All @@ -59,7 +59,7 @@ def _get_num_components(self):
for key, value in outputs.items():
if key.startswith('debug_'):
logging.debug('DEBUG VALUE %r = %r', key, value)
return outputs['num_components']
return outputs

def _get_component_file(self, i):
return os.path.join(self.output_folder, 'component_%05d.svg' % i)
Expand Down Expand Up @@ -105,7 +105,8 @@ def _render_component(self, i, panel_horizontal, panel_vertical):

def render_svgs(self, panelize_quantity):
assert panelize_quantity == 1 or panelize_quantity % 2 == 0, 'Panelize quantity must be 1 or an even number'
num_components = int(self._get_num_components())
outputs = self._get_extracted_outputs()
num_components = int(outputs['num_components'])
logging.info('Found %d components to render', num_components)
svg_output = None

Expand All @@ -121,6 +122,6 @@ def render_svgs(self, panelize_quantity):
svg_output.import_paths(svg_processor)
output_file_path = os.path.join(self.output_folder, 'combined.svg')
svg_output.write(output_file_path)
return output_file_path
return output_file_path, outputs


2 changes: 1 addition & 1 deletion 3d/splitflap.scad
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ spool_joint_clearance = 0.10; // for the notched joints on the spool struts

character_list = get_character_list();
echo(character_list=len(character_list));
assert(len(character_list) == num_flaps, "WARNING: num_flaps and character_list mismatch!");
assert(len(character_list) == num_flaps || _is_projection_rendering, "WARNING: num_flaps and character_list mismatch!");
render_flap_index = undef;
render_string = is_undef(render_flap_index) ? render_message : character_list[render_flap_index];
render_units = len(render_string);
Expand Down
Loading

0 comments on commit 8a89491

Please sign in to comment.