Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.7

0.11.7 / tools / preview_tutorial.luc

## Preview scenes of the end-to-end tutorial part (tests/editor/
## cad_tutorial_tests.luc builds it; preview.py copies that file and
## sketch_support.luc in):
##   tutorial_p<k>: the timeline build up to stage k (0 the XZ sketch with
##     its dimensions ... 11 Combine), the last node selected and shown.
##   tutorial_rolled: the marker rolled back to the first sketch, its width
##     made 70 (the strip's later features dimmed).
##   tutorial_forward: rolled forward again, everything downstream
##     following.
##   tutorial_d<k>: the Edit CAD build up to stage k (0 ... 9 Combine).
from app import Luce3D
from luce_3d.graphics import Vector3
from luce_cad.sketch import CadSketch
import node_commands
import sketch_commands
import cad_chain
import cad_tutorial_tests

pub func scenes() -> list[str]:
    let result: list[str] = []
    for k in 0..<cad_tutorial_tests.parametric_stages:
        result.append(f"tutorial_p{k}")
    for k in 0..<cad_tutorial_tests.direct_stages:
        result.append(f"tutorial_d{k}")
    return result + ["tutorial_rolled", "tutorial_forward"]

pub func setup(editor: Luce3D, scene: str) -> unit!:
    let w = editor.workspace
    if scene.starts_with("tutorial_d"):
        _ = cad_tutorial_tests.build_direct(editor, int(scene[10..<scene.length]))
        return
    if scene.starts_with("tutorial_p"):
        _ = cad_tutorial_tests.build_parametric(editor, int(scene[10..<scene.length]))
        return
    let built = cad_tutorial_tests.build_parametric(editor, cad_tutorial_tests.parametric_stages - 1)
    cad_chain.roll_to(w, 0)
    let text = w.network.require(built.ids[0]).texts[0]
    let dims = sketch_commands.dimensions(text)
    let s = CadSketch.parse(text)
    s.set_value(dims[0].constraint, 70.0)
    _ = s.solve()
    node_commands.select_node(w, built.ids[0])
    node_commands.set_text(w, 0, s.text())
    if scene == "tutorial_forward":
        cad_chain.roll_to(w, cad_chain.chain(w).length - 1)
        w.view.yaw = 0.6
        w.view.pitch = 0.7
        w.view.distance = 230.0
        w.view.target = Vector3(27.0, 10.0, 0.0)
        w.view.update_camera()

## The sketch editor's hint is not a failure (the capture traps on a
## notice): the first stage shows the sketch being edited.
pub func act(editor: Luce3D, scene: str, frame: int, last: int) -> unit!:
    _ = scene
    if frame == last - 1 and editor.workspace.notice.starts_with("Sketch:"):
        editor.workspace.notice = ""