Skip to main content

RamSpline

A class in Root.Township, the global namespace.

Third-party NatureManufacture river spline: builds a river mesh along Catmull-Rom control points, with width, flow map and vertex colours. Used for forest river paths (RiverPath.Mesh).

Constructors​

MemberWhat it is
RamSpline()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
List<RamSpline> beginnigChildSplinesSplines that connect to the start of this one; rebuilt after this one.
int beginningConnectionIDIndex of the point on beginningSpline this spline starts from (its last point).
float beginningMaxWidthWhere across the parent's width (0 to 1) this spline's start ends.
float beginningMinWidthWhere across the parent's width (0 to 1) this spline's start begins.
RamSpline beginningSplineSpline whose end this spline's start joins onto.
Color[] colorsVertex colours. Reset to black when the vertex count changes.
List<Vector2> colorsFlowMapPer-vertex flow map written to uv4. Kept when overrideFlowMap is set.
List<Vector4> controlPointsControl points: XYZ is the local position, W the width there.
List<Vector3> controlPointsDownLeft edge points at each control point.
List<AnimationCurve> controlPointsMeshCurvesPer control point curve that lifts vertices across the width.
List<Quaternion> controlPointsOrientationOrientation at each control point.
List<Quaternion> controlPointsRotationsExtra rotation per control point.
List<float> controlPointsSnapPer control point amount (0 to 1) that edge vertices snap to the ground.
List<Vector3> controlPointsUpRight edge points at each control point.
SplineProfile currentProfileSpline profile asset in use. Probably read by the editor tool only.
bool debugEditor tool setting. Not read in the game code.
int detailTerrainEditor tool setting for terrain carving. Not read in the game code.
int detailTerrainForwardEditor tool setting for terrain carving. Not read in the game code.
Color drawColorEditor vertex painting colour. Not read in the game code.
bool drawOnMeshEditor vertex painting toggle. Not read in the game code.
bool drawOnMeshFlowMapEditor flow map painting toggle. Not read in the game code.
bool drawOnMultipleEditor painting toggle for several splines. Not read in the game code.
float drawSizeEditor painting brush size. Not read in the game code.
List<RamSpline> endingChildSplinesSplines that connect to the end of this one; rebuilt after this one.
int endingConnectionIDIndex of the point on endingSpline this spline ends at (always 0).
float endingMaxWidthWhere across the next spline's width (0 to 1) this spline's end stops.
float endingMinWidthWhere across the next spline's width (0 to 1) this spline's end starts.
RamSpline endingSplineSpline whose start this spline's end joins onto.
float flowDirectionEditor flow painting setting. Not read in the game code.
AnimationCurve flowFlatFlow speed across the width on level ground.
float flowSpeedSpeed written into the flow map.
AnimationCurve flowWaterfallFlow speed across the width on steep ground.
float fulllengthTotal UV length of the spline, worked out in GenerateMesh.
bool generateMeshPartsWhether the mesh is split into several child parts.
bool invertUVDirectionFlips the UV direction along the river.
float lengthRunning UV length along the spline, carried on from beginningSpline.
List<float> lerpValuesPer sample position along the control points (segment index plus t).
float maxValShapes how vertices spread across the right half of the width.
AnimationCurve meshCurveDefault lift curve across the width. Not read in this class.
List<Transform> meshesPartTransformsChild objects made when the mesh is split into parts. Destroyed on each rebuild.
MeshFilter meshfilterMesh filter that gets the generated mesh.
int meshPartsCountHow many parts the mesh is split into.
float minMaxWidthShare of the joined spline's width this spline covers, for UVs.
float minValShapes how vertices spread across the left half of the width.
bool normalFromRaycastWhen true, normals come from a raycast to the ground instead of the spline orientation.
List<Vector3> normalsBeginningNormals of the first row, used by splines that join onto this one.
List<Vector3> normalsEndingNormals of the last row, used by splines that join onto this one.
List<Vector3> normalsListPer sample normal.
Material oldMaterialEditor tool setting. Not read in the game code.
SplineProfile oldProfilePrevious spline profile. Probably used by the editor tool only.
float opacityEditor painting opacity. Not read in the game code.
List<Quaternion> orientationsPer sample orientation.
bool overrideFlowMapWhen true, a hand painted flow map is kept instead of recomputed.
List<Vector3> pointsSampled centre line points.
List<Vector3> points2Unused point list.
List<Vector3> pointsDownSampled left edge points.
List<Vector3> pointsUpSampled right edge points.
float raycastHeightOffsetHeight above a vertex that ground snap raycasts start from.
bool showFlowMapEditor display toggle. Not read in the game code.
bool showVertexColorsEditor display toggle. Not read in the game code.
float simulatedRiverLengthEditor river simulation setting. Not read in the game code.
int simulatedRiverPointsEditor river simulation setting. Not read in the game code.
float simulationMinStepSizeEditor river simulation setting. Not read in the game code.
LayerMask snapMaskLayers the edge vertices snap and raycast onto.
List<float> snapsPer sample ground snap amount.
bool snapToTerrainWhether generated vertices are raycast down onto snapMask colliders.
List<Vector3> tangentsPer sample tangent.
float terrainAdditionalWidthEditor terrain carving setting. Not read in the game code.
AnimationCurve terrainCurveEditor terrain carving curve. Not read in the game code.
float terrainDepthHeightEditor terrain carving setting. Not read in the game code.
float terrainDepthMultiplierEditor terrain carving setting. Not read in the game code.
float terrainSmoothMultiplierEditor terrain carving setting. Not read in the game code.
int toolbarIntSelected tab in the editor tool. Not read in the game code.
float triangleDensityHow densely the spline is sampled along its length.
float uvBeginningUV offset across the width, from where this spline joins its parent.
bool uvRotationWhen true, the along-river UV goes in u instead of v.
float uvScaleUV tiling along the river.
bool uvScaleOverrideWhen true, keeps this spline's own uvScale instead of copying the parent's.
float uvWidthUV width across the river, scaled by the share of the parent it covers.
List<Vector3> verticesBeginningVertices of the first row, used by splines that join onto this one.
List<Vector3> verticesEndingVertices of the last row, used by splines that join onto this one.
int vertsInShapeVertices across the river's width.
float widthDefault width for new control points.
List<float> widthsPer sample river width.
1 private and internal field
MemberWhat it is
private bool isGenerationControlledSet by ControlledGenerate so Start doesn't generate again.

