diff --git a/src/b1scad/scad2py.py b/src/b1scad/scad2py.py index 7d6a594..f76969e 100644 --- a/src/b1scad/scad2py.py +++ b/src/b1scad/scad2py.py @@ -55,11 +55,11 @@ def shape_set(self, t): @_('CUBE LPAREN vector RPAREN') def shape(self, p): - return f"self.api.box({p.vector})" + return f"self.api.box({p.vector}, center=False)" @_('CUBE LPAREN NUMBER RPAREN') def shape(self, p): - return f"self.api.box({p.NUMBER},{p.NUMBER},{p.NUMBER})" + return f"self.api.box({p.NUMBER},{p.NUMBER},{p.NUMBER}, center=False)" @_('SPHERE LPAREN NUMBER RPAREN') def shape(self, p): diff --git a/src/pylele/api/bpy.py b/src/pylele/api/bpy.py index 5298dbd..78fdda1 100644 --- a/src/pylele/api/bpy.py +++ b/src/pylele/api/bpy.py @@ -93,8 +93,11 @@ def add_material(obj: bpy.types.Object, name: str, color: tuple[int, int, int]): def sphere(self, rad: float) -> BlenderShape: return BlenderBall(rad, self) - def box(self, ln: float, wth: float, ht: float) -> BlenderShape: - return BlenderBox(ln, wth, ht, self) + def box(self, ln: float, wth: float, ht: float, center: bool = True) -> BlenderShape: + retval = BlenderBox(ln, wth, ht, self) + if center: + return retval + return retval.mv(-l / 2, -wth / 2, -ht / 2) def cone_x(self, l: float, r1: float, r2: float) -> BlenderShape: return BlenderConeX(l, r1, r2, self).mv(l / 2, 0, 0) diff --git a/src/pylele/api/cq.py b/src/pylele/api/cq.py index 5771112..c6f1837 100644 --- a/src/pylele/api/cq.py +++ b/src/pylele/api/cq.py @@ -73,8 +73,11 @@ def export_best_multishapes( def sphere(self, rad: float) -> CQShape: return CQBall(rad, self) - def box(self, ln: float, wth: float, ht: float) -> CQShape: - return CQBox(ln, wth, ht, self) + def box(self, ln: float, wth: float, ht: float, center: bool = True) -> CQShape: + retval = CQBox(ln, wth, ht, self) + if center: + return retval + return retval.mv(ln/2,wth/2,ht/2) def cone_x(self, l: float, r1: float, r2: float) -> CQShape: return CQCone(l, r1, r2, (1, 0, 0), self) diff --git a/src/pylele/api/mf.py b/src/pylele/api/mf.py index 076ffce..ef283d4 100644 --- a/src/pylele/api/mf.py +++ b/src/pylele/api/mf.py @@ -102,8 +102,8 @@ def export(self, shape: MFShape, path: Union[str, Path],fmt=".stl") -> None: def sphere(self, rad: float) -> MFShape: return MFBall(rad, self) - def box(self, l: float, wth: float, ht: float) -> MFShape: - return MFBox(l, wth, ht, self) + def box(self, l: float, wth: float, ht: float, center: bool = True) -> MFShape: + return MFBox(l, wth, ht, center, self) def cone_x(self, l: float, r1: float, r2: float) -> MFShape: return MFConeZ(l, r1, r2, None, self).rotate_y(90) @@ -240,12 +240,14 @@ def __init__(self, rad: float, api: MFShapeAPI): class MFBox(MFShape): - def __init__(self, l: float, wth: float, ht: float, api: MFShapeAPI): + def __init__(self, l: float, wth: float, ht: float, center: bool, api: MFShapeAPI ): super().__init__(api) self.ln = l self.wth = wth self.ht = ht - self.solid = Manifold.cube((l, wth, ht)).translate((-l / 2, -wth / 2, -ht / 2)) + self.solid = Manifold.cube((l, wth, ht)) + if center: + self.solid = self.solid.translate((-l / 2, -wth / 2, -ht / 2)) class MFConeZ(MFShape): diff --git a/src/pylele/api/mock.py b/src/pylele/api/mock.py index f9ff474..bfcbdfc 100644 --- a/src/pylele/api/mock.py +++ b/src/pylele/api/mock.py @@ -29,7 +29,7 @@ def export_best(self, shape: MockShape, path: Union[str, Path]) -> None: def sphere(self, rad: float) -> MockShape: return MockShape(self) - def box(self, l: float, wth: float, ht: float) -> MockShape: + def box(self, l: float, wth: float, ht: float, center: bool = True) -> MockShape: return MockShape(self) def cone_x(self, l: float, r1: float, r2: float) -> MockShape: diff --git a/src/pylele/api/sp2.py b/src/pylele/api/sp2.py index 43c5e29..d3c540d 100644 --- a/src/pylele/api/sp2.py +++ b/src/pylele/api/sp2.py @@ -71,8 +71,11 @@ def export_scad(self, shape: Sp2Shape, path: Union[str, Path]) -> str: def sphere(self, rad: float) -> Sp2Shape: return Sp2Ball(rad, self) - def box(self, l: float, wth: float, ht: float) -> Sp2Shape: - return Sp2Box(l, wth, ht, self).mv(-l / 2, -wth / 2, -ht / 2) + def box(self, l: float, wth: float, ht: float, center: bool = True) -> Sp2Shape: + retval = Sp2Box(l, wth, ht, self). + if center: + return retval.mv(-l / 2, -wth / 2, -ht / 2) + return retval def cone_x(self, l: float, r1: float, r2: float) -> Sp2Shape: return Sp2Cone(l, r1, r2, direction="X", sides=None, api=self).mv(l / 2, 0, 0) diff --git a/src/pylele/api/tm.py b/src/pylele/api/tm.py index ef78c72..e24b22a 100644 --- a/src/pylele/api/tm.py +++ b/src/pylele/api/tm.py @@ -75,8 +75,11 @@ def export_best_multishapes( def sphere(self, rad: float) -> TMShape: return TMBall(rad, self) - def box(self, l: float, wth: float, ht: float) -> TMShape: - return TMBox(l, wth, ht, self) + def box(self, l: float, wth: float, ht: float, center: bool = True) -> TMShape: + retval = TMBox(l, wth, ht, self) + if center: + return retval + return retval.mv(-l / 2, -wth / 2, -ht / 2) def cone_x(self, l: float, r1: float, r2: float) -> TMShape: return TMCone(l, r1, r2, None, self.rotZtoX, self)