Expand clip intervals for road edges using edge width
This commit is contained in:
@@ -431,6 +431,24 @@ function isClipBoundaryDistance(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function expandClipIntervalsForRoadEdge(options: {
|
||||||
|
clipIntervals: readonly SplineCorridorPathClipInterval[];
|
||||||
|
edgeWidth: number;
|
||||||
|
totalLength: number;
|
||||||
|
}): SplineCorridorPathClipInterval[] {
|
||||||
|
if (options.clipIntervals.length === 0 || options.edgeWidth <= 0) {
|
||||||
|
return [...options.clipIntervals];
|
||||||
|
}
|
||||||
|
|
||||||
|
const insetDistance = options.edgeWidth * 0.45;
|
||||||
|
|
||||||
|
return options.clipIntervals.map((clipInterval) => ({
|
||||||
|
junctionId: clipInterval.junctionId,
|
||||||
|
startDistance: Math.max(0, clipInterval.startDistance - insetDistance),
|
||||||
|
endDistance: Math.min(options.totalLength, clipInterval.endDistance + insetDistance)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
export function buildSplineRoadMeshData(options: {
|
export function buildSplineRoadMeshData(options: {
|
||||||
path: SplineRoadPathLike;
|
path: SplineRoadPathLike;
|
||||||
terrains?: readonly Terrain[];
|
terrains?: readonly Terrain[];
|
||||||
@@ -562,10 +580,12 @@ export function buildSplineRoadEdgeMeshData(options: {
|
|||||||
const uvs: number[] = [];
|
const uvs: number[] = [];
|
||||||
const indices: number[] = [];
|
const indices: number[] = [];
|
||||||
const profileLastIndex = Math.max(1, profile.length - 1);
|
const profileLastIndex = Math.max(1, profile.length - 1);
|
||||||
const stationRuns = buildVisibleRoadStationRuns(
|
const edgeClipIntervals = expandClipIntervalsForRoadEdge({
|
||||||
stations,
|
clipIntervals: options.clipIntervals ?? [],
|
||||||
options.clipIntervals ?? []
|
edgeWidth: edge.width,
|
||||||
);
|
totalLength: stations[stations.length - 1]?.distance ?? 0
|
||||||
|
});
|
||||||
|
const stationRuns = buildVisibleRoadStationRuns(stations, edgeClipIntervals);
|
||||||
let stationCount = 0;
|
let stationCount = 0;
|
||||||
|
|
||||||
for (const run of stationRuns) {
|
for (const run of stationRuns) {
|
||||||
@@ -623,17 +643,15 @@ export function buildSplineRoadEdgeMeshData(options: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (edge.kind !== "softShoulder") {
|
if (edge.kind !== "softShoulder") {
|
||||||
const clipIntervals = options.clipIntervals ?? [];
|
|
||||||
|
|
||||||
addEdgeProfileCaps({
|
addEdgeProfileCaps({
|
||||||
indices,
|
indices,
|
||||||
profileVertexCount: profile.length,
|
profileVertexCount: profile.length,
|
||||||
vertexOffset: runVertexOffset,
|
vertexOffset: runVertexOffset,
|
||||||
stationCount: run.length,
|
stationCount: run.length,
|
||||||
capStart: !isClipBoundaryDistance(run[0]!.distance, clipIntervals),
|
capStart: !isClipBoundaryDistance(run[0]!.distance, edgeClipIntervals),
|
||||||
capEnd: !isClipBoundaryDistance(
|
capEnd: !isClipBoundaryDistance(
|
||||||
run[run.length - 1]!.distance,
|
run[run.length - 1]!.distance,
|
||||||
clipIntervals
|
edgeClipIntervals
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user