dymokomi/luced-3d
Source of release 0.11.3
0.11.3 / tests / editor / usd_node_tests.luc
## USD in the graph: the File node's USD rows and options, and the Export
## node writing its input by extension and passing it on.
from network import Network
from stamps import stamp_graph
from luce_usd.usd import Usd
from usd_nodes import compose_usd
from luce_geocore.geocore import GeometryFile
from luce_obj.obj import Obj
import node_catalog
pub func usd_node_tests() -> unit!:
assert("Export" in node_catalog.kinds() and node_catalog.category("Export") == "File I/O")
# A USD path brings the USD rows: import mode, time, purposes, units, subdivision
# (the variant menus come with a composed stage).
assert(node_catalog.parameters("File", "stage.usdc").length == 8)
assert(node_catalog.file_format("a.USDZ") == "usd" and node_catalog.file_format("a.stp") == "step" and node_catalog.file_format("a.obj") == "")
let graph = Network(false)
let sphere = graph.add("Sphere", 0.0, 0.0)
let export = graph.add("Export", 0.0, 60.0)
assert(export.texts[1] == "geo" and export.values[0] == 1.0)
graph.connect(sphere.id, export.id, 0)
for name in ["sphere.usda", "sphere.usdc", "sphere.usdz", "sphere.obj", "sphere.prism"]:
export.texts[0] = name
graph.invalidate(export.id)
stamp_graph(graph)
assert(graph.evaluate(export.id).face_count() == graph.evaluate(sphere.id).face_count())
# Each file reads back in its own format.
assert(Usd.serialization("sphere.usda") == "usda" and Usd.serialization("sphere.usdc") == "usdc" and Usd.serialization("sphere.usdz") == "usdz")
let faces = graph.evaluate(sphere.id).face_count()
assert(Obj.load("sphere.obj").face_count() == faces)
let saved = GeometryFile.load("sphere.prism").mesh() else trap("mesh")
assert(saved.face_count() == faces)
# The File node reads the written stage back; the sphere has no subdivisionScheme
# on export ("none" is written), so the default subdivision leaves it alone.
let file = graph.add("File", 200.0, 0.0)
file.texts[0] = "sphere.usdc"
for parameter in node_catalog.parameters("File", file.texts[0]):
file.values[parameter.slot] = parameter.initial
stamp_graph(graph)
assert(graph.evaluate(file.id).face_count() == faces)
# A point instancer: instances by default, baked with Flatten everything.
file.texts[0] = "tests/fixtures/instancer.usda"
graph.invalidate(file.id)
stamp_graph(graph)
assert(graph.evaluate_data(file.id).geometry.instance_count() == 3)
file.values[1] = 1.0
graph.invalidate(file.id)
stamp_graph(graph)
assert(graph.evaluate(file.id).face_count() == 7)
composition_tests(graph)
## A composed stage's rows: what it holds, a menu per variant set, and the
## Variants and Load payloads texts, each changing what the node loads.
func composition_tests(graph: Network) -> unit!:
let room = graph.add("File", 400.0, 0.0)
assert(room.texts == ["", "", ""])
room.texts[0] = "tests/fixtures/room.usda"
for parameter in node_catalog.parameters("File", room.texts[0]):
room.values[parameter.slot] = parameter.initial
room.values[8] = 0.0
let stage = compose_usd(room.texts[0], room.texts)
assert(stage.description() == "2 layers, 7 prims, 2 instances, 1 variant set")
var menus = 0
for row in node_catalog.fields("File", room.texts[0], stage):
if row.kind == "menu" and row.slot == 9:
assert(row.name == "Table top" and row.items == "Authored (quad)|quad|triangles")
menus += 1
if row.kind == "info":
assert(row.text == stage.description())
assert(menus == 1)
let faces = func () -> int!:
graph.invalidate(room.id)
stamp_graph(graph)
let mesh = graph.evaluate_data(room.id).geometry.mesh() else trap("no mesh")
return mesh.face_count()
# The table's quad top and the lamp's three faces (the chairs are instances).
assert(faces() == 4)
room.values[9] = 2.0
assert(faces() == 5)
room.values[9] = 0.0
room.texts[1] = "/Room/Table{top=triangles}"
assert(faces() == 5)
room.texts[2] = "-"
assert(faces() == 2)
assert(compose_usd(room.texts[0], room.texts).description() == "1 layer, 5 prims, 2 instances, 1 variant set")