Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.6

0.11.6 / src / spz_nodes.luc

## Compact splat files in the node graph (luce-spz): the File node reading
## Niantic's .spz and antimatter15's .splat as Gaussian splats, and the Export
## node writing them. Both read into a 3DGS PLY's raw names and axes, so they
## bake as a PLY does (ply_nodes.baked_splats) and a capture loads the same
## from either format.
from luce_spz.spz import Spz
from geometry_data import GeometryData
from usd_nodes import summary
from ply_nodes import baked_splats
from luce_ui import ui

## Whether `path` names an SPZ or .splat file.
pub func is_spz_path(path: str) -> bool:
    let lower = path.trim().lower()
    return lower.ends_with(".spz") or lower.ends_with(".splat")

## A File node's .spz or .splat file: its splats, baked.
pub func load_spz(path: str) -> GeometryData!:
    let geometry = baked_splats(Spz.load(path))
    let data = GeometryData(geometry = geometry)
    data.warning = summary(Spz.warnings())
    return data

## The Export node's cook for a .spz or .splat path: the input's splat cloud
## (unbaked and written in the file's axes by luce-spz; SPZ version 4), passed
## on with what the writer left out as the warning.
pub func export_spz(path: str, data: GeometryData) -> GeometryData!:
    if not data.geometry.has("points"):
        error(ui.invalid, "Export to .spz or .splat needs a point cloud of splats")
    Spz.save(data.geometry, path)
    let warning = summary(Spz.warnings())
    return data.passed(warning) if warning != "" else data