1
Fork 0

Added translate option to scad

This commit is contained in:
Edgar P. Burkhart 2022-03-04 13:20:44 +01:00
parent 764e2cc5bc
commit 9a165d5a54
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
3 changed files with 12 additions and 5 deletions

View file

@ -4,5 +4,6 @@ npz_out=../swash/inp_post
[bathy] [bathy]
bathy=../swash/data/bathyhires.dat bathy=../swash/data/bathyhires.dat
hstru=../swash/data/Hstru.dat hstru=../swash/data/Hstru.dat
scale=[0.5,10,1] scale=[0.5,1,1]
translate=[-150,0,0]
out=out_bathy out=out_bathy

View file

@ -28,10 +28,12 @@ out.mkdir(exist_ok=True)
stl_from_1d( stl_from_1d(
bathy, bathy,
out.joinpath("bathy.stl"), out.joinpath("bathy.stl"),
config.get("bathy", "scale"), config.get("bathy", "scale", fallback=[1,1,1]),
config.get("bathy", "translate", fallback=[0,0,0]),
) )
stl_from_1d( stl_from_1d(
poro, poro,
out.joinpath("poro.stl"), out.joinpath("poro.stl"),
config.get("bathy", "scale"), config.get("bathy", "scale", fallback=[1,1,1]),
config.get("bathy", "translate", fallback=[0,0,0]),
) )

View file

@ -6,12 +6,16 @@ import tempfile
import numpy as np import numpy as np
def stl_from_1d(data, output, scale=[1, 1, 1]): def stl_from_1d(data, output, scale=[1, 1, 1], translate=[0, 0, 0]):
with tempfile.TemporaryDirectory() as tmppath: with tempfile.TemporaryDirectory() as tmppath:
tmpdir = pathlib.Path(tmppath) tmpdir = pathlib.Path(tmppath)
np.savetxt(tmpdir.joinpath("data.dat"), np.stack((data, data))) np.savetxt(tmpdir.joinpath("data.dat"), np.stack((data, data)))
with open(tmpdir.joinpath("scad"), "wt") as scad: with open(tmpdir.joinpath("scad"), "wt") as scad:
scad.write(f"""scale({scale})surface("data.dat");""") scad.write(
f"translate({translate})"
f"scale({scale})"
f"""surface("data.dat");"""
)
subprocess.run(("openscad", "scad", "-o", "data.stl"), cwd=tmpdir) subprocess.run(("openscad", "scad", "-o", "data.stl"), cwd=tmpdir)