Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.2

0.11.2 / tests / editor / subdivision_display_tests.luc

## Subdivision in the editor: the Subdivision node marks the mesh (the cage
## flows on unchanged), the display is its limit surface, and a Crease node
## sharpens edges; Edit on top keeps editing the cage.
from workspace import Workspace
from luce_geocore.geocore import Subdivision
from network import Network
import node_commands

pub func subdivision_display_tests() -> unit!:
    let graph = Network()
    let cube = graph.add("Cube", 0.0, 0.0)
    let crease = graph.add("Crease", 0.0, 100.0)
    graph.connect(cube.id, crease.id, 0)
    crease.texts[0] = "p0-1"
    let subdivision = graph.add("Subdivision", 0.0, 200.0)
    graph.connect(crease.id, subdivision.id, 0)
    let cage = graph.evaluate(subdivision.id)
    assert(cage.face_count() == 6 and cage.point_count() == 8)
    assert(Subdivision.level(cage) == 2)
    let shown = Subdivision.display(cage)
    assert(shown.face_count() == 96 and shown.find_attribute("N", 0) >= 0)
    # The creased edge pulls the surface toward it: its middle (edge point
    # 8 + edge, which keeps its id as a limit point) stays nearer the cage
    # edge than without the crease.
    let plain = graph.add("Subdivision", 200.0, 200.0)
    graph.connect(cube.id, plain.id, 0)
    let smooth = Subdivision.display(graph.evaluate(plain.id))
    let edge = cage.find_edge(0, 1)
    let middle = cage.point(0).add(cage.point(1)).multiply_scalar(0.5)
    let creased_gap = shown.point(8 + edge).subtract(middle).length()
    let smooth_gap = smooth.point(8 + edge).subtract(middle).length()
    assert(creased_gap < smooth_gap * 0.5 and smooth_gap > 0.01)
    # Edit downstream edits the cage (display flows from the attributes).
    let w = Workspace()
    node_commands.delete_selected(w)
    node_commands.add_node(w, "Cube", 0.0, 0.0)
    node_commands.add_node(w, "Subdivision", 0.0, 100.0)
    node_commands.add_node(w, "Edit Mesh", 0.0, 200.0)
    let edited = w.geometry else trap("geometry")
    assert(edited.face_count() == 6 and Subdivision.level(edited) == 2)
    print("PASS subdivision in the editor: Subdivision and Crease nodes, limit display, Edit on the cage")