28 lines
903 B
Python
28 lines
903 B
Python
from build123d import Plane, Pos, Text, extrude
|
|
|
|
|
|
def validate(context, target, params):
|
|
errors = []
|
|
if target is None:
|
|
errors.append("NO_TARGET: text_emboss 需要一个实体作为输入")
|
|
return errors
|
|
|
|
|
|
def run(context, target, params):
|
|
bbox = target.bounding_box()
|
|
top_z = bbox.max.Z
|
|
depth = params["depth"]
|
|
|
|
if params["mode"] == "emboss":
|
|
txt_sketch = Plane.XY.offset(top_z) * (
|
|
Pos(params["x_offset"], params["y_offset"], 0) * Text(params["text"], font_size=params["font_size"])
|
|
)
|
|
solid = extrude(txt_sketch, amount=depth)
|
|
return target + solid
|
|
else:
|
|
txt_sketch = Plane.XY.offset(top_z - depth) * (
|
|
Pos(params["x_offset"], params["y_offset"], 0) * Text(params["text"], font_size=params["font_size"])
|
|
)
|
|
cutter = extrude(txt_sketch, amount=depth)
|
|
return target - cutter
|