Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Metadata interpolation
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.

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:
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:
var seg = Spline.TFToSegment( Position, out float lf );
var ld = seg.LocalFToDistance( lf ) / seg.Length;
var trackWidthScaled = seg.GetInterpolatedMetadata<TrackMetadata, float>( ld );
But this seem expensive to do in a Controller. Plus a bit contorted and seemingly wrong.

What would you suggest as optimal?
In the CurvyInterpolatableMetadataBase class, you have access to the ControlPoint property. Using it, you can do the conversion you talked about in the Interpolate method's implementation. An example with the example script E01_HeightMetadata:

        public override float Interpolate(CurvyInterpolatableMetadataBase<float> nextMetadata, float interpolationTime)
            if (nextMetadata != null)
                return Mathf.Lerp(MetaDataValue,
                    ControlPoint.LocalFToDistance(interpolationTime) / ControlPoint.Length);
            return MetaDataValue;

Did this help?
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
My mistake. I did not see ControlPoint. Thank you
You are welcome. Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Controler Speed from metadata Bryan Thatcher 1 2 05-24-2024, 08:41 AM
Last Post: _Aka_
  "MetaData" Of Entire Spline Heightmap SAMYTHEBIGJUICY 3 6 10-16-2023, 08:42 AM
Last Post: _Aka_
  Proper metadata usage tairoark 2 8 10-01-2022, 12:04 PM
Last Post: _Aka_
  Accessing Metadata from CG hucota7 1 8 02-16-2022, 08:49 PM
Last Post: _Aka_

Forum Jump: