Skip to content

Repository files navigation

Spline Modular Kit

Assembles authored modular art along a spline. Draw a path, hand it a kit of pieces, and it lays them out: straights packed into every run, corner pieces at every real corner, posts and end caps where they belong.

The solver never deforms your meshes. It reduces the spline to a polyline, finds the corners, and places the prefabs rigidly, so UVs stay correct by construction. Only the optional stretch-to-fit touches a transform, and it compensates texel density through a MaterialPropertyBlock rather than editing UVs.

It is not only a wall tool. Anything that is authored once and repeated along a path fits the same system: sci-fi glass walls, corridors, fences, pipe runs, ruined columns, rocks scattered along a cliff edge.

  • Corners are detected from the path, not authored by hand
  • Pieces are anchored by their leading edge, so start, centre and end pivoted meshes all work with no authoring change
  • Three fit modes: greedy packing, greedy plus a stretch to close the gap, or one piece length stretched uniformly
  • Spacing between pieces, measured either as a gap between bounds or as a fixed pivot-to-pivot step, so the same kit builds a tight wall or a scattered treeline
  • Random rotation and scale per piece, with min/max ranges, stable across rebuilds
  • Placement blocking: pieces that would overlap colliders on chosen layers are skipped, using their real bounds rather than just their length
  • Project a spline onto terrain or any chosen layer, keeping only the knots where the slope actually changes
  • Right hand turns reuse the left hand corner prefab, mirrored on Z
  • Slope handling: pieces either step up a gradient level, or pitch to lie along it
  • Shape presets that write a rectangle, polygon, arc or line straight into the spline, with generic corner filleting and grow / shrink about the centroid
  • Bake the finished run into one mesh per material, with lightmap UV2 generated

Requirements

  • Unity 6.3 (6000.3) or newer
  • com.unity.splines 2.8 or newer (pulled in automatically)

Installation (Git URL)

In Unity, open Window > Package Manager, click + > Add package from git URL, and paste:

https://github.com/innocentmiau/SplineModularKit.git

To pin a specific release, append the tag:

https://github.com/innocentmiau/SplineModularKit.git#v1.0.1

Alternatively, add it directly to your project's Packages/manifest.json:

{
  "dependencies": {
    "com.andreleandrodev.splinemodularkit": "https://github.com/innocentmiau/SplineModularKit.git#v1.0.1"
  }
}

Getting started

The fastest route is the sample. In Package Manager > Spline Modular Kit > Samples, import Demo Kit, then run Tools > Spline Modular Kit > Generate Demo Kit. It builds a placeholder kit out of primitives and drops a working builder in the open scene.

With your own art:

  1. Assets > Create > Spline Modular Kit > Modular Kit to make a kit asset.
  2. Add your prefabs to the pieces list and give each one a role: straight, corner, post, cap start or cap end.
  3. Add a SplineContainer to a GameObject and a Spline Kit Builder next to it, then assign the kit.
  4. Draw the spline, or use the Shape Presets foldout in the builder inspector to write a rectangle, polygon, arc or line into it.

Generated instances live under a __Generated child marked HideFlags.DontSave, so nothing is written into your scene file and the builder rebuilds them on load.

Authoring convention

Everything the solver does depends on these, so they are worth getting right once:

  • Pieces run along local +X. Local +Y is up. Art that does not follow this is corrected with the piece's rotationOffset (Euler degrees, any axis) instead of being re-exported. 180 on Y turns a backwards piece around. Measurement follows the correction, so lengths and corner insets stay right.
  • The pivot can sit anywhere along +X. It gets measured from the mesh bounds, so start, centre and end pivoted meshes all behave the same. Set Pivot Mode to something other than AUTO_FROM_BOUNDS when the bounds lie, for instance when a piece has decorative overhang past its structural length.
  • Corners are authored entering along +X and turning left by cornerAngle. Right turns reuse the same prefab with Z scaled by -1, when mirrorable is set.
  • Preset shapes are wound counter-clockwise seen from above, so every turn on them is a left turn.
  • Measurement reads sharedMesh.bounds, not Renderer.bounds, because the latter is empty on prefab assets. The prefab root's own localScale is folded back in.

How it works

SplineContainer
  -> sample at samplesPerUnit, uniform in t
  -> Ramer-Douglas-Peucker simplify (simplifyTolerance) -> polyline of real corner vertices
  -> for each vertex: horizontal turn angle > cornerThreshold? place a corner piece,
       record the inset it eats on both adjacent edges
  -> for each edge: available = edgeLength - insets
       -> pack straight pieces (see fit modes)
       -> optional posts at postSpacing
  -> posts at corners, caps at open ends
  -> List<KitPlacement> { prefab, position, rotation, scale, uvTiling }
  -> builder instantiates under a "__Generated" child marked HideFlags.DontSave

Everything is computed in the container's local space, and generated objects are parented to the container, so there is no world-transform math anywhere.

Fit modes

Mode Behaviour
GREEDY Longest-first weighted packing. Leftover is left empty.
GREEDY_STRETCH Same, then the whole run is scaled by up to maxStretch to close the gap.
STRETCH_UNIFORM One piece length, rounded count, stretched to fit exactly.

Slope

followSlope off (the default) keeps pieces level, so they step up a gradient. On, they pitch about local Z to lie along it, and corners average the gradient of both edges so a ramp-to-flat join does not kink. keepPostsVertical exempts posts. Corner detection is horizontal-only in both modes: a change in gradient is not a corner.

Layout

Path Contents
Runtime/Kit/ ModularKit (the asset), KitPiece, PieceMeasurement and the enums
Runtime/Layout/ KitLayoutSolver and its helpers: RunFitter, PieceOrientation, PlacementFactory, PolylineSimplifier
Runtime/Shapes/ SplineShapes, the preset polyline generators
Runtime/Components/ SplineKitBuilder, the only thing that touches the scene
Editor/ The builder inspector, the shape presets UI, the static mesh baker

The separation is deliberate: ModularKit is data, KitLayoutSolver is a pure function with no scene access, and SplineKitBuilder owns every side effect.

License

MIT. See LICENSE.md.

About

Assemble modular art along a spline in Unity without deforming it. Corners found from the path, pieces placed rigidly, UVs correct by construction. Walls, fences, pipe runs, columns, rocks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages