dymokomi/luced-3d
Source of release 0.11.8
0.11.8 / src / tool_offset_face.luc
## Offset Face (Fusion 360's; Press Pull on faces): faces moved along their
## normals, tangent faces following, the faces around stretching or
## shrinking to meet them (luce-cad's CadDirect.offset_faces). The node
## keeps its faces by name; an Edit CAD step moves the faces picked. Both
## show the distance's arrow on the first face.
from luce_cad.cad_geometry import CadGeometry
from luce_cad.modeling import CadModeling, CadDirect
from luce_3d.graphics import Vector3
from tool_record import Tool, ToolEntry, Pick, Invocation
from geometry_data import GeometryData
from parameter_rows import Parameter, number
from handle_lines import HandleLine
from edit_types import face_level, patch_level
import handle_lines
import pick_kinds
import cad_cook
from luce_ui import ui
pub func entry() -> ToolEntry:
return ToolEntry("Offset Face", "Offset Face", "offset-face", "Modify", [cad_cook.context], [cad_cook.edit_kind], made)
func made() -> Tool:
return entry().tool("Modify", "Faces", "Move faces along their normals, tangent faces following", picks(), rows(), cook, drag = 0, handles = true, asks = true)
func picks() -> list[Pick]:
return [Pick("Faces", [face_level, patch_level], kind = pick_kinds.faces, slot = 0, needed = optional, button = "Pick faces",
doc = "The faces moved, kept by their names (Press Pull on faces of the body).")]
func optional(values: list[float], texts: list[str], wired: bool) -> bool:
return false
func cook(call: Invocation, data: GeometryData, tag: str) -> GeometryData!:
if not call.node:
return cad_cook.face_step(call, data, tag)
let body = cad_cook.body_of(data, "first")
if call.text(0).trim() == "":
error(ui.invalid, "Pick the faces to offset (Press Pull on a face of the body)")
let result = GeometryData(geometry = CadGeometry.of_model(CadDirect.offset_faces(body, call.text(0), call.number(0), true)))
let at = CadModeling.face_point(body, call.text(0).split(";")[0].trim())
if at.found:
result.handles = handle_lines.encode([HandleLine("arrow", 0, 1.0, at.point, at.normal, -1, Vector3())])
return result
func rows() -> list[Parameter]:
return [number("Distance", 0, 1.0, -100000.0, 100000.0, 0.5, "How far the faces move along their outward normals (negative: in); the faces around stretch or shrink to meet them, tangent ones following.", soft = 50.0)]