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)
![[Image: iDx8f4c.png]](https://i.imgur.com/iDx8f4c.png)
Somewhere is offset more visible
![[Image: wtOn96b.png]](https://i.imgur.com/wtOn96b.png)
Somewhere is offset very big
![[Image: a9iwZn3.png]](https://i.imgur.com/a9iwZn3.png)
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)
![[Image: iDx8f4c.png]](https://i.imgur.com/iDx8f4c.png)
Somewhere is offset more visible
![[Image: wtOn96b.png]](https://i.imgur.com/wtOn96b.png)
Somewhere is offset very big
![[Image: a9iwZn3.png]](https://i.imgur.com/a9iwZn3.png)
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.