@@ -471,6 +471,12 @@ def _mat_to_quat(m):
471471
472472
473473class SplatToFile3D (IO .ComfyNode ):
474+ FORMAT_WRITERS = {
475+ "ply" : _gaussian_ply_bytes ,
476+ "ksplat" : _gaussian_ksplat_bytes ,
477+ "spz" : _gaussian_spz_bytes ,
478+ }
479+
474480 @classmethod
475481 def define_schema (cls ):
476482 return IO .Schema (
@@ -482,7 +488,7 @@ def define_schema(cls):
482488 "Supports one item per batch only." ,
483489 inputs = [
484490 IO .Splat .Input ("splat" ),
485- IO .Combo .Input ("format" , options = [ "ply" , "ksplat" , "spz" ] , # TODO: add "splat" when we have a writer for it
491+ IO .Combo .Input ("format" , options = list ( cls . FORMAT_WRITERS ) , # TODO: add "splat" when we have a writer for it
486492 tooltip = "ply: standard 3D Gaussian Splat with full spherical harmonics. "
487493 "ksplat: mkkellogg SplatBuffer (level 0, uncompressed), base color only "
488494 "spz: Niantic gzip-compressed (~10x smaller), base color only "
@@ -493,10 +499,13 @@ def define_schema(cls):
493499
494500 @classmethod
495501 def execute (cls , splat , format = "ply" ) -> IO .NodeOutput :
502+ writer = cls .FORMAT_WRITERS .get (format )
503+ if writer is None :
504+ raise ValueError (f"Unsupported splat format: { format !r} " )
505+
496506 if splat .positions .shape [0 ] > 1 :
497507 logging .warning ("SplatToFile3D supports one item per batch only. Got %d; using first." , splat .positions .shape [0 ])
498508 end = _real_len (splat , 0 )
499- writer = {"ksplat" : _gaussian_ksplat_bytes , "spz" : _gaussian_spz_bytes }.get (format , _gaussian_ply_bytes )
500509 data = writer (splat .positions [0 , :end ], splat .scales [0 , :end ],
501510 splat .rotations [0 , :end ], splat .opacities [0 , :end ], splat .sh [0 , :end ])
502511 return IO .NodeOutput (Types .File3D (BytesIO (data ), file_format = format ))
0 commit comments