dymokomi/luced-3d
Source of release 0.11.6
## PLY in the node graph (luce-ply): the File node reading .ply (meshes,
## point clouds and 3D Gaussian splats) and the Export node writing it.
from luce_ply.ply import Ply
from luce_geocore.geocore import GeometrySet, GeometryVerbs, SetAttributes
from geometry_data import GeometryData
from usd_nodes import summary
## Whether `path` names a PLY file.
pub func is_ply_path(path: str) -> bool:
return path.trim().lower().ends_with(".ply")
## A File node's PLY file: a mesh when it has faces, else a point cloud.
## A 3DGS splat file (luce-ply's raw f_dc_*, opacity, scale_*, rot_*,
## f_rest) is baked into the splat conventions at once (orient, scale,
## opacity, linear Cd, sh), as Bake GSplats with its defaults would.
pub func load_ply(path: str) -> GeometryData!:
let geometry = baked_splats(Ply.load(path))
let data = GeometryData(geometry = geometry)
data.warning = summary(Ply.warnings())
return data
## `geometry` with a cloud in the raw 3DGS names (a PLY's, an SPZ's) baked
## into the splat conventions by Bake GSplats with its defaults (Up Axis Y
## Down: the file's frame is a 3DGS PLY's, and export turns it back); other
## geometry as it is.
pub func baked_splats(geometry: GeometrySet) -> GeometrySet!:
if SetAttributes.has(geometry, "f_dc_0", 0) and SetAttributes.has(geometry, "rot_0", 0):
return GeometryVerbs.run("Bake GSplats", geometry, none, "", 0, [], []).geometry()
return geometry
## The Export node's cook for a .ply path: binary little-endian PLY of the
## mesh (instances realized into it) or the point cloud, splat clouds in the
## 3DGS layout, passed on with what the writer left out as the warning.
pub func export_ply(path: str, data: GeometryData) -> GeometryData!:
var geometry = data.geometry
if geometry.instance_count() > 0 and not geometry.has("points"):
geometry = GeometrySet.of_mesh(geometry.realized())
# Baked splats go back to the file's own names and color encoding.
if geometry.splat_count() > 0:
geometry = geometry.unbaked_splats()
Ply.save(geometry, path)
let warning = summary(Ply.warnings())
return data.passed(warning) if warning != "" else data