mlx3d.splatting.spaghetti¶
mlx3d.splatting.spaghetti
¶
Spaghetti Splatting: radiance fields of Gaussian-blurred curve segments.
An MLX / Metal implementation of Spaghetti Splatting: Differentiating Curvilinear Dirac Masses via Convolution (Shramko, Govindarajan, Lam, Xie, Rebain, Lindell, Tagliasacchi, 2026). Each primitive is a line segment convolved with a 3D Gaussian kernel; chains of segments represent curves — hair, wires, grass — far more economically than strings of blobs, and a zero-length segment is exactly a 3D Gaussian, so the representation is a strict superset of 3D Gaussian Splatting.
SpaghettiModel
¶
Gaussian-blurred line segments with spherical-harmonic colors.
Parameters (params, all (N, ...)):
means,halves: segment midpoint and half-vector (segment =m ± h);quats,scales: kernel rotation and log standard deviations;opacities: logit of the peak point opacityo. The density isrho = -ln(1 - o) / (sqrt(2 pi) sigma)withsigmathe kernel's geometric-mean scale, so a zero-length segment seen through its center has opacity ~o, exactly like a 3DGS splat; andrho(density per unit length) is what splitting preserves.sh_dc(N, 1, 3),sh_rest(N, K-1, 3).
Source code in src/mlx3d/splatting/spaghetti/model.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
from_points(points, colors=None, sh_degree=3, initial_opacity=0.1, initial_length=2.0, max_scale=None, seed=0)
classmethod
¶
Short segments at points in random directions.
Kernel scales come from nearest-neighbor spacing; each segment is
initial_length kernel widths long (a nonzero length is needed: at
exactly zero the gradient with respect to it vanishes by symmetry).
Source code in src/mlx3d/splatting/spaghetti/model.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
from_gaussians(gaussians, length_frac=0.001)
classmethod
¶
Lift a :class:~mlx3d.splatting.GaussianModel to (near-)zero-length
segments along each Gaussian's major axis — the representation is a
strict superset of 3DGS, so this is a valid starting point.
Source code in src/mlx3d/splatting/spaghetti/model.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
density(params)
staticmethod
¶
Density rho (per unit length) from the opacity / scale parameters.
Source code in src/mlx3d/splatting/spaghetti/model.py
126 127 128 129 130 131 | |
render_params(params, camera, background=None)
¶
Differentiable render of an explicit parameter dict.
Source code in src/mlx3d/splatting/spaghetti/model.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
split_or_clone(idx, split_min_length)
¶
Duplicate rows idx without changing the rendered image.
Rows longer than split_min_length are split at their midpoint (the
row keeps one half, the returned copy is the other); shorter rows are
cloned with half the optical depth each. Optical depth is additive
along rays, so both are exact. Updates rows idx in place and
returns the new rows to place elsewhere.
Source code in src/mlx3d/splatting/spaghetti/model.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
snap_endpoints(radius)
¶
Merge nearby endpoints of different segments into shared joints.
Every endpoint whose nearest other-segment endpoint lies within
radius (scalar, or per-segment) is moved, together with that
neighbor, to their midpoint. Returns the number of joints created.
Source code in src/mlx3d/splatting/spaghetti/model.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
polylines(tolerance)
¶
Chain segments that share endpoints (within tolerance) into
polylines; returns a list of (K, 3) vertex arrays.
Source code in src/mlx3d/splatting/spaghetti/model.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
save_ply(path)
¶
Save as a PLY vertex list with spaghetti-specific properties.
Source code in src/mlx3d/splatting/spaghetti/model.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
SegmentProjection
¶
Bases: dict
Per-segment camera-space quantities (a dict of (N, ...) arrays).
Keys: W (N, 3, 3) whitening map, a / v (N, 3) whitened start /
direction, rho (N,); for tile binning means2d (N, 2) projected
midpoints, radii (N,) pixel radii bounding the footprint (0 = culled)
and depths (N,) midpoint depths; and conics (N, 3), the
(a, b, c) of a pixel-space ellipse x^T C x <= 1 around the
projected midpoint that contains the whole footprint.
Source code in src/mlx3d/splatting/spaghetti/projection.py
72 73 74 75 76 77 78 79 80 81 | |
SpaghettiTrainer
¶
Optimizes a :class:SpaghettiModel against posed images.
Source code in src/mlx3d/splatting/spaghetti/trainer.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
step(camera, target)
¶
One optimization step on one view; returns logging info.
Source code in src/mlx3d/splatting/spaghetti/trainer.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
finalize_polylines(radius_widths=None)
¶
Snap nearby endpoints into shared joints (the paper's merging step); returns the number of joints created.
Source code in src/mlx3d/splatting/spaghetti/trainer.py
260 261 262 263 264 265 | |
SpaghettiTrainerConfig
dataclass
¶
Source code in src/mlx3d/splatting/spaghetti/trainer.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
lr_halves = 0.00016
class-attribute
instance-attribute
¶
Half-vector learning rate (scaled by the scene extent, like means).
lambda_opacity = 0.01
class-attribute
instance-attribute
¶
MCMC regularizer: mean peak opacity (encourages few, opaque segments).
lambda_scale = 0.01
class-attribute
instance-attribute
¶
MCMC regularizer: mean kernel scale (encourages thin kernels).
split_ratio = 2.0
class-attribute
instance-attribute
¶
Duplicated segments longer than this many kernel widths are split.
lambda_connect = 0.0
class-attribute
instance-attribute
¶
Endpoint attraction weight (applied from connect_from).
connect_radius = 3.0
class-attribute
instance-attribute
¶
Endpoints closer than this many kernel widths attract each other.
project_segments(camera, means, halves, quats, scales, rho)
¶
Map world-space segments into whitened camera space (differentiable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
means
|
array
|
(N, 3) segment midpoints. |
required |
halves
|
array
|
(N, 3) half-vectors: the segment runs from |
required |
quats
|
array
|
(N, 4) kernel rotations (w, x, y, z). |
required |
scales
|
array
|
(N, 3) kernel standard deviations (activated). |
required |
rho
|
array
|
(N,) densities (activated). |
required |
Source code in src/mlx3d/splatting/spaghetti/projection.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
segment_optical_depth(e, a, v, rho)
¶
Closed-form optical depth tau (pure MLX, differentiable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e
|
array
|
|
required |
a
|
array
|
|
required |
v
|
array
|
|
required |
rho
|
array
|
|
required |
Source code in src/mlx3d/splatting/spaghetti/projection.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
pack_segments(W, a, v, rho)
¶
Pack per-segment kernel inputs into the (N, 16) layout the kernels read.
Source code in src/mlx3d/splatting/spaghetti/rasterize.py
346 347 348 349 | |
rasterize_segments(segments, colors, means2d, conics, sorted_ids, tile_ranges, intrinsics, width, height, tiles_x, tiles_y, background=None)
¶
Composite binned segments into an image (differentiable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segments
|
array
|
(N, 16) packed segments (:func: |
required |
colors
|
array
|
(N, 3) RGB. |
required |
means2d
|
array
|
(N, 2) footprint-ellipse centers in pixels. |
required |
conics
|
array
|
(N, 3) footprint ellipses |
required |
intrinsics
|
tuple[float, float, float, float]
|
pinhole |
required |
Returns:
| Type | Description |
|---|---|
dict[str, array]
|
dict with |
dict[str, array]
|
|
Source code in src/mlx3d/splatting/spaghetti/rasterize.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
render_spaghetti(camera, means, halves, quats, scales, rho, colors, background=None)
¶
Render Gaussian-blurred segments with the tiled Metal rasterizer.
Differentiable with respect to every per-segment input and, through
camera's extrinsics, the pose (e.g. via :func:~mlx3d.cameras.refine_camera).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera
|
Camera
|
the pinhole camera to render from. |
required |
means
|
array
|
(N, 3) segment midpoints. |
required |
halves
|
array
|
(N, 3) half-vectors; each segment spans |
required |
quats
|
array
|
(N, 4) kernel rotations (w, x, y, z). |
required |
scales
|
array
|
(N, 3) kernel standard deviations. |
required |
rho
|
array
|
(N,) densities. |
required |
colors
|
array
|
(N, 3) RGB. |
required |
background
|
array | None
|
optional (3,) background color (default black). |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, array]
|
dict with |
dict[str, array]
|
( |
Source code in src/mlx3d/splatting/spaghetti/render.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
render_spaghetti_reference(camera, means, halves, quats, scales, rho, colors, background=None)
¶
Dense pure-MLX renderer with the same semantics (tests / small scenes).
Evaluates every segment at every pixel (O(H W N) memory) with the
rasterizer's depth order, opacity clamp and cut-off, but no early
termination. Differentiable via MLX autodiff.
Source code in src/mlx3d/splatting/spaghetti/render.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
segment_colors(camera, means, sh, sh_degree)
¶
View-dependent RGB per segment: SH evaluated toward the segment midpoint.
Source code in src/mlx3d/splatting/spaghetti/render.py
16 17 18 19 20 | |
default_config_for(iterations, **overrides)
¶
Schedule scaled to iterations: densify until 5/6 of the run, attract
endpoints in the final sixth (the paper's 25k / 30k split).
Source code in src/mlx3d/splatting/spaghetti/trainer.py
268 269 270 271 272 273 274 275 276 277 278 279 | |