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

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 );
But this seem expensive to do in a Controller. Plus a bit contorted and seemingly wrong.

What would you suggest as optimal?
Reply
#2
Hi
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:

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

Did this help?
Have a nice day
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
My mistake. I did not see ControlPoint. Thank you
Reply
#4
You are welcome. Have a nice day
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Controler Speed from metadata Bryan Thatcher 4 10 06-25-2024, 11:18 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 9 02-16-2022, 08:49 PM
Last Post: _Aka_

Forum Jump: