Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.4

0.11.4 / src / main.luc

## luced-3d's entry: opens the editor on the projects named (`--empty`
## starts with no nodes, `--smoke` draws three frames and quits), or with
## `--import FILE` cooks a File node on FILE without a window.
from app import Luce3D
from network import Network
from stamps import stamp_graph
import node_catalog
import time

pub func main(arguments: list[str]) -> int!:
    # `--import FILE`: cook a File node on FILE without a window (smoke checks
    # of installed builds) and print what it made.
    for at in 0..<arguments.length - 1:
        if arguments[at] == "--import":
            import_file(arguments[at + 1])
            return 0
    let editor = Luce3D(persist = not ("--smoke" in arguments))
    # `--empty`: start with no nodes (no Cube) to build from scratch.
    if "--empty" in arguments:
        editor.workspace.replace_network(Network(false))
        editor.panels.refresh()
    editor.run(arguments) catch failure:
        editor.close()
        error(failure.code, failure.message)
    editor.close()
    return 0

func import_file(path: str) -> unit!:
    let graph = Network(false)
    let file = graph.add("File", 0.0, 0.0)
    file.texts[0] = path
    for parameter in node_catalog.parameters("File", path):
        file.values[parameter.slot] = parameter.initial
    stamp_graph(graph)
    let started = time.now()
    let data = graph.evaluate_data(file.id)
    let milliseconds = float(time.now() - started) / 1000000.0
    let geometry = data.geometry
    var faces = 0
    var points = 0
    if let mesh = data.mesh:
        faces = mesh.face_count()
        points = mesh.point_count()
    print(f"{path}: {faces} faces, {points} points, {geometry.instance_count()} instances, {geometry.component_count()} components in {milliseconds} ms")
    if data.warning != "":
        print(f"warning: {data.warning}")