I have segment Metadata that represent the starting 'width' of a Spline's segment. If this 'width' changes from segment to segment, the width is linearly interpolated using a "Variable Mixed Shape" CG module. The resulting extrusion is what is desired.
In the Spline's Controller (and other places), I need to to know the 'width' at any Position along the Spline. The general implementation of Metadata interpolation is a problem.
The value passed into this method are 'local F' space. This is not the uniformly spaced linear values needed for Lerp to go from width to the next.
The following convert 'local F' space to linear segment space:
But it needs access to the segment, which isn't passed into the Metadata's Interpolate routine.
In some places I can do this where I'm accessing the Metadata for a specific segment. But other places, like the Controller, it is preferable to use the Spline.InterpolateMetadata<>( Position ). I cad get the segment of the Position myself and do the conversion:
But this seem expensive to do in a Controller. Plus a bit contorted and seemingly wrong.
What would you suggest as optimal?
In the Spline's Controller (and other places), I need to to know the 'width' at any Position along the Spline. The general implementation of Metadata interpolation is a problem.
Code:
public override float Interpolate( CurvyInterpolatableMetadataBase<float> nextMetadata, float interpolationTime ) {
return (nextMetadata is not null) ? Mathf.Lerp( MetaDataValue, nextMetadata.MetaDataValue, interpolationTime ) : MetaDataValue;
}
The value passed into this method are 'local F' space. This is not the uniformly spaced linear values needed for Lerp to go from width to the next.
The following convert 'local F' space to linear segment space:
Code:
var ld = seg.LocalFToDistance( lf ) / seg.Length;
var widthAtLf = seg.GetInterpolatedMetadata<TrackMetadata, float>( ld );
But it needs access to the segment, which isn't passed into the Metadata's Interpolate routine.
In some places I can do this where I'm accessing the Metadata for a specific segment. But other places, like the Controller, it is preferable to use the Spline.InterpolateMetadata<>( Position ). I cad get the segment of the Position myself and do the conversion:
Code:
var seg = Spline.TFToSegment( Position, out float lf );
var ld = seg.LocalFToDistance( lf ) / seg.Length;
var trackWidthScaled = seg.GetInterpolatedMetadata<TrackMetadata, float>( ld );
What would you suggest as optimal?