Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions selectric_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pymeshlab as ml
import os
import subprocess
import concurrent.futures

from glyph_tables import typeball

Expand All @@ -23,24 +24,38 @@
if not os.path.exists("ballparts"):
os.mkdir("ballparts")

glyphs = []
# Process each glyph in sequence
for case, hemisphere in enumerate(typeball):
for row, line in enumerate(hemisphere):
for column, glyph in enumerate(line):
# Skip this entry if no glyph is provided; otherwise, make an STL with OpenSCAD
if glyph=="": continue
filename = f"ballparts/{row}-{column}-{case}.STL"
# Generate an extruded letter using OpenSCAD
# Pass the glyph's unicode codepoint(s) instead of the glyph itself, which I hope makes this more cross-compatible
codepoints = [ord(x) for x in glyph]
codepoints = str(codepoints).replace(" ","")
cmd = f"\"{PATH_TO_OPENSCAD}\" -o \"{filename}\" -D codepoints={codepoints} -D row={row} -D column={column} -D case={case} oneletter.scad"
print(f"Generating glyph {glyph}...")
subprocess.run(cmd)
mainMeshSet.load_new_mesh(filename)
mainMeshSet.generate_by_merging_visible_meshes()
mainMeshSet.save_current_mesh("ballparts/textForTypeball.STL")
print(f"Glyph {glyph} complete.")
with concurrent.futures.ThreadPoolExecutor() as executor:
for case, hemisphere in enumerate(typeball):
for row, line in enumerate(hemisphere):
for column, glyph in enumerate(line):
# Skip this entry if no glyph is provided; otherwise, make an STL with OpenSCAD
if glyph=="": continue
filename = f"ballparts/{row}-{column}-{case}.STL"
# Generate an extruded letter using OpenSCAD
# Pass the glyph's unicode codepoint(s) instead of the glyph itself, which I hope makes this more cross-compatible
codepoints = [ord(x) for x in glyph]
codepoints = str(codepoints).replace(" ","")
cmd = f"\"{PATH_TO_OPENSCAD}\" -o \"{filename}\" -D codepoints={codepoints} -D row={row} -D column={column} -D case={case} oneletter.scad"
print(f"Generating glyph {glyph}...")
future = executor.submit(subprocess.run, cmd, shell=True)
glyphs.append({
"filename": filename,
"task": future,
"glyph": glyph
})


for glyph in glyphs:
while not glyph["task"].done():
print("waiting...")

mainMeshSet.load_new_mesh(glyph["filename"])
mainMeshSet.generate_by_merging_visible_meshes()
mainMeshSet.save_current_mesh("ballparts/textForTypeball.STL")
symbol = glyph["glyph"]
print(f"Glyph {symbol} complete.")

# Once all glyphs are processed, put them onto the typeball body
print("Attaching glyphs to typeball body...")
Expand Down