Added translate option to scad
This commit is contained in:
parent
764e2cc5bc
commit
9a165d5a54
3 changed files with 12 additions and 5 deletions
|
@ -4,5 +4,6 @@ npz_out=../swash/inp_post
|
|||
[bathy]
|
||||
bathy=../swash/data/bathyhires.dat
|
||||
hstru=../swash/data/Hstru.dat
|
||||
scale=[0.5,10,1]
|
||||
scale=[0.5,1,1]
|
||||
translate=[-150,0,0]
|
||||
out=out_bathy
|
||||
|
|
|
@ -28,10 +28,12 @@ out.mkdir(exist_ok=True)
|
|||
stl_from_1d(
|
||||
bathy,
|
||||
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(
|
||||
poro,
|
||||
out.joinpath("poro.stl"),
|
||||
config.get("bathy", "scale"),
|
||||
config.get("bathy", "scale", fallback=[1,1,1]),
|
||||
config.get("bathy", "translate", fallback=[0,0,0]),
|
||||
)
|
||||
|
|
|
@ -6,12 +6,16 @@ import tempfile
|
|||
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:
|
||||
tmpdir = pathlib.Path(tmppath)
|
||||
np.savetxt(tmpdir.joinpath("data.dat"), np.stack((data, data)))
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue