Skip to content

Instantly share code, notes, and snippets.

@simmsb
Created December 22, 2021 08:09
Show Gist options
  • Save simmsb/3c3d34d54e3b6bacb20bd659a3c10641 to your computer and use it in GitHub Desktop.
Save simmsb/3c3d34d54e3b6bacb20bd659a3c10641 to your computer and use it in GitHub Desktop.
import pymesh
rules = """
""".strip().splitlines()
def parse_rule(r: str):
on, c = r.split(" ")
on = on == "on"
ranges = c.split(",")
ranges = tuple([tuple(tuple(int(n) for n in g.split("=")[1].split(".."))) for g in ranges])
return on, ranges
rules = [parse_rule(l) for l in rules]
def rule_to_csg(rule):
_, (xr, yr, zr) = rule
return pymesh.generate_box_mesh((xr[0], yr[0], zr[0]), (xr[1] + 1, yr[1] + 1, zr[1] + 1))
it = iter(rules)
initial = rule_to_csg(next(it))
for rule in it:
mesh = rule_to_csg(rule)
if mesh is None:
continue
if rule[0]:
initial = pymesh.boolean(initial, mesh, operation="union", engine="igl")
else:
initial = pymesh.boolean(initial, mesh, operation="difference", engine="igl")
pymesh.save_mesh("lol.obj", initial)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment