dymokomi/luced-3d
Source of release 0.11.9
0.11.9 / src / edit_cad_surfaces.luc
## Surfacing Stage 3's tools (docs/research/SURFACING-ALIAS-PLASTICITY.md
## ยง7.1), each declared in its tool_<name>.luc (tool_project, tool_intersect,
## tool_trim, tool_untrim, tool_trim_convert, tool_shrink, tool_stitch,
## tool_unstitch): their verbs, the slots their numbers keep, and what their
## Edit CAD steps share (the faces or bodies a step picked, Trim's picks).
## surface_ops.luc does the work.
from luce_cad.cad_geometry import CadGeometry
from luce_cad.cad_edits import CadEdits
from luce_geocore.geocore import Mesh
from luce_3d.graphics import Vector3
from geometry_data import GeometryData
from edit_operations import EditStep
from tool_record import Invocation
import cad_cook
import surface_ops
from luce_ui import ui
pub let project_verb = "Project"
pub let intersect_verb = "Intersect"
pub let trim_verb = "Trim"
pub let untrim_verb = "Untrim"
pub let convert_verb = "Trim Convert"
pub let shrink_verb = "Shrink"
pub let stitch_verb = "Stitch"
pub let unstitch_verb = "Unstitch"
# -- The steps' numbers.
pub let along_slot = 0
pub let direction_slot = 1
pub let both_slot = 4
pub let original_slot = 5
pub let with_slot = 0
pub let origin_slot = 1
pub let normal_slot = 4
pub let both_faces_slot = 7
pub let mode_slot = 0
pub let show_slot = 1
## Alias's 3D Trimming: the curves on the face only, or curves off it cast
## along the direction or along the normals; faces picked after the first
## (or the node's cutting faces) cut it too with Intersect faces.
pub let cast_slot = 2
pub let cast_direction_slot = 3
pub let cutters_slot = 6
pub let extend_slot = 7
pub let count_slot = 8
## Trim's picks: count_slot of them, x y z each, from here.
pub let picks_slot = 9
pub let all_slot = 0
pub let degree_u_slot = 0
pub let degree_v_slot = 1
pub let spans_u_slot = 2
pub let spans_v_slot = 3
pub let swap_slot = 4
pub let keep_slot = 5
pub let gap_slot = 0
pub let periodic_slot = 1
pub let single_slot = 2
pub func trim_numbers() -> list[float]:
return [0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0]
## Project's starting numbers.
pub func project_numbers() -> list[float]:
return [0.0, 0.0, -1.0, 0.0, 1.0, 0.0]
## Trim's 3D Trimming and Extend options from its numbers.
pub func trim_options(v: list[float]) -> surface_ops.TrimOptions:
let start = trim_numbers()
let at = func (slot: int) -> float:
return v[slot] if v.length > slot else start[slot]
return surface_ops.TrimOptions(int(at(cast_slot)), Vector3(at(cast_direction_slot), at(cast_direction_slot + 1), at(cast_direction_slot + 2)), at(extend_slot) != 0.0)
## A Trim step's picks.
pub func picks_of(numbers: list[float]) -> list[Vector3]:
let found: list[Vector3] = []
if numbers.length <= count_slot:
return found
let count = int(numbers[count_slot])
for k in 0..<count:
let at = picks_slot + 3 * k
if at + 2 < numbers.length:
found.append(Vector3(numbers[at], numbers[at + 1], numbers[at + 2]))
return found
## Trim's numbers with `picks` in place of its picks.
pub func with_picks(numbers: list[float], picks: list[Vector3]) -> list[float]:
let start = trim_numbers()
var made: list[float] = []
for slot in 0..<count_slot:
made.append(numbers[slot] if numbers.length > slot else start[slot])
made.append(float(picks.length))
for p in picks:
made = made + [p.x, p.y, p.z]
return made
## The faces a step picked (`call`, an Edit CAD step), in the models'
## order: one at least.
pub func step_faces(call: Invocation, data: GeometryData) -> list[str]!:
cad_cook.needs_models(data)
let faces = picked_faces(cad_cook.step_of(call), data, cad_cook.shown(call, data))
if faces.length == 0:
error(ui.invalid, f"{call.verb}: pick a face at the Faces or Patch level")
return faces
## The bodies a step picked (`call`, at the Object level), by index: one at
## least.
pub func step_bodies(call: Invocation, data: GeometryData) -> list[int]!:
cad_cook.needs_models(data)
let mesh = cad_cook.shown(call, data)
let bodies: list[int] = []
for index in 0..<CadGeometry.model_count(data.geometry):
if CadEdits.model_share(mesh, call.group(), index) > 0:
bodies.append(index)
if bodies.length == 0:
error(ui.invalid, f"{call.verb}: pick bodies at the Object level")
return bodies
## The bodies a node names (one face's name each, apart by `;`), by index,
## each once.
pub func named_bodies(data: GeometryData, names: str) -> list[int]!:
let bodies: list[int] = []
for name in names.split(";"):
if name.trim() != "":
let body = surface_ops.body_with(data, name.trim())
if not (body in bodies):
bodies.append(body)
return bodies
## The names of the faces a step's group picked, in the models' order.
pub func picked_faces(step: EditStep, data: GeometryData, mesh: Mesh) -> list[str]!:
let found: list[str] = []
for index in 0..<CadGeometry.model_count(data.geometry):
let names = CadEdits.model_faces(mesh, step.group, index)
if names == "":
continue
for name in names.split(";"):
if name != "" and not (name in found):
found.append(name)
return found