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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Proper metadata usage tairoark 2 6 10-01-2022, 12:04 PM
Last Post: _Aka_
  Accessing Metadata from CG hucota7 1 7 02-16-2022, 08:49 PM
Last Post: _Aka_
  Metadata warnings Josenildo 4 740 07-13-2021, 12:19 AM
Last Post: p30better
  Variable Mix Shape Interpolation Not Spanning Entire Input Spine Diasporism 4 1,203 04-20-2021, 06:54 PM
Last Post: _Aka_

Forum Jump: