Add shape mode support (straight, curve, corner) to spline corridor junctions

This commit is contained in:
2026-05-13 19:11:20 +02:00
parent ed09f81289
commit 9fe67f6ebe

View File

@@ -9,6 +9,7 @@ export type SplineCorridorJunctionTerrainMode =
| "none" | "none"
| "paintOnly" | "paintOnly"
| "flattenAndPaint"; | "flattenAndPaint";
export type SplineCorridorJunctionShapeMode = "straight" | "curve" | "corner";
export interface SplineCorridorJunctionConnection { export interface SplineCorridorJunctionConnection {
id: string; id: string;
@@ -27,6 +28,7 @@ export interface SplineCorridorJunction {
radius: number; radius: number;
materialId: string | null; materialId: string | null;
terrainMode: SplineCorridorJunctionTerrainMode; terrainMode: SplineCorridorJunctionTerrainMode;
shapeMode: SplineCorridorJunctionShapeMode;
edge: ScenePathRoadEdgeSettings; edge: ScenePathRoadEdgeSettings;
connections: SplineCorridorJunctionConnection[]; connections: SplineCorridorJunctionConnection[];
} }
@@ -43,6 +45,8 @@ export const DEFAULT_SPLINE_CORRIDOR_JUNCTION_CLIP_DISTANCE = 1.5;
export const DEFAULT_SPLINE_CORRIDOR_JUNCTION_MATERIAL_ID = null; export const DEFAULT_SPLINE_CORRIDOR_JUNCTION_MATERIAL_ID = null;
export const DEFAULT_SPLINE_CORRIDOR_JUNCTION_TERRAIN_MODE: SplineCorridorJunctionTerrainMode = export const DEFAULT_SPLINE_CORRIDOR_JUNCTION_TERRAIN_MODE: SplineCorridorJunctionTerrainMode =
"flattenAndPaint"; "flattenAndPaint";
export const DEFAULT_SPLINE_CORRIDOR_JUNCTION_SHAPE_MODE: SplineCorridorJunctionShapeMode =
"straight";
export const DEFAULT_SPLINE_CORRIDOR_JUNCTION_EDGE_ENABLED = false; export const DEFAULT_SPLINE_CORRIDOR_JUNCTION_EDGE_ENABLED = false;
export const MIN_SPLINE_CORRIDOR_JUNCTION_RADIUS = 0.05; export const MIN_SPLINE_CORRIDOR_JUNCTION_RADIUS = 0.05;
export const MAX_SPLINE_CORRIDOR_JUNCTION_RADIUS = 500; export const MAX_SPLINE_CORRIDOR_JUNCTION_RADIUS = 500;
@@ -53,6 +57,11 @@ export const SPLINE_CORRIDOR_JUNCTION_TERRAIN_MODES = [
"paintOnly", "paintOnly",
"flattenAndPaint" "flattenAndPaint"
] as const satisfies readonly SplineCorridorJunctionTerrainMode[]; ] as const satisfies readonly SplineCorridorJunctionTerrainMode[];
export const SPLINE_CORRIDOR_JUNCTION_SHAPE_MODES = [
"straight",
"curve",
"corner"
] as const satisfies readonly SplineCorridorJunctionShapeMode[];
function cloneVec3(vector: Vec3): Vec3 { function cloneVec3(vector: Vec3): Vec3 {
return { return {
@@ -87,6 +96,14 @@ export function isSplineCorridorJunctionTerrainMode(
); );
} }
export function isSplineCorridorJunctionShapeMode(
value: unknown
): value is SplineCorridorJunctionShapeMode {
return SPLINE_CORRIDOR_JUNCTION_SHAPE_MODES.includes(
value as SplineCorridorJunctionShapeMode
);
}
export function normalizeSplineCorridorJunctionRadius(value: number): number { export function normalizeSplineCorridorJunctionRadius(value: number): number {
return normalizePositiveFiniteNumber( return normalizePositiveFiniteNumber(
value, value,
@@ -141,6 +158,18 @@ export function normalizeSplineCorridorJunctionTerrainMode(
); );
} }
export function normalizeSplineCorridorJunctionShapeMode(
value: unknown
): SplineCorridorJunctionShapeMode {
if (isSplineCorridorJunctionShapeMode(value)) {
return value;
}
throw new Error(
"Spline corridor junction shape mode must be straight, curve, or corner."
);
}
export function createSplineCorridorJunctionConnection( export function createSplineCorridorJunctionConnection(
overrides: Partial<SplineCorridorJunctionConnection> & { overrides: Partial<SplineCorridorJunctionConnection> & {
pathId: string; pathId: string;
@@ -196,6 +225,10 @@ export function createSplineCorridorJunction(
overrides.terrainMode === undefined overrides.terrainMode === undefined
? DEFAULT_SPLINE_CORRIDOR_JUNCTION_TERRAIN_MODE ? DEFAULT_SPLINE_CORRIDOR_JUNCTION_TERRAIN_MODE
: normalizeSplineCorridorJunctionTerrainMode(overrides.terrainMode), : normalizeSplineCorridorJunctionTerrainMode(overrides.terrainMode),
shapeMode:
overrides.shapeMode === undefined
? DEFAULT_SPLINE_CORRIDOR_JUNCTION_SHAPE_MODE
: normalizeSplineCorridorJunctionShapeMode(overrides.shapeMode),
edge: createScenePathRoadEdgeSettings({ edge: createScenePathRoadEdgeSettings({
enabled: enabled:
overrides.edge?.enabled ?? DEFAULT_SPLINE_CORRIDOR_JUNCTION_EDGE_ENABLED, overrides.edge?.enabled ?? DEFAULT_SPLINE_CORRIDOR_JUNCTION_EDGE_ENABLED,