01-07-2022, 09:12 AM
Hello,
I have script to programmatically create intersections.
I use Shape Extrusion on road to end and start pavements, curbs and other things (cutout for intersection)
range.from and range.to are in meters.
In intersection script I use:
DistanceStart and DistanceEnd is in meters. it has same values as range.from and range.to
Somewhere (near the road start) it looks great (sphere gameobjects are edge points of intersection)
Somewhere is offset more visible
Somewhere is offset very big
How to get same points for intersection script and for Shape Extrusion? I tried to turn cache off (everywhere), I'm using non-fast methods, but no success.
It's always offseted towards spline start.
I have script to programmatically create intersections.
I use Shape Extrusion on road to end and start pavements, curbs and other things (cutout for intersection)
range.from and range.to are in meters.
Code:
var shapeExtrusion = generator.AddModule<BuildShapeExtrusion>();
shapeExtrusion.Resolution = 100;
if (range != null && spline && (range.@from >= 0 || range.to >= 0))
{
var totalDistance = spline.TFToDistance(1);
var tfFrom = 1 - (totalDistance - range.from) / totalDistance;
shapeExtrusion.From = tfFrom;
if (range.to > range.from)
{
var tfTo = 1 - (totalDistance - range.to) / totalDistance;
shapeExtrusion.To = tfTo;
}
}
In intersection script I use:
DistanceStart and DistanceEnd is in meters. it has same values as range.from and range.to
Code:
float distanceBetweenPoints = DistanceEnd - DistanceStart;
float pointPart = 1f / (float) (PointsCount - 1);
float[] pointsDistances = new float[PointsCount];
for (int i = 0; i < PointsCount; i++)
{
pointsDistances[i] = Road.DistanceToTF(DistanceStart + distanceBetweenPoints * pointPart * i);
}
Somewhere (near the road start) it looks great (sphere gameobjects are edge points of intersection)
Somewhere is offset more visible
Somewhere is offset very big
How to get same points for intersection script and for Shape Extrusion? I tried to turn cache off (everywhere), I'm using non-fast methods, but no success.
It's always offseted towards spline start.