dymokomi/luced-3d
Source of release 0.11.8
0.11.8 / tools / preview_history.luc
## Stages 7 and 8's captures for preview.py (docs/research/FUSION-CAD-UX.md):
## the Modify features as nodes, and the timeline strip.
## modify_shell: a box's top selected, Modify › Shell: the Shell node
## with its Inside arrow and value box, its rows.
## modify_face_menu: that top right-clicked: Sketch on face, Extrude face,
## Press Pull and the Modify features.
## modify_marking: that top, S held: the S marking menu with them.
## modify_combine: the box and a copy 10 along X, Combine waiting for its
## tool bodies: the target lit, the node waiting with no badge.
## modify_move: the box moved and turned by a Move node (Free move): its
## arrows and rings at the pivot, turned with the body, its rows.
## modify_split_face: the box's top split by the YZ plane, the piece on
## +X selected at the Faces level.
## modify_split_edge: the same split with nothing selected: the edge
## between the pieces drawn.
## timeline_strip: Sketch → Extrude → Fillet → Shell, the strip along the
## Network panel, the Fillet selected.
## timeline_rolled: the marker rolled back to the Extrude: the features
## after it dimmed.
## timeline_refused: the Fillet dragged before the Extrude: refused, the
## reason in the status line.
import preview_support
from luce_ui.ui import Event
from luce_window.input import EventKind, Key
from luce_3d.graphics import Vector3
from luce_cad.cad_geometry import CadGeometry
from luce_cad.modeling import CadModeling
from app import Luce3D
from view_projection import project
import node_commands
import sketch_commands
import selection_commands
import cad_chain
import cad_moves
import edit_cad_faces
pub func scenes() -> list[str]:
return ["modify_shell", "modify_face_menu", "modify_marking", "modify_combine", "modify_move", "modify_split_face", "modify_split_edge", "timeline_strip", "timeline_rolled", "timeline_refused"]
func look(editor: Luce3D, yaw: float, pitch: float, distance: float, target: Vector3) -> unit!:
let w = editor.workspace
w.view.yaw = yaw
w.view.pitch = pitch
w.view.distance = distance
w.view.target = target
w.view.update_camera()
## A CAD node entered, holding a 20 mm Solid Box; its id.
func box(editor: Luce3D) -> int!:
let w = editor.workspace
node_commands.delete_selected(w)
node_commands.add_node(w, "CAD", 40.0, 40.0)
node_commands.enter_group(w, w.network.selected)
node_commands.add_node(w, "Solid Box", 40.0, 40.0)
return w.network.selected
## The face of the displayed body whose polygons `keep` takes, selected
## at the Faces level.
func select_face(editor: Luce3D, keep: func(Vector3, Vector3) -> bool) -> unit!:
let w = editor.workspace
editor.panels.refresh()
selection_commands.set_mode(w, w.level_of(2))
let mesh = preview_support.shown(w) else trap("pick geometry")
for polygon in 0..<mesh.face_count():
if keep(mesh.face_center(polygon), mesh.face_normal(polygon)):
selection_commands.choose_component(w, polygon, false)
return
func top(c: Vector3, n: Vector3) -> bool:
return n.y > 0.99
## The first face name of node `id`'s first body facing `normal`.
func facing(editor: Luce3D, id: int, normal: Vector3, model: int = 0) -> str!:
let body = CadGeometry.model(preview_support.cooked(editor.workspace, id).geometry, model)
for face in 0..<body.face_count():
let name = CadModeling.face_name_of(body, face)
let at = CadModeling.face_point(body, name)
if at.found and at.normal.dot(normal) > 0.999:
return name
return ""
## Sketch → Extrude → Fillet (its uprights) → Shell (the top open): the
## nodes' ids.
func history(editor: Luce3D) -> list[int]!:
let w = editor.workspace
node_commands.delete_selected(w)
node_commands.add_node(w, "CAD", 40.0, 40.0)
node_commands.enter_group(w, w.network.selected)
node_commands.add_node(w, "Sketch", 40.0, 40.0)
node_commands.set_parameter(w, 0, 1.0)
node_commands.set_text(w, 0, sketch_commands.rectangle_text(0.0, 0.0, 30.0, 20.0))
let sketch = w.network.selected
node_commands.add_node(w, "Extrude", 40.0, 130.0)
node_commands.set_parameter(w, 0, 15.0)
let extrude = w.network.selected
let body = CadGeometry.model(preview_support.cooked(w, extrude).geometry, 0)
node_commands.add_node(w, "Fillet", 40.0, 220.0)
# The uprights: edges between two side faces.
let uprights: list[int] = []
for edge in 0..<body.edge_count():
let reference = CadModeling.edge_references(body, [edge])
if not reference.contains("start") and not reference.contains("end"):
uprights.append(edge)
node_commands.set_text(w, 0, CadModeling.edge_references(body, uprights))
node_commands.set_parameter(w, 0, 3.0)
let fillet = w.network.selected
node_commands.add_node(w, "Shell", 40.0, 310.0)
node_commands.set_text(w, 0, facing(editor, extrude, Vector3(0.0, 1.0, 0.0)))
let shell = w.network.selected
w.network.set_display(shell)
return [sketch, extrude, fillet, shell]
## Scene `scene` before its first frame.
pub func setup(editor: Luce3D, scene: str) -> unit!:
let w = editor.workspace
if scene in ["modify_shell", "modify_face_menu", "modify_marking"]:
_ = box(editor)
look(editor, 0.5, 0.6, 75.0, Vector3())
select_face(editor, top)
if scene == "modify_shell":
editor.panels.actions.refresh()
let shell = editor.panels.actions.command("Shell") else trap("Shell")
shell.trigger()
node_commands.set_parameter(w, edit_cad_faces.thickness_slot, 2.0)
elif scene == "modify_combine":
let solid = box(editor)
node_commands.add_node(w, "Move", 40.0, 130.0)
node_commands.set_text(w, 0, facing(editor, solid, Vector3(0.0, 1.0, 0.0)))
node_commands.set_parameter(w, cad_moves.type_slot, 1.0)
node_commands.set_parameter(w, 0, 12.0)
node_commands.set_parameter(w, 2, 6.0)
node_commands.set_parameter(w, cad_moves.copy_slot, 1.0)
look(editor, 0.5, 0.55, 95.0, Vector3(6.0, 0.0, 3.0))
w.selection = none
editor.panels.refresh()
editor.panels.actions.refresh()
let combine = editor.panels.actions.command("Combine") else trap("Combine")
combine.trigger()
editor.panels.refresh()
# The target: the first box, clicked.
let mesh = preview_support.shown(w) else trap("pick geometry")
for polygon in 0..<mesh.face_count():
if mesh.face_center(polygon).x < -9.9:
selection_commands.choose_component(w, polygon, false)
break
elif scene == "modify_move":
let solid = box(editor)
node_commands.add_node(w, "Move", 40.0, 130.0)
node_commands.set_text(w, 0, facing(editor, solid, Vector3(0.0, 1.0, 0.0)))
node_commands.set_parameter(w, 0, 8.0)
node_commands.set_parameter(w, 3, 15.0)
node_commands.set_parameter(w, 4, 30.0)
look(editor, 0.5, 0.55, 90.0, Vector3(6.0, 0.0, 0.0))
elif scene in ["modify_split_face", "modify_split_edge"]:
let solid = box(editor)
node_commands.add_node(w, "Split Face", 40.0, 130.0)
node_commands.set_text(w, 0, facing(editor, solid, Vector3(0.0, 1.0, 0.0)))
node_commands.set_parameter(w, edit_cad_faces.split_tool_slot, 3.0)
look(editor, 0.5, 0.6, 75.0, Vector3())
let piece = func (c: Vector3, n: Vector3) -> bool:
return n.y > 0.99 and c.x > 1.0
if scene == "modify_split_face":
select_face(editor, piece)
elif scene in ["timeline_strip", "timeline_rolled", "timeline_refused"]:
let ids = history(editor)
look(editor, 0.6, 0.55, 90.0, Vector3(0.0, 7.0, 0.0))
node_commands.select_node(w, ids[2])
if scene == "timeline_rolled":
cad_chain.roll_to(w, 1)
if scene == "timeline_refused":
_ = cad_chain.reorder(w, 2, 1)
editor.panels.refresh()
## Frame `frame` of scene `scene` (from 2; `last` is the frame captured).
pub func act(editor: Luce3D, scene: str, frame: int, last: int) -> unit!:
let w = editor.workspace
let area = editor.panels.view.layout().bounds()
if frame != last - 1:
return
if scene in ["modify_face_menu", "modify_marking"]:
let at = project(w, Vector3(-4.0, 10.0, 4.0), area.width, area.height)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = area.x + at[0], y = area.y + at[1]))
if scene == "modify_marking":
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.s))
else:
for kind in [EventKind.pointer_down, EventKind.pointer_up]:
editor.app.dispatch(Event(kind = kind, x = area.x + at[0], y = area.y + at[1], button = 1))
if scene in ["timeline_strip", "timeline_rolled"]:
# The pointer over the Fillet's icon: its name shows.
let strip = editor.panels.cad_timeline.layout().bounds()
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = strip.x + 102.0 + 2.0 * 30.0 + 12.0, y = strip.y + strip.height * 0.5))