Methods​

MemberWhat it is
void AddPoint(Vector4 position)Adds a control point at the end. A w of 0 copies the last point's width, or width for the first.
void AddPoint(Vector4 position, AnimationCurve curve)Adds a control point at the end. A w of 0 copies the last point's width, or width for the first.
void AddPointAfter(int i)Inserts a control point after index i, halfway to the next point or extended past the last one.
void ChangePointPosition(int i, Vector3 position)Moves a control point. A w of 0 keeps its current width.
void ChangePointPosition(int i, Vector4 position)Moves a control point. A w of 0 keeps its current width.
void ControlledGenerate()Builds the mesh now and stops Start from building it again.
static RamSpline CreateSpline(Material splineMaterial = null, List<Vector4> positions = null)Creates a new game object with a spline and an unshadowed mesh renderer, optionally with a material and points.
void GenerateBeginningParentBased()Snaps the first control point onto the end of beginningSpline, between its min and max width.
void GenerateEndingParentBased()Snaps the last control point onto the start of endingSpline, between its min and max width.
void GenerateMeshParts(Mesh baseMesh)Splits a built mesh into meshPartsCount child mesh objects and hides the main renderer.
void GenerateSpline(List<RamSpline> generatedSplines = null)Rebuilds the river mesh from the control points, then regenerates connected child splines. The list argument is ignored.
void RemovePoint(int i)Removes a control point and its rotation, snap and curve entries.
void RemovePoints(int fromID = -1)Removes every control point after index fromID (all of them by default).
void Start()Builds the mesh unless ControlledGenerate already did.
13 private and internal methods
MemberWhat it is
private void CalculateCatmullRomSideSplines(List<Vector4> controlPoints, int pos)For one control point segment, works out the orientation and the left and right edge points from the point's width.
private void CalculateCatmullRomSpline(List<Vector3> controlPoints, int pos, ref List<Vector3> points)Samples one segment of a Catmull-Rom curve through the given points into the output list, at triangleDensity steps.
private void CalculateCatmullRomSplineParameters(List<Vector4> controlPoints, int pos, bool initialPoints = false)Samples one segment of the centre line, filling the width, snap, orientation, tangent and normal lists.
private Vector3 CalculateNormal(Vector3 tangent, Vector3 up)Normal that is square to the tangent and as close to up as it can be.
private void CalculatePointParameters(List<Vector4> controlPoints, int pos, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)Adds one centre line sample: position, width, snap, orientation, tangent and normal (flipped to stay on the same side).
private void CalculatePointPosition(List<Vector3> controlPoints, int pos, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t, ref List<Vector3> points)Adds one sampled position to the output list.
private int ClampListPos(int pos)Wraps an index into the control point list.
private float FlowCalculate(float u, float normalY)Flow speed for a point across the width: the waterfall curve on steep ground, the flat curve on level ground.
private void GenerateMesh(ref Mesh mesh)Builds the river mesh from the sampled edges: vertices, normals, UVs, flow map in uv4 and colours. Also sets a MeshCollider if there is one.
private float GenerateRow(int i, int j, int offset, ref float u, ref float u3, Vector3[] vertices, Vector3[] normals, Vector2[] uvs, Vector2[] uvs3, Vector2[] uvs4, bool isRaycasting)Places one vertex across the width, snapping to joined splines or the ground below, and sets its normal, UVs and flow value.
private Vector3 GetCatmullRomPosition(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)Point on a Catmull-Rom curve at t.
private Vector3 GetCatmullRomTangent(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)Tangent of a Catmull-Rom curve at t.
private void OnDestroy()Cleans up the generated mesh.

Used in​

Members of other types that take, return or hold a RamSpline: