dymokomi/luced-3d
Source of release 0.11.3
0.11.3 / tests / editor / name_node_tests.luc
## The Name node: the group's faces get a name attribute, which any Group
## field then picks by @name; here Assign Material binds the named faces.
from network import Network
## Face `face`'s text in attribute `name` ("" without it).
func face_text(graph: Network, id: int, name: str, face: int) -> str!:
let mesh = graph.evaluate(id)
let index = mesh.find_attribute(name, 2)
if index < 0:
return ""
return mesh.attribute_text(index, face)
pub func name_node_tests() -> unit!:
let graph = Network()
let cube = graph.nodes[0]
let named = graph.add("Name", 0.0, 100.0)
graph.connect(cube.id, named.id, 0)
named.texts[0] = "0-2"
named.texts[1] = "lid"
assert(face_text(graph, named.id, "name", 0) == "lid" and face_text(graph, named.id, "name", 5) == "")
# A second Name keeps the first's names on the faces it leaves.
let again = graph.add("Name", 0.0, 200.0)
graph.connect(named.id, again.id, 0)
again.texts[0] = "5"
again.texts[1] = "base"
assert(face_text(graph, again.id, "name", 1) == "lid" and face_text(graph, again.id, "name", 5) == "base")
# Materials by name.
let material = graph.add("Material", 300.0, 0.0)
let assign = graph.add("Assign Material", 0.0, 300.0)
graph.connect(again.id, assign.id, 0)
graph.connect(material.id, assign.id, 1)
assign.texts[0] = "@name=lid"
let path = material.texts[0]
assert(face_text(graph, assign.id, "material", 2) == path and face_text(graph, assign.id, "material", 3) == "" and face_text(graph, assign.id, "material", 5) == "")
print("PASS Name node: named faces, names kept, materials bound by @name")